Created
April 29, 2018 17:22
-
-
Save vgallet/fc43785a96d7613cab3f48f30ec8f4b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SMTPServerExtension implements BeforeEachCallback, AfterEachCallback { | |
private GreenMail smtpServer; | |
private String hostname; | |
private int port; | |
public SMTPServerExtension() { | |
this(25); | |
} | |
public SMTPServerExtension(int port) { | |
this("localhost", port); | |
} | |
public SMTPServerExtension(String hostname, int port) { | |
this.hostname = hostname; | |
this.port = port; | |
} | |
public List<ExpectedMail> getMessages() { | |
return Lists.newArrayList(smtpServer.getReceivedMessages()).stream() | |
.parallel() | |
.map(mimeMessage -> ExpectedMail.transformMimeMessage(mimeMessage)).collect(Collectors.toList()); | |
} | |
@Override | |
public void afterEach(ExtensionContext extensionContext) throws Exception { | |
smtpServer.stop(); | |
} | |
@Override | |
public void beforeEach(ExtensionContext extensionContext) throws Exception { | |
smtpServer = new GreenMail(new ServerSetup(port, hostname, "smtp")); | |
smtpServer.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment