private GenericMailet setupMockedMailet(String name1, String name2) throws MessagingException { GenericMailet mailet = new RemoveMimeHeader(); FakeMailetConfig mci = new FakeMailetConfig("Test", new FakeMailContext()); if (name1 != null) mci.setProperty("name", name1); if (name2 != null) mci.setProperty("name", name2); mailet.init(mci); return mailet; }
@Test public void shouldOverwriteAttributeWhenAttributeAlreadyPresent() throws MessagingException { FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext()); mailetConfig.setProperty("org.apache.james.junit1", "bar"); mailet.init(mailetConfig); Mail mail = MailUtil.createMockMail2Recipients( new MimeMessage(Session.getDefaultInstance(new Properties()))); mail.setAttribute("org.apache.james.junit1", "foo"); mailet.service(mail); assertThat(mail.getAttribute("org.apache.james.junit1")).isEqualTo("bar"); }
@Test public void shouldAddConfiguredAttributes() throws MessagingException { FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext()); mailetConfig.setProperty("org.apache.james.junit1", "true"); mailetConfig.setProperty("org.apache.james.junit2", "happy"); mailet.init(mailetConfig); Mail mail = MailUtil.createMockMail2Recipients( new MimeMessage(Session.getDefaultInstance(new Properties()))); mailet.service(mail); assertThat(mail.getAttribute("org.apache.james.junit1")).isEqualTo("true"); assertThat(mail.getAttribute("org.apache.james.junit2")).isEqualTo("happy"); }
@Test public void shouldThrowWhenNullProperty() throws MessagingException { FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext()); expectedException.expect(NullPointerException.class); mailetConfig.setProperty(null, "bar"); }
@Test public void shouldThrowWhenNullValue() throws MessagingException { FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext()); expectedException.expect(NullPointerException.class); mailetConfig.setProperty("org.apache.james.junit1", null); }