james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [3/7] james-project git commit: JAMES-1718 Abstract tests for Token Repository should comply with our coding best practice
Date Fri, 15 Apr 2016 08:53:25 GMT
JAMES-1718 Abstract tests for Token Repository should comply with our coding best practice


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

Branch: refs/heads/master
Commit: 0cc164a0a6d8c78c4dfde9b6a0caf1159fec63f3
Parents: 7a59d2d
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Apr 11 18:32:45 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Apr 15 15:49:52 2016 +0700

----------------------------------------------------------------------
 .../access/CassandraAccessTokenDAO.java         |  3 ++-
 .../AbstractAccessTokenRepositoryTest.java      | 28 +++++++++-----------
 2 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0cc164a0/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenDAO.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenDAO.java
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenDAO.java
index 1dcd903..43e4811 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenDAO.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/access/CassandraAccessTokenDAO.java
@@ -35,6 +35,7 @@ import org.apache.james.jmap.cassandra.access.table.CassandraAccessTokenTable;
 
 import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.Session;
+import com.google.common.primitives.Ints;
 
 public class CassandraAccessTokenDAO {
 
@@ -48,7 +49,7 @@ public class CassandraAccessTokenDAO {
 
     public CassandraAccessTokenDAO(Session session, long durationInMilliseconds) {
         this.cassandraAsyncExecutor = new CassandraAsyncExecutor(session);
-        this.durationInSeconds = (int) (durationInMilliseconds / 1000);
+        this.durationInSeconds = Ints.checkedCast(durationInMilliseconds / 1000);
 
         this.removeStatement = session.prepare(delete()
             .from(CassandraAccessTokenTable.TABLE_NAME)

http://git-wip-us.apache.org/repos/asf/james-project/blob/0cc164a0/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AbstractAccessTokenRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AbstractAccessTokenRepositoryTest.java
b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AbstractAccessTokenRepositoryTest.java
index 0209af3..648a92e 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AbstractAccessTokenRepositoryTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/access/AbstractAccessTokenRepositoryTest.java
@@ -20,7 +20,7 @@
 package org.apache.james.jmap.api.access;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.jmap.api.access.exceptions.AccessTokenAlreadyStored;
 import org.apache.james.jmap.api.access.exceptions.InvalidAccessToken;
@@ -40,41 +40,37 @@ public abstract class AbstractAccessTokenRepositoryTest {
         accessTokenRepository = createAccessTokenRepository();
     }
 
-    abstract protected AccessTokenRepository createAccessTokenRepository();
+    protected abstract AccessTokenRepository createAccessTokenRepository();
 
     @Test
-    public void validTokenMustWork() throws Exception {
+    public void validTokenMustBeRetrieved() throws Exception {
         accessTokenRepository.addToken(USERNAME, TOKEN);
         assertThat(accessTokenRepository.getUsernameFromToken(TOKEN)).isEqualTo(USERNAME);
     }
 
-    @Test(expected=InvalidAccessToken.class)
-    public void nonStoredTokensMustBeInvalid() throws Exception {
-        accessTokenRepository.getUsernameFromToken(TOKEN);
+    @Test
+    public void absentTokensMustBeInvalid() throws Exception {
+        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(TOKEN)).isInstanceOf(InvalidAccessToken.class);
     }
 
-    @Test(expected=InvalidAccessToken.class)
+    @Test
     public void removedTokensMustBeInvalid() throws Exception {
         accessTokenRepository.addToken(USERNAME, TOKEN);
         accessTokenRepository.removeToken(TOKEN);
-        accessTokenRepository.getUsernameFromToken(TOKEN);
+        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(TOKEN)).isInstanceOf(InvalidAccessToken.class);
     }
 
-    @Test(expected = AccessTokenAlreadyStored.class)
+    @Test
     public void addTokenMustThrowWhenTokenIsAlreadyStored() throws Exception {
-        try {
-            accessTokenRepository.addToken(USERNAME, TOKEN);
-        } catch(Exception e) {
-            fail("Exception caught", e);
-        }
         accessTokenRepository.addToken(USERNAME, TOKEN);
+        assertThatThrownBy(() -> accessTokenRepository.addToken(USERNAME, TOKEN)).isInstanceOf(AccessTokenAlreadyStored.class);
     }
 
-    @Test(expected=InvalidAccessToken.class)
+    @Test
     public void outDatedTokenMustBeInvalid() throws Exception {
         accessTokenRepository.addToken(USERNAME, TOKEN);
         Thread.sleep(2 * TTL_IN_MS);
-        accessTokenRepository.getUsernameFromToken(TOKEN);
+        assertThatThrownBy(() -> accessTokenRepository.getUsernameFromToken(TOKEN)).isInstanceOf(InvalidAccessToken.class);
     }
 
     @Test(expected = NullPointerException.class)


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