james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [09/17] james-project git commit: MAILET-124 Provide tests for Xor composite matcher
Date Thu, 15 Sep 2016 10:08:50 GMT
MAILET-124 Provide tests for Xor composite matcher


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b626c0c9
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b626c0c9
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b626c0c9

Branch: refs/heads/master
Commit: b626c0c90ef57e0293ab9463304cac4832dfef4a
Parents: a86a67d
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Sep 1 15:15:29 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Sep 15 12:05:16 2016 +0200

----------------------------------------------------------------------
 .../mailetcontainer/impl/matchers/XorTest.java  | 87 ++++++++++++++------
 1 file changed, 60 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b626c0c9/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
index fe29bfc..c06aeaf 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java
@@ -18,51 +18,84 @@
  ****************************************************************/
 package org.apache.james.mailetcontainer.impl.matchers;
 
+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 static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES2;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
 import org.junit.Test;
 
-import javax.mail.MessagingException;
-import java.util.Collection;
-import java.util.Iterator;
+import com.google.common.collect.ImmutableList;
+
+public class XorTest {
 
-public class XorTest extends BaseMatchersTest {
+    private Xor testee;
+    private Matcher matcher1;
+    private Matcher matcher2;
+    private Mail mail;
 
-    @Override
     @Before
     public void setUp() throws Exception {
-        super.setUp();
-        setupCompositeMatcher("Xor", Xor.class);
+        matcher1 = mock(Matcher.class);
+        matcher2 = mock(Matcher.class);
+
+        testee = new Xor();
+
+        mail = FakeMail.builder().recipients(ANY_AT_JAMES, OTHER_AT_JAMES, ANY_AT_JAMES2,
OTHER_AT_JAMES2).build();
+    }
+
+    @Test
+    public void shouldReturnNoResultWhenNoMatcherSpecified() throws Exception {
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void shouldReturnMatchResultWhenOnlyOneMatcher() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2));
+
+        testee.add(matcher1);
+
+        assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES, ANY_AT_JAMES2);
     }
 
-    // test if all recipients was returned
     @Test
-    public void testIntersectSame() throws MessagingException {
-        setupChild("RecipientIsRegex=test@james.apache.org");
-        setupChild("RecipientIsRegex=test@james.apache.org");
+    public void shouldPerformXorWhenTwoMatchers() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2));
+        when(matcher2.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES));
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+        testee.add(matcher1);
+        testee.add(matcher2);
 
-        assertNotNull(matchedRecipients);
-        assertEquals(0, matchedRecipients.size());
+        assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES2, OTHER_AT_JAMES);
     }
 
     @Test
-    public void testNoIntersect() throws MessagingException {
-        setupChild("RecipientIsRegex=test@james.apache.org");
-        setupChild("RecipientIsRegex=test2@james.apache.org");
+    public void shouldAcceptEmptyResults() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2));
+        when(matcher2.match(mail)).thenReturn(ImmutableList.<MailAddress>of());
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+        testee.add(matcher1);
+        testee.add(matcher2);
+
+        assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES, ANY_AT_JAMES2);
+    }
+
+    @Test
+    public void shouldAcceptNullResults() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2));
+        when(matcher2.match(mail)).thenReturn(null);
 
-        assertNotNull(matchedRecipients);
-        assertEquals(2, matchedRecipients.size());
+        testee.add(matcher1);
+        testee.add(matcher2);
 
-        Iterator<MailAddress> iterator = matchedRecipients.iterator();
-        MailAddress address = (MailAddress) iterator.next();
-        assertEquals(address, "test@james.apache.org");
-        address = (MailAddress) iterator.next();
-        assertEquals(address, "test2@james.apache.org");
+        assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES, ANY_AT_JAMES2);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message