@Test public void shouldAddNothingWhenNoConfiguredAttribute() throws MessagingException { FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext()); mailet.init(mailetConfig); Mail mail = MailUtil.createMockMail2Recipients( new MimeMessage(Session.getDefaultInstance(new Properties()))); mailet.service(mail); assertThat(mail.getAttributeNames()).isEmpty(); }
@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); }