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 2017/08/18 02:48:13 UTC

[5/8] james-project git commit: JAMES-2107 fix warnings about assertj generic arrays and errors on generic streams

JAMES-2107 fix warnings about assertj generic arrays and errors on generic streams


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

Branch: refs/heads/master
Commit: 2f7eba1273df167c250baeaa3f94d46287aa2c9c
Parents: b87f9fc
Author: Matthieu Baechler <ma...@apache.org>
Authored: Wed Aug 16 15:57:51 2017 +0200
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Thu Aug 17 13:27:29 2017 +0200

----------------------------------------------------------------------
 backends-common/pom.xml                         |  3 +-
 .../cassandra/mail/utils/DataChunkerTest.java   | 44 +++++-------------
 mailbox/pom.xml                                 |  3 +-
 .../store/search/CombinedComparatorTest.java    | 12 -----
 mailet/pom.xml                                  |  7 ++-
 mpt/pom.xml                                     |  3 +-
 protocols/pom.xml                               |  3 +-
 .../apache/james/utils/ConfigurablesTest.java   |  1 -
 server/pom.xml                                  |  3 +-
 .../jmap/methods/GetMessagesMethodTest.java     | 47 ++++++++------------
 10 files changed, 37 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/backends-common/pom.xml
----------------------------------------------------------------------
diff --git a/backends-common/pom.xml b/backends-common/pom.xml
index e4a2b3c..40f093d 100644
--- a/backends-common/pom.xml
+++ b/backends-common/pom.xml
@@ -34,7 +34,6 @@
     <inceptionYear>2015</inceptionYear>
 
     <properties>
-        <assertj.version>3.2.0</assertj.version>
         <junit.version>4.11</junit.version>
         <slf4j.version>1.7.25</slf4j.version>
     </properties>
@@ -70,7 +69,7 @@
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
-                <version>${assertj.version}</version>
+                <version>3.8.0</version>
             </dependency>
             <dependency>
                 <groupId>org.slf4j</groupId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DataChunkerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DataChunkerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DataChunkerTest.java
index ccb5e4f..3d237a5 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DataChunkerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DataChunkerTest.java
@@ -21,24 +21,16 @@ package org.apache.james.mailbox.cassandra.mail.utils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.List;
 import java.util.stream.Stream;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
-import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Charsets;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.primitives.Bytes;
 
