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 0b62377c2930f3f2bad009db2d9b2c945f478118
Author: Tran Tien Duc <[email protected]>
AuthorDate: Wed Aug 21 10:22:48 2019 +0700

    JAMES-2864 Condition POJO for matching SMTP lines
---
 server/mailet/mock-smtp-server/pom.xml             |  4 ++
 .../apache/james/mock/smtp/server/Condition.java   | 39 ++++++++++++++
 .../james/mock/smtp/server/ConditionTest.java      | 63 ++++++++++++++++++++++
 3 files changed, 106 insertions(+)

diff --git a/server/mailet/mock-smtp-server/pom.xml 
b/server/mailet/mock-smtp-server/pom.xml
index c532536..78ec7c1 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -38,6 +38,10 @@
 
     <dependencies>
         <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-engine</artifactId>
             <scope>test</scope>
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
new file mode 100644
index 0000000..92c95cb
--- /dev/null
+++ 
b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mock.smtp.server;
+
+import com.google.common.base.Preconditions;
+
+class Condition {
+    private final Operator operator;
+    private final String matchingValue;
+
+    Condition(Operator operator, String matchingValue) {
+        Preconditions.checkNotNull(operator);
+        Preconditions.checkNotNull(matchingValue);
+
+        this.operator = operator;
+        this.matchingValue = matchingValue;
+    }
+
+    boolean matches(String line) {
+        return operator.matches(line, matchingValue);
+    }
+}
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
new file mode 100644
index 0000000..ac400d9
--- /dev/null
+++ 
b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mock.smtp.server;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+
+class ConditionTest {
+    @Test
+    void constructorShouldThrowWhenNullOperator() {
+        assertThatThrownBy(() -> new Condition(null, "matchingValue"))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    void constructorShouldThrowWhenNullMatchingValue() {
+        assertThatThrownBy(() -> new Condition(Operator.CONTAINS, null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    void matchesShouldReturnTrueWhenOperatorMatches() {
+        Condition condition = new Condition(Operator.CONTAINS, "match me");
+
+        assertThat(condition.matches("this contains match me string"))
+            .isTrue();
+    }
+
+    @Test
+    void matchesShouldReturnFalseWhenOperatorDoesNotMatch() {
+        Condition condition = new Condition(Operator.CONTAINS, "match me");
+
+        assertThat(condition.matches("this contains another string"))
+            .isFalse();
+    }
+
+    @Test
+    void matchesShouldThrowWhenNullLine() {
+        Condition condition = new Condition(Operator.CONTAINS, "match me");
+
+        assertThatThrownBy(() -> condition.matches(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to