You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2016/08/29 10:39:28 UTC

[5/5] james-project git commit: MAILET-109 HostIsTest should match our coding conventions

MAILET-109 HostIsTest 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/18bca984
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/18bca984
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/18bca984

Branch: refs/heads/master
Commit: 18bca984986fae7bfad9eda72865441dc0fb80ca
Parents: 262f0f2
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 17 13:15:08 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Aug 29 17:38:49 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HostIsTest.java    | 77 +++++++-------------
 1 file changed, 26 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/18bca984/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java
index 65715a3..b2cb5d6 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java
@@ -17,11 +17,9 @@
  * under the License.                                           *
  ****************************************************************/
 
-
 package org.apache.james.transport.matchers;
 
-import java.util.Arrays;
-import java.util.Collection;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import javax.mail.MessagingException;
 
@@ -30,80 +28,57 @@ 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.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-public class HostIsTest {
+import com.google.common.collect.ImmutableList;
 
-    private FakeMail mockedMail;
+public class HostIsTest {
+    public static final String JAMES_APACHE_ORG = "james.apache.org";
+    public static final String JAMES2_APACHE_ORG = "james2.apache.org";
 
+    private FakeMail fakeMail;
     private Matcher matcher;
 
-    private MailAddress[] recipients;
-
-    private void setRecipients(MailAddress[] recipients) {
-        this.recipients = recipients;
-    }
-
-    private void setupMockedMail() {
-        mockedMail = new FakeMail();
-        mockedMail.setRecipients(Arrays.asList(recipients));
-
-    }
+    @Before
+    public void setUp() throws Exception {
+        fakeMail = new FakeMail();
 
-    private void setupMatcher() throws MessagingException {
         matcher = new HostIs();
-        String HOST_NAME = "james.apache.org";
-        FakeMatcherConfig mci = new FakeMatcherConfig("HostIs=" + HOST_NAME,
-                new FakeMailContext());
+        FakeMatcherConfig mci = new FakeMatcherConfig("HostIs=" + JAMES_APACHE_ORG, new FakeMailContext());
         matcher.init(mci);
     }
 
     // test if all recipients get returned as matched
     @Test
     public void testHostIsMatchedAllRecipients() throws MessagingException {
-        setRecipients(new MailAddress[]{
-                new MailAddress("test@james.apache.org"),
-                new MailAddress("test2@james.apache.org")});
-
-        setupMockedMail();
-        setupMatcher();
+        MailAddress mailAddress1 = new MailAddress("test@" + JAMES_APACHE_ORG);
+        MailAddress mailAddress2 = new MailAddress("test2@" + JAMES_APACHE_ORG);
+        fakeMail.setRecipients(ImmutableList.of(
+            mailAddress1,
+            mailAddress2));
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        Assert.assertNotNull(matchedRecipients);
-        Assert.assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+        assertThat(matcher.match(fakeMail)).containsExactly(mailAddress1, mailAddress2);
     }
 
     // test if one recipients get returned as matched
     @Test
     public void testHostIsMatchedOneRecipient() throws MessagingException {
-        setRecipients(new MailAddress[]{
-                new MailAddress("test@james2.apache.org"),
-                new MailAddress("test2@james.apache.org")});
-
-        setupMockedMail();
-        setupMatcher();
+        MailAddress matchingAddress = new MailAddress("test2@" + JAMES_APACHE_ORG);
+        fakeMail.setRecipients(ImmutableList.of(
+            new MailAddress("test@" + JAMES2_APACHE_ORG),
+            matchingAddress));
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        Assert.assertNotNull(matchedRecipients);
-        Assert.assertEquals(matchedRecipients.size(), 1);
+        assertThat(matcher.match(fakeMail)).containsExactly(matchingAddress);
     }
 
     // test if no recipient get returned cause it not match
     @Test
     public void testHostIsNotMatch() throws MessagingException {
-        setRecipients(new MailAddress[]{
-                new MailAddress("test@james2.apache.org"),
-                new MailAddress("test2@james2.apache.org")});
-
-        setupMockedMail();
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+        fakeMail.setRecipients(ImmutableList.of(
+            new MailAddress("test@" + JAMES2_APACHE_ORG),
+            new MailAddress("test2@" + JAMES2_APACHE_ORG)));
 
-        Assert.assertEquals(matchedRecipients.size(), 0);
+        assertThat(matcher.match(fakeMail)).isEmpty();
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org