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 13529174457ffbabc159a8eeb6af006fa6e1fce1 Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Wed Aug 28 10:31:46 2019 +0700 JAMES-2567 MockSMTPServer should not proxy repository Also remove a harmful constructor helper --- .../apache/james/mock/smtp/server/MockSMTPServer.java | 16 +--------------- .../james/mock/smtp/server/MockSMTPServerTest.java | 17 +++++++++-------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPServer.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPServer.java index 834bdec..13a7965 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPServer.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPServer.java @@ -19,31 +19,17 @@ package org.apache.james.mock.smtp.server; -import java.util.List; - -import org.apache.james.mock.smtp.server.model.Mail; import org.apache.james.util.Port; import org.subethamail.smtp.server.SMTPServer; class MockSMTPServer { - private final SMTPServer server; - private final ReceivedMailRepository mailRepository; - - MockSMTPServer() { - this(new SMTPBehaviorRepository()); - } - MockSMTPServer(SMTPBehaviorRepository behaviorRepository) { - this.mailRepository = new ReceivedMailRepository(); + MockSMTPServer(SMTPBehaviorRepository behaviorRepository, ReceivedMailRepository mailRepository) { this.server = new SMTPServer(ctx -> new MockMessageHandler(mailRepository, behaviorRepository)); this.server.setPort(0); } - List<Mail> listReceivedMails() { - return mailRepository.list(); - } - void start() { if (!server.isRunning()) { server.start(); 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 bd7f361..ee8e41f 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 @@ -63,17 +63,18 @@ import com.github.fge.lambdas.Throwing; import com.google.common.collect.ImmutableList; class MockSMTPServerTest { - private MockSMTPServer mockServer; private FakeMail mail1; private MimeMessage mimeMessage1; private SMTPMessageSender smtpClient; private SMTPBehaviorRepository behaviorRepository; + private ReceivedMailRepository mailRepository; @BeforeEach void setUp() throws Exception { behaviorRepository = new SMTPBehaviorRepository(); - mockServer = new MockSMTPServer(behaviorRepository); + mailRepository = new ReceivedMailRepository(); + mockServer = new MockSMTPServer(behaviorRepository, mailRepository); mimeMessage1 = MimeMessageBuilder.mimeMessageBuilder() .setSubject("test") @@ -120,7 +121,7 @@ class MockSMTPServerTest { Awaitility.await().atMost(Duration.TEN_SECONDS) .untilAsserted(() -> { - List<Mail> mails = mockServer.listReceivedMails(); + List<Mail> mails = mailRepository.list(); Mail.Envelope expectedEnvelope = new Mail.Envelope( new MailAddress(BOB), ImmutableList.of(new MailAddress(ALICE), new MailAddress(JACK))); @@ -228,7 +229,7 @@ class MockSMTPServerTest { sendMessageIgnoreError(mail1); Awaitility.await().atMost(Duration.TEN_SECONDS) - .untilAsserted(() -> assertThat(mockServer.listReceivedMails()).hasSize(1)); + .untilAsserted(() -> assertThat(mailRepository.list()).hasSize(1)); } @Test @@ -422,7 +423,7 @@ class MockSMTPServerTest { @Test void serverStartShouldOpenASmtpPort() { - MockSMTPServer mockServer = new MockSMTPServer(); + MockSMTPServer mockServer = new MockSMTPServer(new SMTPBehaviorRepository(), new ReceivedMailRepository()); mockServer.start(); assertThatCode(() -> new SMTPMessageSender(DOMAIN) @@ -432,7 +433,7 @@ class MockSMTPServerTest { @Test void serverShouldBeAbleToStop() { - MockSMTPServer mockServer = new MockSMTPServer(); + MockSMTPServer mockServer = new MockSMTPServer(new SMTPBehaviorRepository(), new ReceivedMailRepository()); mockServer.start(); Port port = mockServer.getPort(); @@ -445,10 +446,10 @@ class MockSMTPServerTest { @Test void serverStartShouldBeIdempotent() { - MockSMTPServer mockServer = new MockSMTPServer(); + MockSMTPServer mockServer = new MockSMTPServer(new SMTPBehaviorRepository(), new ReceivedMailRepository()); mockServer.start(); - assertThatCode(() -> mockServer.start()) + assertThatCode(mockServer::start) .doesNotThrowAnyException(); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org