james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [2/5] james-project git commit: MAILBOX-267 use throwing-lambdas and replace ad-hoc code
Date Mon, 02 May 2016 08:28:50 GMT
MAILBOX-267 use throwing-lambdas and replace ad-hoc code


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

Branch: refs/heads/master
Commit: 84be5d74a4f57d567b7ddc4bb6f0f69c705535b7
Parents: 8049cde
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Tue Apr 19 15:13:51 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Mon May 2 10:24:47 2016 +0200

----------------------------------------------------------------------
 mailbox/cassandra/pom.xml                       |  5 ++++
 .../mail/CassandraUidAndModSeqProviderTest.java | 28 +++++---------------
 2 files changed, 11 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/84be5d74/mailbox/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/pom.xml b/mailbox/cassandra/pom.xml
index afc07ed..6839e75 100644
--- a/mailbox/cassandra/pom.xml
+++ b/mailbox/cassandra/pom.xml
@@ -240,6 +240,11 @@
                     <version>${assertj-1.version}</version>
                     <scope>test</scope>
                 </dependency>
+                <dependency>
+                    <groupId>com.github.fge</groupId>
+                    <artifactId>throwing-lambdas</artifactId>
+                    <version>0.5.0</version>
+                </dependency>
             </dependencies>
             <build>
                 <plugins>

http://git-wip-us.apache.org/repos/asf/james-project/blob/84be5d74/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraUidAndModSeqProviderTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraUidAndModSeqProviderTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraUidAndModSeqProviderTest.java
index 4c4234a..6d094c4 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraUidAndModSeqProviderTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraUidAndModSeqProviderTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.function.LongConsumer;
 import java.util.stream.LongStream;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
@@ -33,14 +32,13 @@ import org.apache.james.mailbox.cassandra.CassandraId;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraUidAndModSeqModule;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.base.Throwables;
+import com.github.fge.lambdas.Throwing;
 
 /**
  * Unit tests for UidProvider and ModSeqProvider.
@@ -113,7 +111,7 @@ public class CassandraUidAndModSeqProviderTest {
         long result = uidProvider.lastUid(null, newBox);
         assertEquals(0, result);
         LongStream.range(1, 10)
-            .forEach(propagateException(value -> {
+            .forEach(Throwing.longConsumer(value -> {
                         long uid = uidProvider.nextUid(null, newBox);
                         assertThat(uid).isEqualTo(uidProvider.lastUid(null, newBox));
                 })
@@ -125,7 +123,7 @@ public class CassandraUidAndModSeqProviderTest {
         SimpleMailbox<CassandraId> mailbox = mailboxList.get(mailboxList.size() / 2);
         long lastUid = uidProvider.lastUid(null, mailbox);
         LongStream.range(lastUid + 1, lastUid + 10)
-            .forEach(propagateException(value -> {
+            .forEach(Throwing.longConsumer(value -> {
                         long result = uidProvider.nextUid(null, mailbox);
                         assertThat(value).isEqualTo(result);
                 })
@@ -143,7 +141,7 @@ public class CassandraUidAndModSeqProviderTest {
         long result = modSeqProvider.highestModSeq(null, newBox);
         assertEquals(0, result);
         LongStream.range(1, 10)
-            .forEach(propagateException(value -> {
+            .forEach(Throwing.longConsumer(value -> {
                         long uid = modSeqProvider.nextModSeq(null, newBox);
                         assertThat(uid).isEqualTo(modSeqProvider.highestModSeq(null, newBox));
                 })
@@ -155,7 +153,7 @@ public class CassandraUidAndModSeqProviderTest {
         SimpleMailbox<CassandraId> mailbox = mailboxList.get(mailboxList.size() / 2);
         long lastUid = modSeqProvider.highestModSeq(null, mailbox);
         LongStream.range(lastUid + 1, lastUid + 10)
-            .forEach(propagateException(value -> {
+            .forEach(Throwing.longConsumer(value -> {
                         long result = modSeqProvider.nextModSeq(null, mailbox);
                         assertThat(value).isEqualTo(result);
                 })
@@ -169,7 +167,7 @@ public class CassandraUidAndModSeqProviderTest {
         final AtomicLong previousValue = new AtomicLong();
         LongStream.range(lastUid + 1, lastUid + 10)
             .parallel()
-            .forEach(propagateException(value -> {
+            .forEach(Throwing.longConsumer(value -> {
                         long result = modSeqProvider.nextModSeq(null, mailbox);
                         assertThat(result).isGreaterThan(previousValue.get());
                         previousValue.set(result);
@@ -177,18 +175,4 @@ public class CassandraUidAndModSeqProviderTest {
             );
     }
     
-    @FunctionalInterface
-    private interface ConsumerThatThrowsMailboxException<T> {
-        void apply(T arg) throws MailboxException;
-    }
-    
-    private LongConsumer propagateException(ConsumerThatThrowsMailboxException<Long>
function) {
-        return (value) -> {
-            try {
-                function.apply(value);
-            } catch (MailboxException e) {
-                Throwables.propagate(e);
-            }
-        };
-    }
 }


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