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 2018/08/30 13:16:02 UTC

[20/26] james-project git commit: JAMES-2529 Rewrite MailetPreconditionTest with JUNIT 5

JAMES-2529 Rewrite MailetPreconditionTest with JUNIT 5

Use nested classes to enhance readability


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

Branch: refs/heads/master
Commit: 7164031c3226c4bf8313335ffd7800683f7a0b30
Parents: a8a8a90
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 29 12:32:28 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Aug 30 15:11:55 2018 +0200

----------------------------------------------------------------------
 server/container/guice/protocols/jmap/pom.xml   |  18 +-
 .../james/jmap/MailetPreconditionTest.java      | 175 +++++++++++--------
 2 files changed, 115 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7164031c/server/container/guice/protocols/jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/pom.xml b/server/container/guice/protocols/jmap/pom.xml
index 9cce57a..df48b58 100644
--- a/server/container/guice/protocols/jmap/pom.xml
+++ b/server/container/guice/protocols/jmap/pom.xml
@@ -71,13 +71,23 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.assertj</groupId>
-            <artifactId>assertj-core</artifactId>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-launcher</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.vintage</groupId>
+            <artifactId>junit-vintage-engine</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>

http://git-wip-us.apache.org/repos/asf/james-project/blob/7164031c/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
index 04832d6..aaacbd9 100644
--- a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
+++ b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java
@@ -19,6 +19,9 @@
 
 package org.apache.james.jmap;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import java.util.List;
 
 import org.apache.commons.configuration.ConfigurationException;
@@ -31,88 +34,112 @@ import org.apache.james.transport.matchers.All;
 import org.apache.james.transport.matchers.RecipientIsLocal;
 import org.apache.mailet.MailetContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Test;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.Lists;
 
-public class MailetPreconditionTest {
+class MailetPreconditionTest {
 
     private static final MailetContext MAILET_CONTEXT = null;
     private static final String BCC = "bcc";
 
-    @Test(expected = ConfigurationException.class)
-    public void vacationMailetCheckShouldThrowOnEmptyList() throws Exception {
-        JMAPModule.VACATION_MAILET_CHECK.check(Lists.newArrayList());
-    }
-
-    @Test(expected = NullPointerException.class)
-    public void vacationMailetCheckShouldThrowOnNullList() throws Exception {
-        JMAPModule.VACATION_MAILET_CHECK.check(null);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void vacationMailetCheckShouldThrowOnWrongMatcher() throws Exception {
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), new VacationMailet(null, null, null, null, null)));
-        JMAPModule.VACATION_MAILET_CHECK.check(pairs);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void vacationMailetCheckShouldThrowOnWrongMailet() throws Exception {
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new RecipientIsLocal(), new Null()));
-        JMAPModule.VACATION_MAILET_CHECK.check(pairs);
-    }
-
-    @Test
-    public void vacationMailetCheckShouldNotThrowIfValidPairPresent() throws Exception {
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new RecipientIsLocal(), new VacationMailet(null, null, null, null, null)));
-        JMAPModule.VACATION_MAILET_CHECK.check(pairs);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void bccMailetCheckShouldThrowOnEmptyList() throws Exception {
-        CamelMailetContainerModule.BCC_Check.check(Lists.newArrayList());
-    }
-
-    @Test(expected = NullPointerException.class)
-    public void bccMailetCheckShouldThrowOnNullList() throws Exception {
-        CamelMailetContainerModule.BCC_Check.check(null);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void bccMailetCheckShouldThrowOnWrongMatcher() throws Exception {
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new RecipientIsLocal(),  new RemoveMimeHeader()));
-        CamelMailetContainerModule.BCC_Check.check(pairs);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void bccMailetCheckShouldThrowOnWrongMailet() throws Exception {
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), new Null()));
-        CamelMailetContainerModule.BCC_Check.check(pairs);
-    }
-
-    @Test(expected = ConfigurationException.class)
-    public void bccMailetCheckShouldThrowOnWrongFieldName() throws Exception {
-        RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader();
-        removeMimeHeader.init(FakeMailetConfig.builder()
-            .mailetName(BCC)
-            .mailetContext(MAILET_CONTEXT)
-            .setProperty("name", "bad")
-            .build());
-
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), removeMimeHeader));
-        CamelMailetContainerModule.BCC_Check.check(pairs);
+    @Nested
+    class VacationMailetCheck {
+        @Test
+        void vacationMailetCheckShouldThrowOnEmptyList() {
+            assertThatThrownBy(() -> JMAPModule.VACATION_MAILET_CHECK.check(Lists.newArrayList()))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void vacationMailetCheckShouldThrowOnNullList() {
+            assertThatThrownBy(() -> JMAPModule.VACATION_MAILET_CHECK.check(null))
+                .isInstanceOf(NullPointerException.class);
+        }
+
+        @Test
+        void vacationMailetCheckShouldThrowOnWrongMatcher() {
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), new VacationMailet(null, null, null, null, null)));
+
+            assertThatThrownBy(() -> JMAPModule.VACATION_MAILET_CHECK.check(pairs))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void vacationMailetCheckShouldThrowOnWrongMailet() {
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new RecipientIsLocal(), new Null()));
+
+            assertThatThrownBy(() -> JMAPModule.VACATION_MAILET_CHECK.check(pairs))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void vacationMailetCheckShouldNotThrowIfValidPairPresent() {
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new RecipientIsLocal(), new VacationMailet(null, null, null, null, null)));
+
+            assertThatCode(() -> JMAPModule.VACATION_MAILET_CHECK.check(pairs))
+                .doesNotThrowAnyException();
+        }
     }
 
