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 2019/12/03 02:32:20 UTC

[james-project] 01/09: JAMES-2988 Rewrite FetchGroupConverterTest with junit5 parameters

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6ce2a5f630ae434c505db9c495dd929039e35d57
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Nov 28 11:04:27 2019 +0700

    JAMES-2988 Rewrite FetchGroupConverterTest with junit5 parameters
---
 mailbox/store/pom.xml                              |   5 +
 .../store/mail/FetchGroupConverterTest.java        | 120 +++++----------------
 2 files changed, 33 insertions(+), 92 deletions(-)

diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 291c43c..6e4d32a 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -129,6 +129,11 @@
             <version>1.11.3</version>
         </dependency>
         <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-params</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
index 07c92e9..ed93a81 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
@@ -21,101 +21,37 @@ package org.apache.james.mailbox.store.mail;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.stream.Stream;
+
 import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.MimePath;
-import org.junit.jupiter.api.Test;
+import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 class FetchGroupConverterTest {
-    @Test
-    void getFetchTypeShouldReturnMetadataWhenMinimal() {
-        assertThat(FetchGroupConverter.getFetchType(FetchGroup.MINIMAL))
-            .isEqualTo(MessageMapper.FetchType.Metadata);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnHeadersWhenHeaders() {
-        assertThat(FetchGroupConverter.getFetchType(FetchGroup.HEADERS))
-            .isEqualTo(MessageMapper.FetchType.Headers);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnBodyContentWhenBody() {
-        assertThat(FetchGroupConverter.getFetchType(FetchGroup.BODY_CONTENT))
-            .isEqualTo(MessageMapper.FetchType.Body);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenBodyAndHeaders() {
-        FetchGroup fetchGroup = FetchGroup.BODY_CONTENT
-            .with(FetchGroup.HEADERS_MASK);
-
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenFull() {
-        assertThat(FetchGroupConverter.getFetchType(FetchGroup.FULL_CONTENT))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimeContent() {
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .with(FetchGroup.MIME_CONTENT_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimeDescriptor() {
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .with(FetchGroup.MIME_DESCRIPTOR_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimeHeaders() {
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .with(FetchGroup.MIME_HEADERS_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimePartIsReadMinimally() {
-        int[] parts = {12};
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .addPartContent(new MimePath(parts), FetchGroup.MINIMAL_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimePartHeadersIsRead() {
-        int[] parts = {12};
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .addPartContent(new MimePath(parts), FetchGroup.HEADERS_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimePartBodyIsRead() {
-        int[] parts = {12};
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .addPartContent(new MimePath(parts), FetchGroup.BODY_CONTENT_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
-    }
-
-    @Test
-    void getFetchTypeShouldReturnFullWhenMimePartIsFullyRead() {
-        int[] parts = {12};
-        FetchGroup fetchGroup = FetchGroup.MINIMAL
-            .addPartContent(new MimePath(parts), FetchGroup.FULL_CONTENT_MASK);
-        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
-            .isEqualTo(MessageMapper.FetchType.Full);
+    private static final int[] PARTS = new int[]{12};
+
+    static Stream<Arguments> getFetchTypeShouldReturnCorrectValue() {
+        return Stream.of(
+            Arguments.arguments(FetchGroup.MINIMAL, FetchType.Metadata),
+            Arguments.arguments(FetchGroup.HEADERS, FetchType.Headers),
+            Arguments.arguments(FetchGroup.BODY_CONTENT, FetchType.Body),
+            Arguments.arguments(FetchGroup.FULL_CONTENT, FetchType.Full),
+            Arguments.arguments(FetchGroup.BODY_CONTENT.with(FetchGroup.HEADERS_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.with(FetchGroup.MIME_CONTENT_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.with(FetchGroup.MIME_DESCRIPTOR_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.with(FetchGroup.MIME_HEADERS_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.addPartContent(new MimePath(PARTS), FetchGroup.MINIMAL_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.addPartContent(new MimePath(PARTS), FetchGroup.HEADERS_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.addPartContent(new MimePath(PARTS), FetchGroup.BODY_CONTENT_MASK), FetchType.Full),
+            Arguments.arguments(FetchGroup.MINIMAL.addPartContent(new MimePath(PARTS), FetchGroup.FULL_CONTENT_MASK), FetchType.Full));
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void getFetchTypeShouldReturnCorrectValue(FetchGroup fetchGroup, FetchType expected) {
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup)).isEqualTo(expected);
     }
 }
\ No newline at end of file


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