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 18f37b39870efb8f8b40aae50e3ac456fdc1824e
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Aug 29 10:21:27 2019 +0700

    JAMES-2865 Refactor MockSMTPServerTest
    
    Optimized setups
---
 .../james/mock/smtp/server/MockSMTPServerTest.java | 187 ++++++---------------
 1 file changed, 48 insertions(+), 139 deletions(-)

diff --git 
a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java
 
b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java
index 5e9c873..47a7c04 100644
--- 
a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java
+++ 
b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java
@@ -58,26 +58,46 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
-import org.testcontainers.shaded.com.google.common.collect.ImmutableList;
 
 import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.ImmutableList;
 
 class MockSMTPServerTest {
 
-    @Nested
-    class NormalBehaviorTests {
-        private MockSMTPServer mockServer;
+    private MockSMTPServer mockServer;
+    private FakeMail mail1;
+    private MimeMessage mimeMessage1;
+    private SMTPMessageSender smtpClient;
+    private SMTPBehaviorRepository behaviorRepository;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        behaviorRepository = new SMTPBehaviorRepository();
+        mockServer = new MockSMTPServer(behaviorRepository);
+
+        mimeMessage1 = MimeMessageBuilder.mimeMessageBuilder()
+            .setSubject("test")
+            .setText("any text")
+            .build();
+        mail1 = FakeMail.builder()
+            .name("name")
+            .sender(BOB)
+            .recipients(ALICE, JACK)
+            .mimeMessage(mimeMessage1)
+            .build();
 
-        @BeforeEach
-        void setUp() {
-            mockServer = new MockSMTPServer();
-            mockServer.start();
-        }
+        mockServer.start();
+        smtpClient = new SMTPMessageSender(DOMAIN)
+            .connect("localhost", mockServer.getPort());
+    }
 
-        @AfterEach
-        void tearDown() {
-            mockServer.stop();
-        }
+    @AfterEach
+    void tearDown() {
+        mockServer.stop();
+    }
+
+    @Nested
+    class NormalBehaviorTests {
 
         @Test
         void serverShouldReceiveMessageFromClient() throws Exception {
@@ -116,39 +136,6 @@ class MockSMTPServerTest {
 
     @Nested
     class MailMockBehaviorTest {
-        private MockSMTPServer mockServer;
-        private FakeMail mail1;
-        private MimeMessage mimeMessage1;
-        private SMTPMessageSender smtpClient;
-        private SMTPBehaviorRepository behaviorRepository;
-
-        @BeforeEach
-        void setUp() throws Exception {
-            behaviorRepository = new SMTPBehaviorRepository();
-            mockServer = new MockSMTPServer(behaviorRepository);
-
-            mimeMessage1 = MimeMessageBuilder.mimeMessageBuilder()
-                .setSubject("test")
-                .setText("any text")
-                .build();
-            mail1 = FakeMail.builder()
-                .name("name")
-                .sender(BOB)
-                .recipients(ALICE, JACK)
-                .mimeMessage(mimeMessage1)
-                .build();
-
-            mockServer.start();
-            smtpClient = new SMTPMessageSender(DOMAIN)
-                .connect("localhost", mockServer.getPort());
-        }
-
-        @AfterEach
-        void tearDown() {
-            behaviorRepository.clearBehaviors();
-            mockServer.stop();
-        }
-
         @Test
         void serverShouldReceiveMessageFromClient() throws Exception {
             behaviorRepository.setBehaviors(new MockSMTPBehavior(
@@ -191,38 +178,6 @@ class MockSMTPServerTest {
 
     @Nested
     class NumberOfAnswersTest {
-        private MockSMTPServer mockServer;
-        private FakeMail mail1;
-        private MimeMessage mimeMessage1;
-        private SMTPMessageSender smtpClient;
-        private SMTPBehaviorRepository behaviorRepository;
-
-        @BeforeEach
-        void setUp() throws Exception {
-            behaviorRepository = new SMTPBehaviorRepository();
-            mockServer = new MockSMTPServer(behaviorRepository);
-
-            mimeMessage1 = MimeMessageBuilder.mimeMessageBuilder()
-                .setSubject("test")
-                .setText("any text")
-                .build();
-            mail1 = FakeMail.builder()
-                .name("name")
-                .sender(BOB)
-                .recipients(ALICE, JACK)
-                .mimeMessage(mimeMessage1)
-                .build();
-
-            mockServer.start();
-            smtpClient = new SMTPMessageSender(DOMAIN)
-                .connect("localhost", mockServer.getPort());
-        }
-
-        @AfterEach
-        void tearDown() {
-            mockServer.stop();
-        }
-
         @Test
         void serverShouldKeepReceivingErrorResponseWhenAnytime() throws 
Exception {
             behaviorRepository.setBehaviors(new MockSMTPBehavior(
@@ -323,56 +278,10 @@ class MockSMTPServerTest {
             assertThat(remainedAnswersOf(matchesAnyFrom) + 
remainedAnswersOf(matchesAnyRecipient))
                 .isEqualTo(4);
         }
-
-        private void sendMessageIgnoreError(FakeMail mail) {
-            try {
-                smtpClient.sendMessage(mail);
-            } catch (MessagingException | IOException e) {
-                // ignore error
-            }
-        }
-
-        private Integer remainedAnswersOf(MockSMTPBehavior nonMatched) {
-            return behaviorRepository
-                .getBehaviorInformation(nonMatched)
-                .remainingAnswersCounter()
-                .get();
-        }
     }
 
     @Nested
     class ConditionFilteringTest {
-        private MockSMTPServer mockServer;
-        private FakeMail mail1;
-        private MimeMessage mimeMessage1;
-        private SMTPMessageSender smtpClient;
-        private SMTPBehaviorRepository behaviorRepository;
-
-        @BeforeEach
-        void setUp() throws Exception {
-            behaviorRepository = new SMTPBehaviorRepository();
-            mockServer = new MockSMTPServer(behaviorRepository);
-
-            mimeMessage1 = MimeMessageBuilder.mimeMessageBuilder()
-                .setSubject("test")
-                .setText("any text")
-                .build();
-            mail1 = FakeMail.builder()
-                .name("name")
-                .sender(BOB)
-                .recipients(ALICE, JACK)
-                .mimeMessage(mimeMessage1)
-                .build();
-
-            mockServer.start();
-            smtpClient = new SMTPMessageSender(DOMAIN)
-                .connect("localhost", mockServer.getPort());
-        }
-
-        @AfterEach
-        void tearDown() {
-            mockServer.stop();
-        }
 
         @Test
         void serverShouldBehaveOnMatchedFromBehavior() throws Exception {
@@ -509,21 +418,6 @@ class MockSMTPServerTest {
             assertThat(remainedAnswersOf(matched) + 
remainedAnswersOf(qualifiedButNotMatched))
                 .isEqualTo(matchedOriginalCount + 
qualifiedButNotMatchedOriginalCount - 1);
         }
-
-        private void sendMessageIgnoreError(FakeMail mail) {
-            try {
-                smtpClient.sendMessage(mail);
-            } catch (MessagingException | IOException e) {
-                // ignore error
-            }
-        }
-
-        private Integer remainedAnswersOf(MockSMTPBehavior nonMatched) {
-            return behaviorRepository
-                .getBehaviorInformation(nonMatched)
-                .remainingAnswersCounter()
-                .get();
-        }
     }
 
     @Test
@@ -557,4 +451,19 @@ class MockSMTPServerTest {
         assertThatCode(() -> mockServer.start())
             .doesNotThrowAnyException();
     }
+
+    private void sendMessageIgnoreError(FakeMail mail) {
+        try {
+            smtpClient.sendMessage(mail);
+        } catch (MessagingException | IOException e) {
+            // ignore error
+        }
+    }
+
+    private Integer remainedAnswersOf(MockSMTPBehavior nonMatched) {
+        return behaviorRepository
+            .getBehaviorInformation(nonMatched)
+            .remainingAnswersCounter()
+            .get();
+    }
 }
\ No newline at end of file


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

Reply via email to