james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [04/10] james-project git commit: MAILET-116 port SubjectIsTest to junit 4 and assertj
Date Mon, 05 Sep 2016 13:42:03 GMT
MAILET-116 port SubjectIsTest 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/1c89c7c3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1c89c7c3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1c89c7c3

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

----------------------------------------------------------------------
 .../matchers/AbstractSubjectIsTest.java         | 85 -----------------
 .../james/transport/matchers/SubjectIsTest.java | 99 +++++++++++---------
 2 files changed, 56 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1c89c7c3/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
deleted file mode 100644
index b46a8b5..0000000
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractSubjectIsTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-
-package org.apache.james.transport.matchers;
-
-import java.io.UnsupportedEncodingException;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-
-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.apache.mailet.base.test.FakeMimeMessage;
-import org.apache.mailet.base.test.MailUtil;
-
-import junit.framework.TestCase;
-
-public abstract class AbstractSubjectIsTest extends TestCase {
-
-    protected FakeMail mockedMail;
-
-    protected Matcher matcher;
-
-    private String subject = null;
-
-    private FakeMimeMessage mockedMimeMessage;
-
-    public AbstractSubjectIsTest(String arg0)
-            throws UnsupportedEncodingException {
-        super(arg0);
-    }
-
-    protected void setSubject(String subject) {
-        this.subject = subject;
-    }
-
-    protected void setupMockedMail(MimeMessage m) {
-        mockedMail = new FakeMail();
-        mockedMail.setMessage(m);
-
-    }
-
-    protected void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = MailUtil.createMimeMessage("test", "test");
-        mockedMimeMessage.setSubject(subject);
-    }
-
-    protected void setupMatcher() throws MessagingException {
-        matcher = createMatcher();
-        FakeMatcherConfig mci = new FakeMatcherConfig(getConfigOption()
-                + getSubjectName(), FakeMailContext.defaultContext());
-        matcher.init(mci);
-    }
-
-    protected void setupAll() throws MessagingException {
-        setupMockedMimeMessage();
-        setupMockedMail(mockedMimeMessage);
-        setupMatcher();
-    }
-
-    protected abstract String getConfigOption();
-
-    protected abstract String getSubjectName();
-
-    protected abstract Matcher createMatcher();
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c89c7c3/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectIsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectIsTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectIsTest.java
index 2fd98c9..9e08582 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectIsTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SubjectIsTest.java
@@ -20,56 +20,69 @@
 
 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.SubjectIs;
 import org.apache.mailet.MailAddress;
-import org.apache.mailet.Matcher;
-
-public class SubjectIsTest extends AbstractSubjectIsTest {
-
-    private final String SUBJECT_NAME = "testSubject";
-
-    public SubjectIsTest(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 SubjectIsTest {
+
+    private SubjectIs matcher;
+    private MailAddress roger;
+
+    @Before
+    public void setup() throws AddressException {
+        matcher = new SubjectIs();
+        roger = new MailAddress("roger@nasa.org");
     }
-
-    // test if the recipients get returned as matched
-    public void testHostIsMatchedAllRecipients() throws MessagingException {
-        setSubject(SUBJECT_NAME);
-
-        setupAll();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNotNull(matchedRecipients);
-        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+    
+    @Test
+    public void shouldMatchWhenSubjectEqualsConfiguredValue() throws MessagingException {
+        FakeMail mail = FakeMail.builder()
+                .mimeMessage(MailUtil.createMimeMessageWithSubject("test"))
+                .recipients(roger)
+                .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("test");
-
-        setupAll();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        assertNull(matchedRecipients);
-    }
-
-    protected Matcher createMatcher() {
-        return new SubjectIs();
+    @Test
+    public void shouldNotMatchWhenSubjectDoesntEqualsConfiguredValue() throws MessagingException
{
+        FakeMail mail = FakeMail.builder()
+                .mimeMessage(MailUtil.createMimeMessageWithSubject("foobar"))
+                .recipients(roger)
+                .build();
+        
+        FakeMatcherConfig mailetConfig = new FakeMatcherConfig("SubjectIs=foo", FakeMailContext.defaultContext());
+        
+        matcher.init(mailetConfig);
+
+        assertThat(matcher.match(mail)).isNull();
     }
-
-    protected String getConfigOption() {
-        return "SubjectIs=";
-    }
-
-    protected String getSubjectName() {
-        return SUBJECT_NAME;
+    
+    @Test
+    public void shouldNotMatchWhenNoSubject() throws MessagingException {
+        FakeMail mail = FakeMail.builder()
+                .mimeMessage(MailUtil.createMimeMessageWithSubject(null))
+                .recipients(roger)
+                .build();
+        
+        FakeMatcherConfig mailetConfig = new FakeMatcherConfig("SubjectIs=foo", 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