james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [06/11] james-project git commit: MAILET-121 Upgrade code for SenderIsNull and related tests
Date Fri, 02 Sep 2016 06:23:31 GMT
MAILET-121 Upgrade code for SenderIsNull and related 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/a6b30bd0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a6b30bd0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a6b30bd0

Branch: refs/heads/master
Commit: a6b30bd0c8b28cd4d13295cc0fdd2ca85612024f
Parents: 5eb9b61
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Aug 31 15:16:43 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Sep 2 13:22:36 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/SenderIsNull.java  |  2 -
 .../transport/matchers/SenderIsNullTest.java    | 78 +++++++++-----------
 2 files changed, 35 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a6b30bd0/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsNull.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsNull.java
b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsNull.java
index 7607d4e..bd244ab 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsNull.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsNull.java
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.transport.matchers;
 
 import org.apache.mailet.base.GenericMatcher;

http://git-wip-us.apache.org/repos/asf/james-project/blob/a6b30bd0/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java
index a13bddb..1337792 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java
@@ -20,56 +20,48 @@
 
 package org.apache.james.transport.matchers;
 
-import java.io.UnsupportedEncodingException;
-import java.util.Collection;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import javax.mail.MessagingException;
-
-import org.apache.james.transport.matchers.SenderIsNull;
 import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
-
-public class SenderIsNullTest extends AbstractSenderIsTest {
-
-    public SenderIsNullTest(String arg0) throws UnsupportedEncodingException {
-        super(arg0);
+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.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class SenderIsNullTest {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    private SenderIsNull matcher;
+    private MailAddress recipient;
+
+    @Before
+    public void setUp() throws Exception {
+        matcher = new SenderIsNull();
+        matcher.init(new FakeMatcherConfig("SenderIsNull", FakeMailContext.defaultContext()));
+        recipient = new MailAddress("recipient@james.apache.org");
     }
 
-    // test if matched
-    public void testSenderIsMatchedAllRecipients() throws MessagingException {
-        setSender(null);
-
-        setupMockedMail();
-        setupMatcher();
+    @Test
+    public void shouldMatchWhenNullSender() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(recipient)
+            .build();
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+        assertThat(matcher.match(fakeMail)).containsExactly(recipient);
     }
 
-    // test if not matched
-    public void testSenderIsNotMatchedAllRecipients() throws MessagingException {
-        setSender(new MailAddress("t@james.apache.org"));
-
-        setupMockedMail();
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNull(matchedRecipients);
-    }
-
-    protected Matcher createMatcher() {
-        return new SenderIsNull();
-    }
-
-    protected String getConfigOption() {
-        return "SenderIsNull";
-    }
+    @Test
+    public void shouldNotMatchWhenSenderIsPresent() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(recipient)
+            .sender(new MailAddress("other@james.apache.org"))
+            .build();
 
-    protected String getConfigValue() {
-        return "";
+        assertThat(matcher.match(fakeMail)).isNull();
     }
 }


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