james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/11] james-project git commit: MAILET-121 Complete tests for SenderIs
Date Fri, 02 Sep 2016 06:23:26 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 085eebba9 -> 4a2550182


MAILET-121 Complete tests for SenderIs


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

Branch: refs/heads/master
Commit: 260b5ec484d0b9f7745674ef58d04ac9d191afd7
Parents: 1f6f1e2
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Aug 31 11:14:08 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Sep 2 13:22:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/SenderIsTest.java  | 37 ++++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/260b5ec4/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
index e0fc0e1..7b2297e 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsTest.java
@@ -22,30 +22,37 @@ package org.apache.james.transport.matchers;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import javax.mail.MessagingException;
+
 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.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 public class SenderIsTest {
 
     private final String SENDER_NAME = "test@james.apache.org";
 
-    private Matcher matcher;
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    private SenderIs matcher;
     private MailAddress recipient;
 
     @Before
     public void setUp() throws Exception {
         matcher = new SenderIs();
-        matcher.init(new FakeMatcherConfig("SenderIs=" + SENDER_NAME, FakeMailContext.defaultContext()));
         recipient = new MailAddress("recipient@james.apache.org");
     }
 
     @Test
     public void shouldMatchWhenGoodSender() throws Exception {
+        matcher.init(new FakeMatcherConfig("SenderIs=" + SENDER_NAME, FakeMailContext.defaultContext()));
+
         FakeMail fakeMail = FakeMail.builder()
             .recipient(recipient)
             .sender(new MailAddress(SENDER_NAME))
@@ -56,6 +63,8 @@ public class SenderIsTest {
 
     @Test
     public void shouldNotMatchWhenWrongSender() throws Exception {
+        matcher.init(new FakeMatcherConfig("SenderIs=" + SENDER_NAME, FakeMailContext.defaultContext()));
+
         FakeMail fakeMail = FakeMail.builder()
             .recipient(recipient)
             .sender(new MailAddress("other@james.apache.org"))
@@ -66,10 +75,32 @@ public class SenderIsTest {
 
     @Test
     public void shouldNotMatchWhenNullSender() throws Exception {
+        matcher.init(new FakeMatcherConfig("SenderIs=" + SENDER_NAME, FakeMailContext.defaultContext()));
+
         FakeMail fakeMail = FakeMail.builder()
             .recipient(recipient)
             .build();
 
         assertThat(matcher.match(fakeMail)).isNull();
     }
+
+    @Test
+    public void senderIsShouldBeConfigurableWithSeveralAddresses() throws Exception {
+        String mailAddress = "any@apache.org";
+        matcher.init(new FakeMatcherConfig("SenderIs=" + mailAddress + ", " + SENDER_NAME,
FakeMailContext.defaultContext()));
+
+        assertThat(matcher.getSenders()).containsExactly(new MailAddress(mailAddress), new
MailAddress(SENDER_NAME));
+    }
+
+    @Test
+    public void senderIsShouldThrowWhenNoAddressesPassedByConfiguration() throws Exception
{
+        expectedException.expect(MessagingException.class);
+        matcher.init(new FakeMatcherConfig("SenderIs=", FakeMailContext.defaultContext()));
+    }
+
+    @Test
+    public void senderIsShouldThrowWhenNoConfiguration() throws Exception {
+        expectedException.expect(MessagingException.class);
+        matcher.init(new FakeMatcherConfig("SenderIs", FakeMailContext.defaultContext()));
+    }
 }


---------------------------------------------------------------------
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