You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2016/09/15 10:08:47 UTC
[06/17] james-project git commit: MAILET-122 Improve And tests
MAILET-122 Improve And tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2a996bad
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2a996bad
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2a996bad
Branch: refs/heads/master
Commit: 2a996badaf1884ab74f8ff8aef91f68558649a82
Parents: 12df8f9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Sep 1 14:10:49 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Sep 15 12:04:53 2016 +0200
----------------------------------------------------------------------
.../mailetcontainer/impl/matchers/AndTest.java | 84 ++++++++++++++------
1 file changed, 60 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/2a996bad/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java
index e5ca169..1ec5d76 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java
@@ -18,47 +18,83 @@
****************************************************************/
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.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 com.google.common.collect.ImmutableList;
+
+public class AndTest {
-public class AndTest extends BaseMatchersTest {
+ private And testee;
+ private Matcher matcher1;
+ private Matcher matcher2;
+ private Mail mail;
- @Override
@Before
public void setUp() throws Exception {
- super.setUp();
- setupCompositeMatcher("And", And.class);
+ matcher1 = mock(Matcher.class);
+ matcher2 = mock(Matcher.class);
+
+ testee = new And();
+
+ mail = FakeMail.builder().recipients(ANY_AT_JAMES, OTHER_AT_JAMES, ANY_AT_JAMES2).build();
+ }
+
+ @Test
+ public void shouldNotMatchWhenNoChild() throws Exception {
+ assertThat(testee.match(mail)).isNull();
+ }
+
+ @Test
+ public void shouldMatchWhenSingleUnderlyingMatcherMatch() throws Exception {
+ when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES));
+
+ testee.add(matcher1);
+
+ assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES);
+ }
+
+ @Test
+ public void shouldMatchWhenTwoUnderlyingMatcherMatch() throws Exception {
+ when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES));
+ when(matcher2.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2));
+
+ testee.add(matcher1);
+ testee.add(matcher2);
+
+ assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES);
}
- // test if all recipients was returned
@Test
- public void testAndIntersectSameTwice() throws MessagingException {
- setupChild("RecipientIs=test@james.apache.org");
- setupChild("RecipientIs=test@james.apache.org");
- setupChild("All");
+ public void shouldMatchWhenAtLeastOneUnderlyingMatcherDoNotMatch() throws Exception {
+ when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES));
+ when(matcher2.match(mail)).thenReturn(ImmutableList.<MailAddress>of());
- Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+ testee.add(matcher1);
+ testee.add(matcher2);
- assertNotNull(matchedRecipients);
- assertEquals(1, matchedRecipients.size());
- MailAddress address = (MailAddress) matchedRecipients.iterator().next();
- assertEquals(address.toString(), "test@james.apache.org");
+ assertThat(testee.match(mail)).isNull();
}
@Test
- public void testAndNoIntersect() throws MessagingException {
- setupChild("RecipientIs=test@james.apache.org");
- setupChild("RecipientIs=test2@james.apache.org");
+ public void shouldSupportNull() throws Exception {
+ when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES));
+ when(matcher2.match(mail)).thenReturn(null);
- Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+ testee.add(matcher1);
+ testee.add(matcher2);
- assertNotNull(matchedRecipients);
- assertEquals(0, matchedRecipients.size());
+ assertThat(testee.match(mail)).isNull();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org