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 ad...@apache.org on 2016/11/09 07:57:53 UTC

james-project git commit: MAILET-138 SenderIsLocal should be covered with tests

Repository: james-project
Updated Branches:
  refs/heads/master b6cd9e261 -> e20b50b47


MAILET-138 SenderIsLocal should be covered with tests


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

Branch: refs/heads/master
Commit: e20b50b475f129bd0dc54ef1f4f1229b3ac09c1b
Parents: b6cd9e2
Author: Laura Royet <lr...@linagora.com>
Authored: Fri Nov 4 16:02:47 2016 +0100
Committer: Laura Royet <lr...@linagora.com>
Committed: Tue Nov 8 14:54:39 2016 +0100

----------------------------------------------------------------------
 .../james/transport/matchers/SenderIsLocal.java |  9 ++-
 .../transport/matchers/SenderIsLocalTest.java   | 82 ++++++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e20b50b4/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsLocal.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsLocal.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsLocal.java
index bb4c46b..4cf9db3 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsLocal.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIsLocal.java
@@ -32,7 +32,14 @@ import org.apache.mailet.base.GenericMatcher;
 public class SenderIsLocal extends GenericMatcher {
 
     public final Collection<MailAddress> match(Mail mail) throws MessagingException {
-        return (getMailetContext().isLocalEmail(mail.getSender())) ? mail.getRecipients(): null;
+        if (isLocal(mail.getSender())) {
+            return mail.getRecipients();
+        }
+        return null;
+    }
+
+    private boolean isLocal(MailAddress mailAddress) {
+        return getMailetContext().isLocalEmail(mailAddress);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e20b50b4/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
new file mode 100644
index 0000000..31f8251
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
@@ -0,0 +1,82 @@
+/****************************************************************
+ * 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 static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES;
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SenderIsLocalTest {
+
+    private Matcher matcher;
+
+    @Before
+    public void setUp() throws MessagingException {
+        MailetContext mailContext = mock(MailetContext.class);
+        when(mailContext.isLocalEmail(ANY_AT_JAMES)).thenReturn(true);
+        when(mailContext.isLocalEmail(ANY_AT_JAMES2)).thenReturn(false);
+        
+        matcher = new SenderIsLocal();
+        FakeMatcherConfig mci = new FakeMatcherConfig("SenderIsLocal", mailContext);
+        matcher.init(mci);
+    }
+
+    @Test
+    public void shouldMatchWhenLocalSender() throws MessagingException {
+        //Given
+        Mail mail = FakeMail.builder()
+            .sender(ANY_AT_JAMES)
+            .recipient(ANY_AT_JAMES2)
+            .build();
+        //When
+        Collection<MailAddress> actual = matcher.match(mail);
+        //Then
+        assertThat(actual).containsExactly(ANY_AT_JAMES2);
+    }
+
+    @Test
+    public void shouldNotMatchWhenSenderIsNotLocal() throws MessagingException {
+        //Given
+        Mail mail = FakeMail.builder()
+            .sender(ANY_AT_JAMES2)
+            .recipient(ANY_AT_JAMES)
+            .build();
+        //When
+        Collection<MailAddress> actual = matcher.match(mail);
+        //Then
+        assertThat(actual).isNull();
+    }
+
+}


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