james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [14/14] james-project git commit: JAMES-2525 hardens swift value types against null and empty strings
Date Fri, 05 Oct 2018 11:12:57 GMT
JAMES-2525 hardens swift value types against null and empty strings


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

Branch: refs/heads/master
Commit: 6b9e2e9839fd4ceb6510652e4c2e80bcd0a79bcd
Parents: be1702d
Author: Jean Helou <jhe@codamens.fr>
Authored: Wed Sep 5 09:25:58 2018 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Oct 5 18:11:43 2018 +0700

----------------------------------------------------------------------
 .../blob/objectstorage/swift/Credentials.java   |  5 +++
 .../blob/objectstorage/swift/DomainId.java      |  5 +++
 .../blob/objectstorage/swift/DomainName.java    |  5 +++
 .../blob/objectstorage/swift/HeaderName.java    |  5 +++
 .../blob/objectstorage/swift/Identity.java      |  7 ++++
 .../blob/objectstorage/swift/IdentityV3.java    |  7 ++++
 .../james/blob/objectstorage/swift/Project.java |  8 +++-
 .../blob/objectstorage/swift/ProjectName.java   |  5 +++
 .../james/blob/objectstorage/swift/Region.java  |  5 +++
 .../blob/objectstorage/swift/TenantName.java    |  5 +++
 .../blob/objectstorage/swift/UserName.java      |  5 +++
 .../objectstorage/swift/CredentialsTest.java    | 22 +++++++++++
 .../blob/objectstorage/swift/DomainIdTest.java  | 27 ++++++++++++--
 .../objectstorage/swift/DomainNameTest.java     | 22 +++++++++++
 .../objectstorage/swift/HeaderNameTest.java     | 39 +++++++++++++++++++-
 .../blob/objectstorage/swift/IdentityTest.java  | 16 +++++++-
 .../objectstorage/swift/IdentityV3Test.java     | 20 +++++++++-
 .../objectstorage/swift/ProjectNameTest.java    | 23 +++++++++++-
 .../blob/objectstorage/swift/ProjectTest.java   |  8 +++-
 .../blob/objectstorage/swift/RegionTest.java    | 22 +++++++++++
 .../objectstorage/swift/TenantNameTest.java     | 22 +++++++++++
 .../blob/objectstorage/swift/UserNameTest.java  | 21 +++++++++++
 22 files changed, 291 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Credentials.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Credentials.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Credentials.java
