Repository: james-project Updated Branches: refs/heads/master 094d62776 -> 54f3bf313
MAILET-113 IsSingleRecipientTest should match our coding conventions Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/284424de Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/284424de Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/284424de Branch: refs/heads/master Commit: 284424dedf74be6575bd3256d8ad015d2e09ff78 Parents: 094d627 Author: Benoit Tellier <[email protected]> Authored: Wed Aug 17 14:26:12 2016 +0700 Committer: Benoit Tellier <[email protected]> Committed: Wed Aug 31 00:55:56 2016 +0700 ---------------------------------------------------------------------- .../matchers/IsSingleRecipientTest.java | 61 +++++++------------- 1 file changed, 21 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/284424de/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java index 19b0a54..9fc7f83 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java @@ -20,8 +20,7 @@ package org.apache.james.transport.matchers; -import java.util.Arrays; -import java.util.Collection; +import static org.assertj.core.api.Assertions.assertThat; import javax.mail.MessagingException; @@ -30,62 +29,44 @@ import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Assert; +import org.junit.Before; import org.junit.Test; public class IsSingleRecipientTest { - private FakeMail mockedMail; - private Matcher matcher; + private MailAddress mailAddress1; + private MailAddress mailAddress2; - private MailAddress[] recipients; + @Before + public void setUp() throws MessagingException { + matcher = new IsSingleRecipient(); + FakeMatcherConfig matcherConfig = new FakeMatcherConfig("IsSingleRecipient", FakeMailContext.defaultContext()); + matcher.init(matcherConfig); - private void setRecipients(MailAddress[] recipients) { - this.recipients = recipients; + mailAddress1 = new MailAddress("[email protected]"); + mailAddress2 = new MailAddress("[email protected]"); } - private void setupMockedMail() { - mockedMail = new FakeMail(); - mockedMail.setRecipients(Arrays.asList(recipients)); + @Test + public void matchShouldMatchOneRecipientsEmails() throws MessagingException { + FakeMail fakeMail = FakeMail.builder().recipient(mailAddress1).build(); + assertThat(matcher.match(fakeMail)).containsExactly(mailAddress1); } - private void setupMatcher() throws MessagingException { - - matcher = new IsSingleRecipient(); - FakeMatcherConfig mci = new FakeMatcherConfig("IsSingleRecipient", - FakeMailContext.defaultContext()); - matcher.init(mci); - } - - // test if matched @Test - public void testHostIsMatchedAllRecipients() throws MessagingException { - setRecipients(new MailAddress[]{new MailAddress( - "[email protected]")}); - - setupMockedMail(); - setupMatcher(); - - Collection<MailAddress> matchedRecipients = matcher.match(mockedMail); + public void matchShouldNotMatchMultiRecipientsEMail() throws MessagingException { + FakeMail fakeMail = FakeMail.builder().recipients(mailAddress1, mailAddress2).build(); - Assert.assertNotNull(matchedRecipients); + assertThat(matcher.match(fakeMail)).isNull(); } - // test if not matched @Test - public void testHostIsMatchedOneRecipient() throws MessagingException { - setRecipients(new MailAddress[]{ - new MailAddress("[email protected]"), - new MailAddress("[email protected]")}); - - setupMockedMail(); - setupMatcher(); - - Collection<MailAddress> matchedRecipients = matcher.match(mockedMail); + public void matchShouldNotMatchMailWithNotRecipients() throws MessagingException { + FakeMail fakeMail = FakeMail.builder().build(); - Assert.assertNull(matchedRecipients); + assertThat(matcher.match(fakeMail)).isNull(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
