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 2018/04/03 10:02:53 UTC

[07/24] james-project git commit: JAMES-2366 More Mapping.Type tests

JAMES-2366 More Mapping.Type tests


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

Branch: refs/heads/master
Commit: 667b860d0c965ebb9277598bb851244189885891
Parents: f5ebe4f
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 28 13:10:59 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Tue Apr 3 16:59:44 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/rrt/lib/MappingTest.java   | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/667b860d/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
index 5277358..5c4bca8 100644
--- a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
@@ -19,6 +19,7 @@
 package org.apache.james.rrt.lib;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.rrt.lib.Mapping.Type;
 import org.junit.jupiter.api.Test;
@@ -48,4 +49,70 @@ public class MappingTest {
         boolean hasPrefix = Mapping.Type.hasPrefix(Type.Address.asPrefix() + "myRegex");
         assertThat(hasPrefix).isFalse();
     }
+
+    @Test
+    public void detectTypeShouldReturnAddressWhenAddressPrefix() {
+        assertThat(Mapping.detectType(Type.Address.asPrefix() + "mapping"))
+            .isEqualTo(Type.Address);
+    }
+
+    @Test
+    public void detectTypeShouldReturnRegexWhenRegexPrefix() {
+        assertThat(Mapping.detectType(Type.Regex.asPrefix() + "mapping"))
+            .isEqualTo(Type.Regex);
+    }
+
+    @Test
+    public void detectTypeShouldReturnErrorWhenErrorPrefix() {
+        assertThat(Mapping.detectType(Type.Error.asPrefix() + "mapping"))
+            .isEqualTo(Type.Error);
+    }
+
+    @Test
+    public void detectTypeShouldReturnDomainWhenDomainPrefix() {
+        assertThat(Mapping.detectType(Type.Domain.asPrefix() + "mapping"))
+            .isEqualTo(Type.Domain);
+    }
+
+    @Test
+    public void withoutPrefixShouldRemoveAddressPrefix() {
+        assertThat(Type.Address.withoutPrefix(Type.Address.asPrefix() + "mapping"))
+            .isEqualTo("mapping");
+    }
+
+    @Test
+    public void withoutPrefixShouldDoNothingWhenAddressAndNoPrefix() {
+        assertThat(Type.Address.withoutPrefix("mapping"))
+            .isEqualTo("mapping");
+    }
+
+    @Test
+    public void withoutPrefixShouldRemoveDomainPrefix() {
+        assertThat(Type.Domain.withoutPrefix(Type.Domain.asPrefix() + "mapping"))
+            .isEqualTo("mapping");
+    }
+
+    @Test
+    public void withoutPrefixShouldRemoveErrorPrefix() {
+        assertThat(Type.Error.withoutPrefix(Type.Error.asPrefix() + "mapping"))
+            .isEqualTo("mapping");
+    }
+
+    @Test
+    public void withoutPrefixShouldRemoveRegexPrefix() {
+        assertThat(Type.Regex.withoutPrefix(Type.Regex.asPrefix() + "mapping"))
+            .isEqualTo("mapping");
+    }
+
+    @Test
+    public void withoutPrefixShouldThrowOnBadPrefix() {
+        assertThatThrownBy(() -> Type.Regex.withoutPrefix(Type.Domain.asPrefix() + "mapping"))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    public void withoutPrefixShouldThrowWhenNoPrefix() {
+        assertThatThrownBy(() -> Type.Regex.withoutPrefix("mapping"))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
 }


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