james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/17] james-project git commit: MAILET-124 Upgrade OrTest
Date Thu, 15 Sep 2016 10:08:49 GMT
MAILET-124 Upgrade OrTest


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

Branch: refs/heads/master
Commit: e114c6d14931b651d4e68f8186e7a61749616c7c
Parents: 2a996ba
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Sep 1 14:24:59 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Sep 15 12:04:57 2016 +0200

----------------------------------------------------------------------
 .../mailetcontainer/impl/matchers/OrTest.java   | 85 +++++++++++++++-----
 1 file changed, 64 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e114c6d1/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
index 373e790..d71ee19 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java
@@ -19,41 +19,84 @@
 
 package org.apache.james.mailetcontainer.impl.matchers;
 
+import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_1;
+import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_2;
+import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_3_OTHER_DOMAIN;
+import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_4_OTHER_DOMAIN;
+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 java.util.Collection;
-import java.util.Iterator;
+import com.google.common.collect.ImmutableList;
+
+public class OrTest {
 
-public class OrTest extends BaseMatchersTest {
+    private Or testee;
+    private Matcher matcher1;
+    private Matcher matcher2;
+    private Mail mail;
 
-    @Override
     @Before
     public void setUp() throws Exception {
-        super.setUp();
-        setupCompositeMatcher("Or", Or.class);
+        matcher1 = mock(Matcher.class);
+        matcher2 = mock(Matcher.class);
+
+        testee = new Or();
+
+        mail = FakeMail.builder().recipients(MAIL_ADDRESS_1, MAIL_ADDRESS_2, MAIL_ADDRESS_3_OTHER_DOMAIN,
MAIL_ADDRESS_4_OTHER_DOMAIN).build();
+    }
+
+    @Test
+    public void shouldReturnNoResultWhenNoMatcherSpecified() throws Exception {
+        assertThat(testee.match(mail)).isEmpty();
+    }
+
+    @Test
+    public void shouldReturnMatchResultWhenOnlyOneMatcher() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN));
+
+        testee.add(matcher1);
+
+        assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN);
     }
 
-    // test if all recipients was returned
     @Test
-    public void testAllRecipientsReturned() throws Exception {
-        setupChild("RecipientIsRegex=test@james.apache.org");
-        setupChild("RecipientIsRegex=test2@james.apache.org");
+    public void shouldReturnUnionWhenTwoMatchers() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN));
+        when(matcher2.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_2));
+
+        testee.add(matcher1);
+        testee.add(matcher2);
+
+        assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN,
MAIL_ADDRESS_2);
+    }
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+    @Test
+    public void shouldAcceptEmptyResults() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN));
+        when(matcher2.match(mail)).thenReturn(ImmutableList.<MailAddress>of());
 
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), mockedMail.getRecipients().size());
+        testee.add(matcher1);
+        testee.add(matcher2);
 
-        // Now ensure they match the actual recipients
-        Iterator<MailAddress> iterator = matchedRecipients.iterator();
-        MailAddress address = iterator.next();
-        assertEquals(address, "test@james.apache.org");
-        address = iterator.next();
-        assertEquals(address, "test2@james.apache.org");
+        assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN);
     }
 
+    @Test
+    public void shouldAcceptNullResults() throws Exception {
+        when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN));
+        when(matcher2.match(mail)).thenReturn(null);
+
+        testee.add(matcher1);
+        testee.add(matcher2);
+
+        assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN);
+    }
 }


---------------------------------------------------------------------
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