@@ -82,8 +74,9 @@ public class DataChunkerTest {
     @Test
     public void chunkShouldReturnOneEmptyArrayWhenInputEmpty() {
         Stream<Pair<Integer, ByteBuffer>> chunks = testee.chunk(new byte[0], CHUNK_SIZE);
-        assertThat(toArraysWithPosition(chunks))
-            .containsOnly(Pair.of(0, ImmutableList.of()));
+        ByteBuffer emptyBuffer = ByteBuffer.wrap(new byte[0]);
+        assertThat(chunks)
+            .containsOnlyElementsOf(ImmutableList.of(Pair.of(0, emptyBuffer)));
     }
 
     @Test
@@ -92,8 +85,8 @@ public class DataChunkerTest {
 
         Stream<Pair<Integer, ByteBuffer>> chunks = testee.chunk(data, CHUNK_SIZE);
 
-        assertThat(toArraysWithPosition(chunks))
-            .containsOnly(Pair.of(0, ImmutableList.copyOf(ArrayUtils.toObject(data))));
+        assertThat(chunks)
+            .containsOnlyElementsOf(ImmutableList.of(Pair.of(0, ByteBuffer.wrap(data))));
     }
 
     @Test
@@ -103,8 +96,8 @@ public class DataChunkerTest {
 
         Stream<Pair<Integer, ByteBuffer>> chunks = testee.chunk(data, CHUNK_SIZE);
 
-        assertThat(toArraysWithPosition(chunks))
-            .containsOnly(Pair.of(0, ImmutableList.copyOf(ArrayUtils.toObject(data))));
+        assertThat(chunks)
+            .containsOnlyElementsOf(ImmutableList.of(Pair.of(0, ByteBuffer.wrap(data))));
     }
 
     @Test
@@ -115,25 +108,10 @@ public class DataChunkerTest {
 
         Stream<Pair<Integer, ByteBuffer>> chunks = testee.chunk(data, CHUNK_SIZE);
 
-        assertThat(toArraysWithPosition(chunks))
-            .containsOnly(
-                Pair.of(0, ImmutableList.copyOf(ArrayUtils.toObject(part1))),
-                Pair.of(1, ImmutableList.copyOf(ArrayUtils.toObject(part2))));
-    }
-
-    private ImmutableList<Pair<Integer, List<Byte>>> toArraysWithPosition(Stream<Pair<Integer, ByteBuffer>> chunks) {
-        return chunks
-            .map(this::toByteArrayPair)
-            .collect(Guavate.toImmutableList());
-    }
-
-    private Pair<Integer, List<Byte>> toByteArrayPair(Pair<Integer, ByteBuffer> pair) {
-        try {
-            Byte[] bytes = ArrayUtils.toObject(IOUtils.toByteArray(new ByteBufferBackedInputStream(pair.getRight())));
-            return Pair.of(pair.getKey(), Arrays.asList(bytes));
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
+        assertThat(chunks)
+        .containsOnlyElementsOf(ImmutableList.of(
+                Pair.of(0, ByteBuffer.wrap(part1)),
+                Pair.of(1, ByteBuffer.wrap(part2))));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/pom.xml b/mailbox/pom.xml
index ffacd09..3a5e5cd 100644
--- a/mailbox/pom.xml
+++ b/mailbox/pom.xml
@@ -106,7 +106,6 @@
         <guava.version>18.0</guava.version>
         <jackson-databinding.version>2.6.3</jackson-databinding.version>
         <cassandra-unit.version>2.1.9.2</cassandra-unit.version>
-        <assertj.version>3.2.0</assertj.version>
         <logback.version>1.1.7</logback.version>
     </properties>
 
@@ -484,7 +483,7 @@
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
-                <version>${assertj.version}</version>
+                <version>3.8.0</version>
             </dependency>
             <!--
                 END Testing

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
index 8376687..9277646 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
@@ -61,84 +61,72 @@ public class CombinedComparatorTest {
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertInternalDate() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Arrival))).getComparators())
             .containsOnly(InternalDateComparator.INTERNALDATE);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertCc() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxCc))).getComparators())
             .containsOnly(HeaderMailboxComparator.CC_COMPARATOR);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertFrom() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxFrom))).getComparators())
             .containsOnly(HeaderMailboxComparator.FROM_COMPARATOR);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertTo() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxTo))).getComparators())
             .containsOnly(HeaderMailboxComparator.TO_COMPARATOR);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertSize() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Size))).getComparators())
             .containsOnly(SizeComparator.SIZE);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertBaseSubject() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.BaseSubject))).getComparators())
             .containsOnly(BaseSubjectComparator.BASESUBJECT);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertUid() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Uid))).getComparators())
             .containsOnly(UidComparator.UID);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertSentDate() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.SentDate))).getComparators())
             .containsOnly(SentDateComparator.SENTDATE);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertDisplayTo() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayTo))).getComparators())
             .containsOnly(HeaderDisplayComparator.TO_COMPARATOR);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertDisplayFrom() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayFrom))).getComparators())
             .containsOnly(HeaderDisplayComparator.FROM_COMPARATOR);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldConvertId() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Id))).getComparators())
             .containsOnly(MessageIdComparator.MESSAGE_ID_COMPARATOR);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void createShouldReverse() {
         assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayFrom, Order.REVERSE))).getComparators())
             .containsOnly(new ReverseComparator(HeaderDisplayComparator.FROM_COMPARATOR));

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/mailet/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/pom.xml b/mailet/pom.xml
index 1106b35..6bc33e4 100644
--- a/mailet/pom.xml
+++ b/mailet/pom.xml
@@ -54,8 +54,6 @@
         <maven-reporting-api.version>3.0</maven-reporting-api.version>
         <mime4j.version>0.8.1</mime4j.version>
         <qdox.version>1.12.1</qdox.version>
-        <assertj.version>3.3.0</assertj.version>
-        <assertj-guava.version>3.1.0</assertj-guava.version>
         <slf4j.version>1.7.25</slf4j.version>
         <jackson-data.version>2.6.3</jackson-data.version>
         <ical4j.version>2.0.2</ical4j.version>
@@ -186,13 +184,14 @@
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
-                <version>${assertj.version}</version>
+                <version>3.8.0</version>
                 <scope>test</scope>
             </dependency>
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-guava</artifactId>
-                <version>${assertj-guava.version}</version>
+                <version>3.1.0</version>
+                <scope>test</scope>
             </dependency>
             <dependency>
                 <groupId>com.thoughtworks.qdox</groupId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/mpt/pom.xml
----------------------------------------------------------------------
diff --git a/mpt/pom.xml b/mpt/pom.xml
index 38b088f..d17ff93 100644
--- a/mpt/pom.xml
+++ b/mpt/pom.xml
@@ -65,7 +65,6 @@
         <log4j.version>1.2.16</log4j.version>
         <lucene-core.version>3.6.0</lucene-core.version>
         <slf4j.version>1.7.25</slf4j.version>
-        <assertj.version>3.2.0</assertj.version>
 
         <logback.version>1.1.7</logback.version>
     </properties>
@@ -446,7 +445,7 @@
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
-                <version>${assertj.version}</version>
+                <version>3.8.0</version>
             </dependency>
             <dependency>
                 <groupId>org.jmock</groupId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/protocols/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/pom.xml b/protocols/pom.xml
