Repository: james-project
Updated Branches:
  refs/heads/master df506d9d1 -> 35ccb7baa


MAILET-122 RecipientIs 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/9c9de6dd
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9c9de6dd
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9c9de6dd

Branch: refs/heads/master
Commit: 9c9de6dd249185feeb6c894f1c81eb95c6dc9a87
Parents: 91d3ebf
Author: Benoit Tellier <[email protected]>
Authored: Wed Aug 31 13:47:10 2016 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Fri Oct 7 10:59:56 2016 +0200

----------------------------------------------------------------------
 .../transport/matchers/RecipientIsTest.java     | 83 +++++++++-----------
 1 file changed, 35 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9c9de6dd/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java
----------------------------------------------------------------------
diff --git 
a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java
 
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java
index c810e50..c8bfa68 100644
--- 
a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java
+++ 
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java
@@ -20,69 +20,56 @@
 
 package org.apache.james.transport.matchers;
 
-import java.io.UnsupportedEncodingException;
-import java.util.Collection;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES;
+import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES;
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2;
 
-import javax.mail.MessagingException;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Test;
 
-import org.apache.james.transport.matchers.RecipientIs;
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
+public class RecipientIsTest {
 
-public class RecipientIsTest extends AbstractRecipientIsTest {
+    private RecipientIs matcher;
 
-    public RecipientIsTest(String arg0) throws UnsupportedEncodingException {
-        super(arg0);
+    @Before
+    public void setUp() throws Exception {
+        matcher = new RecipientIs();
     }
 
-    protected String getRecipientName() {
-        return "[email protected]";
-    }
-
-    // test if the recipients get returned as matched
-    public void testHostIsMatchedAllRecipients() throws MessagingException {
-        setRecipients(new MailAddress[] { new MailAddress(
-                "[email protected]") });
+    @Test
+    public void shouldMatchCorrespondingAddres() throws Exception {
+        matcher.init(new FakeMatcherConfig("RecipientIs=" + 
ANY_AT_JAMES.toString(), FakeMailContext.defaultContext()));
 
-        setupMockedMail();
-        setupMatcher();
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(ANY_AT_JAMES)
+            .build();
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+       assertThat(matcher.match(fakeMail)).containsExactly(ANY_AT_JAMES);
     }
 
-    // test if one recipients get returned as matched
-    public void testHostIsMatchedOneRecipient() throws MessagingException {
-        setRecipients(new MailAddress[] {
-                new MailAddress("[email protected]"),
-                new MailAddress("[email protected]") });
-
-        setupAll();
+    @Test
+    public void shouldOnlyMatchCorrespondingAddress() throws Exception {
+        matcher.init(new FakeMatcherConfig("RecipientIs=" + 
ANY_AT_JAMES.toString(), FakeMailContext.defaultContext()));
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(ANY_AT_JAMES, OTHER_AT_JAMES)
+            .build();
 
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), 1);
+        assertThat(matcher.match(fakeMail)).containsExactly(ANY_AT_JAMES);
     }
 
-    // test if no recipient get returned cause it not match
-    public void testHostIsNotMatch() throws MessagingException {
-        setRecipients(new MailAddress[] {
-                new MailAddress("[email protected]"),
-                new MailAddress("[email protected]") });
+    @Test
+    public void shouldNotMatchUnrelatedAddresses() throws Exception {
+        matcher.init(new FakeMatcherConfig("RecipientIs=" + 
ANY_AT_JAMES.toString(), FakeMailContext.defaultContext()));
 
-        setupMockedMail();
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertEquals(matchedRecipients.size(), 0);
-    }
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(OTHER_AT_JAMES, ANY_AT_JAMES2)
+            .build();
 
-    protected Matcher createMatcher() {
-        return new RecipientIs();
+        assertThat(matcher.match(fakeMail)).isEmpty();
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to