james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [10/10] james-project git commit: JAMES-1773 HasHeaderTest should match our coding standards
Date Thu, 18 Aug 2016 10:19:33 GMT
JAMES-1773 HasHeaderTest should match our coding standards


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

Branch: refs/heads/master
Commit: c94a99f5492a167cf9657263fa3648b1474fb3d1
Parents: 932acf5
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Aug 9 11:33:25 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HasHeaderTest.java | 73 +++++---------------
 1 file changed, 19 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c94a99f5/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
index d656296..6b40cec 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
@@ -20,81 +20,46 @@
 
 package org.apache.james.transport.matchers;
 
-import org.apache.james.transport.matchers.HasHeader;
-import org.apache.mailet.MailAddress;
+import static org.assertj.core.api.Assertions.assertThat;
+
+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.MailUtil;
-import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import java.util.Collection;
-
 public class HasHeaderTest {
 
-    private MimeMessage mockedMimeMessage;
+    private static final String HEADER_NAME_1 = "JUNIT";
+    private static final String HEADER_NAME_2 = "defaultHeaderName";
+    private static final String HEADER_VALUE_1 = "defaultHeaderValue";
 
     private FakeMail mockedMail;
-
     private Matcher matcher;
 
-    private final String HEADER_NAME = "JUNIT";
-
-    private String headerName = "defaultHeaderName";
-
-    private String headerValue = "defaultHeaderValue";
-
-    private void setHeaderName(String headerName) {
-        this.headerName = headerName;
-    }
-
-    private void setHeaderValue(String headerValue) {
-        this.headerValue = headerValue;
-    }
-
-    private void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = MailUtil.createMimeMessage(headerName, headerValue);
-    }
-
-    private void setupMatcher() throws MessagingException {
-        setupMockedMimeMessage();
+    @Before
+    public void setUp() throws Exception {
+        MimeMessage mimeMessage = MailUtil.createMimeMessage(HEADER_NAME_1, HEADER_VALUE_1);
+        mockedMail = MailUtil.createMockMail2Recipients(mimeMessage);
         matcher = new HasHeader();
-        FakeMatcherConfig mci = new FakeMatcherConfig("HasHeader="
-                + HEADER_NAME, new FakeMailContext());
-        matcher.init(mci);
     }
 
-    // test if the Header was matched
     @Test
-    public void testHeaderIsMatched() throws MessagingException {
-        setHeaderName(HEADER_NAME);
-        String HEADER_VALUE = "test-value";
-        setHeaderValue(HEADER_VALUE);
-
-        setupMockedMimeMessage();
-        mockedMail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
-        setupMatcher();
+    public void matchShouldReturnAddressesWhenRightHeaderNameWithoutValue() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1, new FakeMailContext()));
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        Assert.assertNotNull(matchedRecipients);
-        Assert.assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+        assertThat(matcher.match(mockedMail)).containsAll(mockedMail.getRecipients());
     }
 
-    // test if the Header was not matched
     @Test
-    public void testHeaderIsNotMatched() throws MessagingException {
-        setupMockedMimeMessage();
-        mockedMail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+    public void matchShouldReturnNullWhenWrongHeaderNameWithoutValue() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_2, new FakeMailContext()));
 
-        Assert.assertNull(matchedRecipients);
+        assertThat(matcher.match(mockedMail)).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