index d996f0a..35f4000 100644
--- a/protocols/pom.xml
+++ b/protocols/pom.xml
@@ -59,7 +59,6 @@
         <slf4j.version>1.7.25</slf4j.version>
         <jsieve.version>0.7</jsieve.version>
         <mockito-core.version>1.9.0</mockito-core.version>
-        <assertj.version>3.2.0</assertj.version>
     </properties>
 
     <dependencyManagement>
@@ -274,7 +273,7 @@
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
-                <version>${assertj.version}</version>
+                <version>3.8.0</version>
             </dependency>
             <dependency>
                 <groupId>org.assertj</groupId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/server/container/guice/guice-common/src/test/java/org/apache/james/utils/ConfigurablesTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/ConfigurablesTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/ConfigurablesTest.java
index 97db32b..d1c9bce 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/ConfigurablesTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/ConfigurablesTest.java
@@ -45,7 +45,6 @@ public class ConfigurablesTest {
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void configurablesShouldKeepTheAddedElementsOrder() {
         sut.add(MyConfigurable.class);
         sut.add(MyConfigurable2.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 0ae235f..5bc1db0 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -183,7 +183,6 @@
         <jetty.version>9.3.5.v20151012</jetty.version>
         <cassandra-unit.version>2.1.9.2</cassandra-unit.version>
         <assertj-guava.version>3.1.0</assertj-guava.version>
-        <assertj.version>3.3.0</assertj.version>
         <testcontainers-version>1.3.1</testcontainers-version>
         <guavate.version>1.0.0</guavate.version>
         <metrics.version>3.2.1</metrics.version>
@@ -1191,7 +1190,7 @@
             <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
-                <version>${assertj.version}</version>
+                <version>3.8.0</version>
             </dependency>
             <dependency>
                 <groupId>org.assertj</groupId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/2f7eba12/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
index c8de63a..c403251 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
@@ -32,10 +32,10 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import javax.mail.Flags;
 
+import com.google.common.collect.ImmutableSet;
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.model.ClientId;
 import org.apache.james.jmap.model.GetMessagesRequest;
@@ -120,7 +120,7 @@ public class GetMessagesMethodTest {
     private MailboxPath inboxPath;
     private MailboxPath customMailboxPath;
     private ClientId clientId;
-
+    
     @Before
     public void setup() throws Exception {
         clientId = ClientId.of("#0");
@@ -235,11 +235,9 @@ public class GetMessagesMethodTest {
 
         List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
 
-        assertThat(result).hasSize(1)
-            .extracting(JmapResponse::getProperties)
-            .flatExtracting(Optional::get)
-            .asList()
-            .containsOnly(MessageProperty.id);
+        assertThat(result).hasSize(1);
+        assertThat(result.get(0).getProperties())
+            .isEqualTo(Optional.of(ImmutableSet.of(MessageProperty.id)));
     }
 
     @Test
@@ -253,12 +251,10 @@ public class GetMessagesMethodTest {
                 .ids(ImmutableList.of(message1.getMessageId()))
                 .build();
 
-        Stream<JmapResponse> result = testee.process(request, clientId, session);
-        assertThat(result).hasSize(1)
-            .extracting(JmapResponse::getProperties)
-            .flatExtracting(Optional::get)
-            .asList()
-            .containsOnlyElementsOf(MessageProperty.allOutputProperties());
+        List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
+        assertThat(result).hasSize(1);
+        assertThat(result.get(0).getProperties())
+            .isEqualTo(Optional.of(MessageProperty.allOutputProperties()));
     }
 
     @Test
@@ -276,11 +272,9 @@ public class GetMessagesMethodTest {
         Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.subject);
 
         List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
-        assertThat(result).hasSize(1)
-            .extracting(JmapResponse::getProperties)
-            .flatExtracting(Optional::get)
-            .asList()
-            .containsOnlyElementsOf(expected);
+        assertThat(result).hasSize(1);
+        assertThat(result.get(0).getProperties())
+            .isEqualTo(Optional.of(expected));
     }
     
     @Test
@@ -299,11 +293,9 @@ public class GetMessagesMethodTest {
 
         List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
 
-        assertThat(result).hasSize(1)
-            .extracting(JmapResponse::getProperties)
-            .flatExtracting(Optional::get)
-            .asList()
-            .containsOnlyElementsOf(expected);
+        assertThat(result).hasSize(1);
+        assertThat(result.get(0).getProperties())
+            .isEqualTo(Optional.of(expected));
     }
 
     @Test
@@ -411,12 +403,9 @@ public class GetMessagesMethodTest {
 
         List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
 
-        assertThat(result)
-            .hasSize(1)
-            .extracting(JmapResponse::getProperties)
-            .flatExtracting(Optional::get)
-            .asList()
-            .containsOnlyElementsOf(expected);
+        assertThat(result).hasSize(1);
+        assertThat(result.get(0).getProperties())
+            .isEqualTo(Optional.of(expected));
     }
     
     @Test


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