james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [03/10] james-project git commit: MAILET-116 port SubjectStartsWithTest to junit 4 and assertj
Date Mon, 05 Sep 2016 13:42:02 GMT
MAILET-116 port SubjectStartsWithTest to junit 4 and assertj


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

Branch: refs/heads/master
Commit: 63c48c0a2639f1187cb76d36211620a9bd93ac4e
Parents: 4a25501
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Tue Aug 30 15:38:41 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Mon Sep 5 14:17:50 2016 +0200

----------------------------------------------------------------------
 .../matchers/SubjectStartsWithTest.java         | 102 +++++++++++--------
 1 file changed, 58 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/63c48c0a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectStartsWithTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectStartsWithTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectStartsWithTest.java
index 285804f..673d6d4 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectStartsWithTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectStartsWithTest.java
@@ -20,56 +20,70 @@
 
 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 javax.mail.internet.AddressException;
 
-import org.apache.james.transport.matchers.SubjectStartsWith;
 import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
-
-public class SubjectStartsWithTest extends AbstractSubjectIsTest {
-
-    public SubjectStartsWithTest(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.apache.mailet.base.test.MailUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SubjectStartsWithTest {
+
+    private SubjectStartsWith matcher;
+    private MailAddress roger;
+
+    @Before
+    public void setup() throws AddressException {
+        matcher = new SubjectStartsWith();
+        roger = new MailAddress("roger@nasa.org");
     }
-
-    // test if the recipients get returned as matched
-    public void testHostIsMatchedAllRecipients() throws MessagingException {
-        String SUBJECT_NAME = "testSubject";
-        setSubject(SUBJECT_NAME);
-
-        setupAll();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+    
+    @Test
+    public void shouldMatchWhenSubjectStartsWithConfiguredValue() throws MessagingException
{
+        FakeMail mail = FakeMail.builder()
+                .recipients(roger)
+                .mimeMessage(MailUtil.createMimeMessageWithSubject("testSubject"))
+                .build();
+        
+        FakeMatcherConfig mailetConfig = new FakeMatcherConfig("SubjectIs=test", FakeMailContext.defaultContext());
+        
+        matcher.init(mailetConfig);
+
+        assertThat(matcher.match(mail)).containsExactly(roger);
     }
-
-    // test if no recipient get returned cause it not match
-    public void testHostIsNotMatch() throws MessagingException {
-        setSubject("FOOBAR");
-
-        setupAll();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNull(matchedRecipients);
-    }
-
-    protected Matcher createMatcher() {
-        return new SubjectStartsWith();
+    
+    @Test
+    public void shouldNotMatchWhenSubjectDoesntStartWithConfiguredValue() throws MessagingException
{
+        FakeMail mail = FakeMail.builder()
+                .recipients(roger)
+                .mimeMessage(MailUtil.createMimeMessageWithSubject("foobar"))
+                .build();
+        
+        FakeMatcherConfig mailetConfig = new FakeMatcherConfig("SubjectIs=test", FakeMailContext.defaultContext());
+        
+        matcher.init(mailetConfig);
+
+        assertThat(matcher.match(mail)).isNull();
     }
-
-    protected String getConfigOption() {
-        return "SubjectIs=";
-    }
-
-    protected String getSubjectName() {
-        return "test";
+    
+
+    @Test
+    public void shouldNotMatchWhenNoSubject() throws MessagingException {
+        FakeMail mail = FakeMail.builder()
+                .recipients(roger)
+                .mimeMessage(MailUtil.createMimeMessageWithSubject(null))
+                .build();
+        
+        FakeMatcherConfig mailetConfig = new FakeMatcherConfig("SubjectIs=test", FakeMailContext.defaultContext());
+        
+        matcher.init(mailetConfig);
+
+        assertThat(matcher.match(mail)).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