index 7d41396..46e4c84 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Credentials.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Credentials.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class Credentials {
     public static Credentials of(String value) {
@@ -30,6 +32,9 @@ public final class Credentials {
     private final String credentials;
 
     private Credentials(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.credentials = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java
index fef7a7a..8809dd0 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class DomainId {
     public static DomainId of(String value) {
@@ -30,6 +32,9 @@ public final class DomainId {
     private final String value;
 
     private DomainId(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java
index 6bd921e..89ae083 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class DomainName {
     public static DomainName of(String value) {
@@ -30,6 +32,9 @@ public final class DomainName {
     private final String value;
 
     private DomainName(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/HeaderName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/HeaderName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/HeaderName.java
index 7b9fb16..e62e317 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/HeaderName.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/HeaderName.java
@@ -21,11 +21,16 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public class HeaderName {
     private final String value;
 
     protected HeaderName(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Identity.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Identity.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Identity.java
index 1b72275..82d69b3 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Identity.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Identity.java
@@ -21,6 +21,7 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
 
 public final class Identity {
     public static Identity of(TenantName tenant, UserName userName) {
@@ -31,6 +32,12 @@ public final class Identity {
     private final UserName userName;
 
     private Identity(TenantName tenant, UserName userName) {
+        Preconditions.checkArgument(
+            tenant != null,
+            "Tenant cannot be null");
+        Preconditions.checkArgument(
+            userName != null,
+            "User name cannot be null");
         this.tenant = tenant;
         this.userName = userName;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java
index b8b1d1c..f636d7c 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java
@@ -21,6 +21,7 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
 
 public final class IdentityV3 {
     public static IdentityV3 of(DomainName domainName, UserName userName) {
@@ -31,6 +32,12 @@ public final class IdentityV3 {
     private final UserName userName;
 
     private IdentityV3(DomainName domainName, UserName userName) {
+        Preconditions.checkArgument(
+            domainName != null,
+            "Domain name cannot be null");
+        Preconditions.checkArgument(
+            userName != null,
+            "User name cannot be null");
         this.domainName = domainName;
         this.userName = userName;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java
index 963ded4..394f763 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
 
 public final class Project {
     public static Project of(ProjectName userName) {
@@ -30,11 +31,11 @@ public final class Project {
     }
 
     public static Project of(ProjectName userName, DomainName domainName) {
-        return new Project(userName, Optional.of(domainName), Optional.empty());
+        return new Project(userName, Optional.ofNullable(domainName), Optional.empty());
     }
 
     public static Project of(ProjectName userName, DomainId domainId) {
-        return new Project(userName, Optional.empty(), Optional.of(domainId));
+        return new Project(userName, Optional.empty(), Optional.ofNullable(domainId));
     }
 
     private final ProjectName name;
@@ -42,6 +43,9 @@ public final class Project {
     private final Optional<DomainId> domainId;
 
     private Project(ProjectName name, Optional<DomainName> domainName, Optional<DomainId>
domainId) {
+        Preconditions.checkArgument(
+            name != null,
+        this.getClass().getSimpleName() + "name cannot be null or empty");
         this.domainName = domainName;
         this.name = name;
         this.domainId = domainId;

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java
index 56969bb..e3eba57 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class ProjectName {
     public static ProjectName of(String value) {
@@ -30,6 +32,9 @@ public final class ProjectName {
     private final String value;
 
     private ProjectName(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Region.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Region.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Region.java
index 62fa01a..a17b999 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Region.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Region.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class Region {
     public static Region of(String value) {
@@ -30,6 +32,9 @@ public final class Region {
     private final String region;
 
     private Region(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.region = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/TenantName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/TenantName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/TenantName.java
index d004c84..c59cf74 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/TenantName.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/TenantName.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class TenantName {
     public static TenantName of(String value) {
@@ -30,6 +32,9 @@ public final class TenantName {
     private final String value;
 
     private TenantName(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/UserName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/UserName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/UserName.java
index 5c6f406..e4b310c 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/UserName.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/UserName.java
@@ -21,6 +21,8 @@ package org.apache.james.blob.objectstorage.swift;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public final class UserName {
     public static UserName of(String value) {
@@ -30,6 +32,9 @@ public final class UserName {
     private final String value;
 
     private UserName(String value) {
+        Preconditions.checkArgument(
+            !Strings.isNullOrEmpty(value),
+            this.getClass().getSimpleName() + " cannot be null or empty");
         this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/CredentialsTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/CredentialsTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/CredentialsTest.java
index e3d21f5..1875d1d 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/CredentialsTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/CredentialsTest.java
@@ -19,13 +19,35 @@
 
 package org.apache.james.blob.objectstorage.swift;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class CredentialsTest {
+
+    private static final String EXPECTED = "expected";
+
     @Test
     public void credentialsShouldRespectBeanContract() {
         EqualsVerifier.forClass(Credentials.class).verify();
     }
+
+    @Test
+    void credentialsCanBeBuiltFromNonEmptyString() {
+        Credentials actual = Credentials.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void credentialsCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> Credentials.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void credentialsCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> Credentials.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java
index f95559a..88f4acb 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.blob.objectstorage.swift;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.jupiter.api.Test;
 
@@ -27,14 +28,32 @@ import nl.jqno.equalsverifier.EqualsVerifier;
 
 class DomainIdTest {
 
+    public static final String EXPECTED = "EXPECTED";
+
     @Test
-    public void domainIdShouldRespectBeanContract() {
+    void domainIdShouldRespectBeanContract() {
         EqualsVerifier.forClass(DomainId.class).verify();
     }
 
     @Test
-    public void domainIdShouldProjectToDomainIdString() {
-        String actual = DomainId.of("foo").asString();
-        assertThat(actual).isEqualTo("domain:foo");
+    void domainIdShouldProjectToDomainIdString() {
+        String actual = DomainId.of(EXPECTED).asString();
+        assertThat(actual).isEqualTo("domain:EXPECTED");
+    }
+
+    @Test
+    void domainIdCanBeBuiltFromNonEmptyString() {
+        DomainId actual = DomainId.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void domainIdCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> DomainId.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void domainIdCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> DomainId.of(null)).isInstanceOf(IllegalArgumentException.class);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java
index 4b108c9..eddbf7c 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java
@@ -19,13 +19,35 @@
 
 package org.apache.james.blob.objectstorage.swift;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class DomainNameTest {
+
+    public static final String EXPECTED = "EXPECTED";
+
     @Test
     public void domainNameShouldRespectBeanContract() {
         EqualsVerifier.forClass(DomainName.class).verify();
     }
+
+    @Test
+    void domainNameCanBeBuiltFromNonEmptyString() {
+        DomainName actual = DomainName.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void domainNameCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> DomainName.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void domainNameCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> DomainName.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/HeaderNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/HeaderNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/HeaderNameTest.java
index b384f86..4cf4523 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/HeaderNameTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/HeaderNameTest.java
@@ -19,13 +19,50 @@
 
 package org.apache.james.blob.objectstorage.swift;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class HeaderNameTest {
+    private static final String EXPECTED = "expected";
+
     @Test
-    public void credentialsShouldRespectBeanContract() {
+    public void headerNameShouldRespectBeanContract() {
         EqualsVerifier.forClass(HeaderName.class).verify();
     }
+
+    @Test
+    void passHeaderNameCanBeBuiltFromNonEmptyString() {
+        PassHeaderName actual = PassHeaderName.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void passHeaderNameCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> PassHeaderName.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void passHeaderNameCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> PassHeaderName.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void userHeaderNameCanBeBuiltFromNonEmptyString() {
+        UserHeaderName actual = UserHeaderName.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void userHeaderNameCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> UserHeaderName.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void userHeaderNameCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> UserHeaderName.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityTest.java
index bb7e47d..c0a7eb8 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityTest.java
@@ -20,15 +20,19 @@
 package org.apache.james.blob.objectstorage.swift;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class IdentityTest {
+    public static final TenantName TENANT_NAME = TenantName.of("tenant");
+    public static final UserName USER_NAME = UserName.of("user");
+
     @Test
     void swiftIdentityRendersProperlyAsString() {
-        Identity identity = Identity.of(TenantName.of("tenant"), UserName.of("user"));
+        Identity identity = Identity.of(TENANT_NAME, USER_NAME);
         assertThat(identity.asString()).isEqualTo("tenant:user");
     }
 
@@ -36,4 +40,14 @@ class IdentityTest {
     public void credentialsShouldRespectBeanContract() {
         EqualsVerifier.forClass(Identity.class).verify();
     }
+
+    @Test
+    void userNameCanNotBeNull() {
+        assertThatThrownBy(() -> Identity.of(TENANT_NAME, null)).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void tenantNameCanNotBeNull() {
+        assertThatThrownBy(() -> Identity.of(null, USER_NAME)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java
index 39c3e27..5efb2c0 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java
@@ -20,20 +20,36 @@
 package org.apache.james.blob.objectstorage.swift;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class IdentityV3Test {
+
+    public static final DomainName DOMAIN_NAME = DomainName.of("domain");
+    public static final UserName USER_NAME = UserName.of("user");
+
     @Test
     void identityV3RendersProperlyAsString() {
-        IdentityV3 identity = IdentityV3.of(DomainName.of("domain"), UserName.of("user"));
+        IdentityV3 identity = IdentityV3.of(DOMAIN_NAME, USER_NAME);
         assertThat(identity.asString()).isEqualTo("domain:user");
     }
 
     @Test
-    public void identityV3ShouldRespectBeanContract() {
+    void identityV3ShouldRespectBeanContract() {
         EqualsVerifier.forClass(IdentityV3.class).verify();
     }
+
+
+    @Test
+    void userNameCanNotBeNull() {
+        assertThatThrownBy(() -> IdentityV3.of(DOMAIN_NAME, null)).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void domainNameCanNotBeNull() {
+        assertThatThrownBy(() -> IdentityV3.of(null, USER_NAME)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java
index 080a08e..7dd2f5a 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java
@@ -20,20 +20,39 @@
 package org.apache.james.blob.objectstorage.swift;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class ProjectNameTest {
+    private static final String EXPECTED = "expected";
+
     @Test
-    public void projectNameShouldRespectBeanContract() {
+    void projectNameShouldRespectBeanContract() {
         EqualsVerifier.forClass(ProjectName.class).verify();
     }
 
     @Test
-    public void projectNameShouldProjectToProjectNameString() {
+    void projectNameShouldProjectToProjectNameString() {
         String actual = ProjectName.of("bar").asString();
         assertThat(actual).isEqualTo("project:bar");
     }
+
+    @Test
+    void projectNameCanBeBuiltFromNonEmptyString() {
+        ProjectName actual = ProjectName.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void projectNameCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> ProjectName.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void projectNameCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> ProjectName.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java
index 9956d11..f3a8f51 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.blob.objectstorage.swift;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.junit.jupiter.api.Test;
 
@@ -37,7 +38,7 @@ class ProjectTest {
     }
 
     @Test
-    void projectCanBeBuiltFromNameAlone() {
+    void projectCanBeBuiltFromNameAlone()   {
         Project project = Project.of(PROJECT_NAME);
         assertThat(project.domainName()).isEmpty();
         assertThat(project.domainId()).isEmpty();
@@ -60,4 +61,9 @@ class ProjectTest {
         assertThat(project.domainId()).contains(DOMAIN_ID);
         assertThat(project.name()).isEqualTo(PROJECT_NAME);
     }
+
+    @Test
+    void projectCannotBeBuiltFromNullName() {
+        assertThatThrownBy(() -> Project.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/RegionTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/RegionTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/RegionTest.java
index 509e366..7ee67d9 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/RegionTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/RegionTest.java
@@ -19,13 +19,35 @@
 
 package org.apache.james.blob.objectstorage.swift;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class RegionTest {
+
+    public static final String EXPECTED = "EXPECTED";
+
     @Test
     public void regionShouldRespectBeanContract() {
         EqualsVerifier.forClass(Region.class).verify();
     }
+
+    @Test
+    void regionCanBeBuiltFromNonEmptyString() {
+        Region actual = Region.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void regionCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> Region.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void regionCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> Region.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/TenantNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/TenantNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/TenantNameTest.java
index 65917ab..107fb78 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/TenantNameTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/TenantNameTest.java
@@ -19,13 +19,35 @@
 
 package org.apache.james.blob.objectstorage.swift;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class TenantNameTest {
+
+    public static final String EXPECTED = "EXPECTED";
+
     @Test
     public void tenantNameShouldRespectBeanContract() {
         EqualsVerifier.forClass(TenantName.class).verify();
     }
+
+    @Test
+    void tenantNameCanBeBuiltFromNonEmptyString() {
+        TenantName actual = TenantName.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void tenantNameCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> TenantName.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void tenantNameCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> TenantName.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b9e2e98/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/UserNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/UserNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/UserNameTest.java
index c793ed9..a8f61a2 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/UserNameTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/UserNameTest.java
@@ -19,13 +19,34 @@
 
 package org.apache.james.blob.objectstorage.swift;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class UserNameTest {
+    private static final String EXPECTED = "expected";
+
     @Test
     public void userNameShouldRespectBeanContract() {
         EqualsVerifier.forClass(UserName.class).verify();
     }
+
+    @Test
+    void userNameCanBeBuiltFromNonEmptyString() {
+        UserName actual = UserName.of(EXPECTED);
+        assertThat(actual.value()).isEqualTo(EXPECTED);
+    }
+
+    @Test
+    void userNameCanNotBeBuiltFromEmptyString() {
+        assertThatThrownBy(() -> UserName.of("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void userNameCanNotBeBuiltFromNull() {
+        assertThatThrownBy(() -> UserName.of(null)).isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ 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


Mime
View raw message