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 2019/08/26 11:38:34 UTC

[james-project] 11/11: JAMES-2864 Replace Optional by Condition with MATCH_ALL capability

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit d6ad1d251fba90442c28a518193b2697cc04ad93
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Aug 22 15:43:37 2019 +0700

    JAMES-2864 Replace Optional<Condition> by Condition with MATCH_ALL capability
---
 .../apache/james/mock/smtp/server/Condition.java    |  3 +++
 .../org/apache/james/mock/smtp/server/Operator.java |  1 +
 .../james/mock/smtp/server/ConditionTest.java       | 21 +++++++++++++++++++++
 3 files changed, 25 insertions(+)

diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
index 2fde09a..422eea7 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
@@ -24,6 +24,9 @@ import java.util.Objects;
 import com.google.common.base.Preconditions;
 
 class Condition {
+
+    static final Condition MATCH_ALL = new Condition(Operator.MATCH_ALL, "any");
+
     private final Operator operator;
     private final String matchingValue;
 
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
index 992343f..26947c0 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
@@ -32,6 +32,7 @@ public interface Operator {
     }
 
     Operator CONTAINS = actual -> expected -> () -> actual.contains(expected);
+    Operator MATCH_ALL = actual -> expected -> () -> true;
 
     Expected actual(String actual);
 }
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
index dff65dc..e5fe70a 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
@@ -68,4 +68,25 @@ class ConditionTest {
         assertThatThrownBy(() -> condition.matches(null))
             .isInstanceOf(NullPointerException.class);
     }
+
+    @Test
+    void matchAllShouldReturnTrue() {
+        assertThat(Condition.MATCH_ALL
+                .matches("this contains another string"))
+            .isTrue();
+    }
+
+    @Test
+    void matchAllShouldReturnTrueEvenWhenLineIsNull() {
+        assertThat(Condition.MATCH_ALL
+                .matches(null))
+            .isTrue();
+    }
+
+    @Test
+    void matchAllShouldReturnTrueEvenWhenLineIsEmpty() {
+        assertThat(Condition.MATCH_ALL
+                .matches(""))
+            .isTrue();
+    }
 }


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