james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/11] james-project git commit: MAILET-121 SenderIsTest should match our coding conventions
Date Fri, 02 Sep 2016 06:23:27 GMT
MAILET-121 SenderIsTest 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/1f6f1e2e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1f6f1e2e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1f6f1e2e

Branch: refs/heads/master
Commit: 1f6f1e2e33982107e1137ac816c365c7390e2578
Parents: 085eebb
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Aug 31 10:56:46 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Sep 2 13:22:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/SenderIsTest.java  | 72 ++++++++++----------
 1 file changed, 35 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1f6f1e2e/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
index 072b1f4..e0fc0e1 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
@@ -20,58 +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 javax.mail.MessagingException;
-
-import org.apache.james.transport.matchers.SenderIs;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.Matcher;
+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;
 
-public class SenderIsTest extends AbstractSenderIsTest {
+public class SenderIsTest {
 
     private final String SENDER_NAME = "test@james.apache.org";
 
-    public SenderIsTest(String arg0) throws UnsupportedEncodingException {
-        super(arg0);
-    }
-
-    // test if matched
-    public void testSenderIsMatchedAllRecipients() throws MessagingException {
-        setSender(new MailAddress(SENDER_NAME));
-
-        setupMockedMail();
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+    private Matcher matcher;
+    private MailAddress recipient;
 
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+    @Before
+    public void setUp() throws Exception {
+        matcher = new SenderIs();
+        matcher.init(new FakeMatcherConfig("SenderIs=" + SENDER_NAME, FakeMailContext.defaultContext()));
+        recipient = new MailAddress("recipient@james.apache.org");
     }
 
-    // test if not matched
-    public void testSenderIsNotMatchedAllRecipients() throws MessagingException {
-        setSender(new MailAddress("t@james.apache.org"));
+    @Test
+    public void shouldMatchWhenGoodSender() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(recipient)
+            .sender(new MailAddress(SENDER_NAME))
+            .build();
 
-        setupMockedMail();
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNull(matchedRecipients);
+        assertThat(matcher.match(fakeMail)).containsExactly(recipient);
     }
 
-    protected Matcher createMatcher() {
-        return new SenderIs();
-    }
+    @Test
+    public void shouldNotMatchWhenWrongSender() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(recipient)
+            .sender(new MailAddress("other@james.apache.org"))
+            .build();
 
-    protected String getConfigOption() {
-        return "SenderIs=";
+        assertThat(matcher.match(fakeMail)).isNull();
     }
 
-    protected String getConfigValue() {
-        return SENDER_NAME;
+    @Test
+    public void shouldNotMatchWhenNullSender() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(recipient)
+            .build();
+
+        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