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/30 18:01:45 UTC

[10/10] james-project git commit: JAMES-1773 SizeGreaterThan matcher test should match our coding conventions

JAMES-1773 SizeGreaterThan matcher test 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/6b46cdf3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6b46cdf3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6b46cdf3

Branch: refs/heads/master
Commit: 6b46cdf394f9180dad4d3d5b77684277aca0b282
Parents: fc5e13a
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Aug 29 13:09:00 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Aug 31 00:59:27 2016 +0700

----------------------------------------------------------------------
 .../transport/matchers/SizeGreaterThanTest.java | 68 +++++++++-----------
 1 file changed, 30 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6b46cdf3/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java
index 230aac2..b197eff 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java
@@ -20,70 +20,62 @@
 
 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;
-import javax.mail.internet.ParseException;
 
 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.Assert;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.collect.ImmutableList;
 
 public class SizeGreaterThanTest {
 
-    private FakeMail mockedMail;
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
 
+    private FakeMail fakeMail;
     private Matcher matcher;
+    private MailAddress mailAddress;
 
-    private void setupMockedMail(long size) throws ParseException {
-        mockedMail = new FakeMail();
-        mockedMail.setMessageSize(size);
-        mockedMail.setRecipients(Arrays.asList(new MailAddress("test@email")));
-
-    }
-
-    private void setupMatcher(String size) throws MessagingException {
+    @Before
+    public void setUp() throws Exception {
         matcher = new SizeGreaterThan();
-        FakeMatcherConfig mci = new FakeMatcherConfig("SizeGreaterThan=" + size,
-                FakeMailContext.defaultContext());
-        matcher.init(mci);
-    }
 
+        fakeMail = new FakeMail();
+        mailAddress = new MailAddress("test@email");
+        fakeMail.setRecipients(ImmutableList.of(mailAddress));
+    }
 
     @Test
-    public void testSizeGreater() throws MessagingException {
-        setupMockedMail(2000000);
-        setupMatcher("1m");
+    public void matchShouldMatchWhenMailAboveSize() throws MessagingException {
+        fakeMail.setMessageSize(2000000);
+        FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1m", FakeMailContext.defaultContext());
+        matcher.init(matcherConfiguration);
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        Assert.assertNotNull(matchedRecipients);
-        Assert.assertEquals(matchedRecipients.size(), mockedMail.getRecipients().size());
+        assertThat(matcher.match(fakeMail)).containsExactly(mailAddress);
     }
 
     @Test
-    public void testSizeNotGreater() throws MessagingException {
-        setupMockedMail(200000);
-        setupMatcher("1m");
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+    public void matchShouldNotMatchWhenMailUnderSize() throws MessagingException {
+        fakeMail.setMessageSize(200000);
+        FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1m", FakeMailContext.defaultContext());
+        matcher.init(matcherConfiguration);
 
-        Assert.assertNull(matchedRecipients);
+        assertThat(matcher.match(fakeMail)).isNull();
     }
 
     @Test
-    public void testThrowExceptionOnInvalidAmount() {
-        boolean exception = false;
-        try {
-            setupMatcher("1mb");
-        } catch (MessagingException e) {
-            exception = true;
-        }
-        Assert.assertTrue("Exception thrown", exception);
+    public void initShouldThrowOnInvalidUnits() throws Exception {
+        expectedException.expect(MessagingException.class);
+        FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1mb", FakeMailContext.defaultContext());
+        matcher.init(matcherConfiguration);
     }
 }


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