-    @Test
-    public void bccMailetCheckShouldNotThrowOnValidPair() throws Exception {
-        RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader();
-        removeMimeHeader.init(FakeMailetConfig.builder()
-            .mailetName(BCC)
-            .mailetContext(MAILET_CONTEXT)
-            .setProperty("name", BCC)
-            .build());
-
-        List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), removeMimeHeader));
-        CamelMailetContainerModule.BCC_Check.check(pairs);
+    @Nested
+    class BccCheck {
+        @Test
+        void bccMailetCheckShouldThrowOnEmptyList() {
+            assertThatThrownBy(() -> CamelMailetContainerModule.BCC_Check.check(Lists.newArrayList()))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void bccMailetCheckShouldThrowOnNullList() {
+            assertThatThrownBy(() -> CamelMailetContainerModule.BCC_Check.check(null))
+                .isInstanceOf(NullPointerException.class);
+        }
+
+        @Test
+        void bccMailetCheckShouldThrowOnWrongMatcher() {
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new RecipientIsLocal(), new RemoveMimeHeader()));
+
+            assertThatThrownBy(() -> CamelMailetContainerModule.BCC_Check.check(pairs))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void bccMailetCheckShouldThrowOnWrongMailet() {
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), new Null()));
+
+            assertThatThrownBy(() -> CamelMailetContainerModule.BCC_Check.check(pairs))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void bccMailetCheckShouldThrowOnWrongFieldName() throws Exception {
+            RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader();
+            removeMimeHeader.init(FakeMailetConfig.builder()
+                .mailetName(BCC)
+                .mailetContext(MAILET_CONTEXT)
+                .setProperty("name", "bad")
+                .build());
+
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), removeMimeHeader));
+
+            assertThatThrownBy(() -> CamelMailetContainerModule.BCC_Check.check(pairs))
+                .isInstanceOf(ConfigurationException.class);
+        }
+
+        @Test
+        void bccMailetCheckShouldNotThrowOnValidPair() throws Exception {
+            RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader();
+            removeMimeHeader.init(FakeMailetConfig.builder()
+                .mailetName(BCC)
+                .mailetContext(MAILET_CONTEXT)
+                .setProperty("name", BCC)
+                .build());
+
+            List<MatcherMailetPair> pairs = Lists.newArrayList(new MatcherMailetPair(new All(), removeMimeHeader));
+            assertThatCode(() -> CamelMailetContainerModule.BCC_Check.check(pairs))
+                .doesNotThrowAnyException();
+        }
     }
 }


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