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 382dfacb94269daecb00160792145221d8e6c445
Author: Tran Tien Duc <[email protected]>
AuthorDate: Wed Aug 21 11:53:56 2019 +0700

    JAMES-2864 Mail POJO for the Mock SMTP server
    
    Will be used to verify email and their envelopes after interacting with
    the mockSMTPServer
---
 server/mailet/mock-smtp-server/pom.xml             |   4 +
 .../org/apache/james/mock/smtp/server/Mail.java    | 102 +++++++++++++++++++++
 .../apache/james/mock/smtp/server/MailTest.java    |  89 ++++++++++++++++++
 3 files changed, 195 insertions(+)

diff --git a/server/mailet/mock-smtp-server/pom.xml 
b/server/mailet/mock-smtp-server/pom.xml
index a66b34f..d79081f 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -38,6 +38,10 @@
 
     <dependencies>
         <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-core</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
diff --git 
a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java
 
b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java
new file mode 100644
index 0000000..e977334
--- /dev/null
+++ 
b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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 java.util.List;
+import java.util.Objects;
+
+import org.apache.james.core.MailAddress;
+
+import com.google.common.base.Preconditions;
+
+class Mail {
+    static class Envelope {
+        private final MailAddress from;
+        private final List<MailAddress> recipients;
+
+        Envelope(MailAddress from, List<MailAddress> recipients) {
+            Preconditions.checkNotNull(from);
+            Preconditions.checkNotNull(recipients);
+            Preconditions.checkArgument(!recipients.isEmpty(), "'recipients' 
field should not be empty");
+
+            this.from = from;
+            this.recipients = recipients;
+        }
+
+        public MailAddress getFrom() {
+            return from;
+        }
+
+        public List<MailAddress> getRecipients() {
+            return recipients;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof Envelope) {
+                Envelope envelope = (Envelope) o;
+
+                return Objects.equals(this.from, envelope.from)
+                    && Objects.equals(this.recipients, envelope.recipients);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(from, recipients);
+        }
+    }
+
+    private final Envelope envelope;
+    private final String message;
+
+    Mail(Envelope envelope, String message) {
+        Preconditions.checkNotNull(envelope);
+        Preconditions.checkNotNull(message);
+
+        this.envelope = envelope;
+        this.message = message;
+    }
+
+    public Envelope getEnvelope() {
+        return envelope;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof Mail) {
+            Mail mail = (Mail) o;
+
+            return Objects.equals(this.envelope, mail.envelope)
+                && Objects.equals(this.message, mail.message);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(envelope, message);
+    }
+}
diff --git 
a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java
 
b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java
new file mode 100644
index 0000000..b21082f
--- /dev/null
+++ 
b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.assertThatThrownBy;
+
+import org.apache.james.core.MailAddress;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableList;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class MailTest {
+    private MailAddress bob;
+    private MailAddress alice;
+    private Mail.Envelope envelope;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        bob = new MailAddress("[email protected]");
+        alice = new MailAddress("[email protected]");
+        envelope = new Mail.Envelope(alice, ImmutableList.of(bob));
+    }
+
+    @Nested
+    class EnvelopeTest {
+        @Test
+        void shouldMatchBeanContract() {
+           EqualsVerifier.forClass(Mail.Envelope.class)
+               .verify();
+        }
+
+        @Test
+        void constructorShouldThrowWhenNullFrom() {
+            assertThatThrownBy(() -> new Mail.Envelope(null, 
ImmutableList.of(bob)))
+                .isInstanceOf(NullPointerException.class);
+        }
+
+        @Test
+        void constructorShouldThrowWhenNullRecipients() {
+            assertThatThrownBy(() -> new Mail.Envelope(bob, null))
+                .isInstanceOf(NullPointerException.class);
+        }
+
+        @Test
+        void constructorShouldThrowWhenEmptyRecipients() {
+            assertThatThrownBy(() -> new Mail.Envelope(bob, 
ImmutableList.of()))
+                .isInstanceOf(IllegalArgumentException.class);
+        }
+    }
+
+    @Test
+    void shouldMatchBeanContract() {
+       EqualsVerifier.forClass(Mail.class)
+           .verify();
+    }
+
+    @Test
+    void constructorShouldThrowWhenNullMessage() {
+        assertThatThrownBy(() -> new Mail(envelope, null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    void constructorShouldThrowWhenNullEnvelope() {
+        assertThatThrownBy(() -> new Mail(null, "header: single header message 
dude"))
+            .isInstanceOf(NullPointerException.class);
+    }
+}
\ No newline at end of file


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

Reply via email to