james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/2] james-project git commit: JSIEVE-108 Add unit test for DiscardAction flags removal
Date Wed, 07 Jun 2017 02:56:55 GMT
Repository: james-project
Updated Branches:
  refs/heads/master ffd836d54 -> a54f1ee0c


JSIEVE-108 Add unit test for DiscardAction flags removal


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

Branch: refs/heads/master
Commit: a54f1ee0c86fae5d2cc8b414ef176c53c56b1c1c
Parents: 3a005e0
Author: benwa <btellier@linagora.com>
Authored: Tue May 9 11:46:01 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 09:50:36 2017 +0700

----------------------------------------------------------------------
 .../mailets/jsieve/DiscardActionTest.java       | 84 ++++++++++++++++++++
 1 file changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a54f1ee0/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/DiscardActionTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/DiscardActionTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/DiscardActionTest.java
new file mode 100644
index 0000000..1d83233
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/jsieve/DiscardActionTest.java
@@ -0,0 +1,84 @@
+/*
+ *   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.mailets.jsieve;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.mailet.base.MailAddressFixture;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Test;
+
+public class DiscardActionTest {
+
+    @Test
+    public void removeRecipientShouldWorkWhenOnlyOneRecipient() throws Exception {
+        FakeMail mail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .build();
+        ActionContext actionContext = mock(ActionContext.class);
+        when(actionContext.getRecipient()).thenReturn(MailAddressFixture.ANY_AT_JAMES);
+
+        DiscardAction.removeRecipient(mail, actionContext);
+
+        assertThat(mail.getRecipients()).isEmpty();
+    }
+
+    @Test
+    public void removeRecipientShouldNotThrowWhenRecipientIsAbsent() throws Exception {
+        FakeMail mail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .build();
+        ActionContext actionContext = mock(ActionContext.class);
+        when(actionContext.getRecipient()).thenReturn(MailAddressFixture.OTHER_AT_JAMES);
+
+        DiscardAction.removeRecipient(mail, actionContext);
+
+        assertThat(mail.getRecipients()).containsOnly(MailAddressFixture.ANY_AT_JAMES);
+    }
+
+    @Test
+    public void removeRecipientShouldNotThrowWhenRecipientIsNull() throws Exception {
+        FakeMail mail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .build();
+        ActionContext actionContext = mock(ActionContext.class);
+        when(actionContext.getRecipient()).thenReturn(null);
+
+        DiscardAction.removeRecipient(mail, actionContext);
+
+        assertThat(mail.getRecipients()).containsOnly(MailAddressFixture.ANY_AT_JAMES);
+    }
+
+    @Test
+    public void removeRecipientShouldRemoveOnlyTheConcernedRecipient() throws Exception {
+        FakeMail mail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES)
+            .build();
+        ActionContext actionContext = mock(ActionContext.class);
+        when(actionContext.getRecipient()).thenReturn(MailAddressFixture.ANY_AT_JAMES);
+
+        DiscardAction.removeRecipient(mail, actionContext);
+
+        assertThat(mail.getRecipients()).containsOnly(MailAddressFixture.OTHER_AT_JAMES);
+    }
+}


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