james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [14/21] james-project git commit: JAMES-2048 Cid should not accept blank value
Date Wed, 07 Jun 2017 10:46:24 GMT
JAMES-2048 Cid should not accept blank value


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

Branch: refs/heads/master
Commit: c69c7efbbbbc830a10a8bfe87037f9a1603bc5fb
Parents: d4246a0
Author: quynhn <qnguyen@linagora.com>
Authored: Tue Jun 6 13:40:57 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 17:35:47 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/mailbox/model/Cid.java     | 11 ++++++---
 .../org/apache/james/mailbox/model/CidTest.java | 24 +++++++++++++++++---
 2 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c69c7efb/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
index bfaa6cc..96440e5 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
@@ -20,14 +20,15 @@
 package org.apache.james.mailbox.model;
 
 
+import org.apache.commons.lang.StringUtils;
+
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
 public class Cid {
 
     public static Cid from(String cidAsString) {
-        Preconditions.checkNotNull(cidAsString);
-        Preconditions.checkArgument(!cidAsString.isEmpty(), "'cidAsString' is mandatory");
+        Preconditions.checkArgument(!StringUtils.isBlank(cidAsString), "'cidAsString' is
mandatory");
         return new Cid(normalizedCid(cidAsString));
     }
 
@@ -39,7 +40,11 @@ public class Cid {
     }
     
     private static String unwrap(String cidAsString) {
-        return cidAsString.substring(1, cidAsString.length() - 1);
+        String unwrapCid = cidAsString.substring(1, cidAsString.length() - 1);
+        if (StringUtils.isBlank(unwrapCid)) {
+            throw new IllegalArgumentException("'cidAsString' is mandatory");
+        }
+        return unwrapCid;
     }
 
     private static boolean isWrappedWithAngleBrackets(String cidAsString) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/c69c7efb/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
index c9c9459..20163ad 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
@@ -34,7 +34,7 @@ public class CidTest {
     
     @Test
     public void fromShouldThrowWhenNull() {
-        expectedException.expect(NullPointerException.class);
+        expectedException.expect(IllegalArgumentException.class);
         Cid.from(null);
     }
     
@@ -43,7 +43,25 @@ public class CidTest {
         expectedException.expect(IllegalArgumentException.class);
         Cid.from("");
     }
-    
+
+    @Test
+    public void fromShouldThrowWhenBlank() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("    ");
+    }
+
+    @Test
+    public void fromShouldThrowWhenEmptyAfterRemoveTags() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("<>");
+    }
+
+    @Test
+    public void fromShouldThrowWhenBlankAfterRemoveTags() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("<   >");
+    }
+
     @Test
     public void fromShouldRemoveTagsWhenExists() {
         Cid cid = Cid.from("<123>");
@@ -67,7 +85,7 @@ public class CidTest {
         Cid cid = Cid.from("123>");
         assertThat(cid.getValue()).isEqualTo("123>");
     }
-    
+
     @Test
     public void shouldRespectJavaBeanContract() {
         EqualsVerifier.forClass(Cid.class).verify();


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