Created
April 29, 2018 17:20
-
-
Save vgallet/1a1ffb8f10e439d07fedf0b460e4bd28 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 SMTPServerRule extends ExternalResource { | |
private GreenMail smtpServer; | |
private String hostname; | |
private int port; | |
public SMTPServerRule() { | |
this(25); | |
} | |
public SMTPServerRule(int port) { | |
this("localhost", port); | |
} | |
public SMTPServerRule(String hostname, int port) { | |
this.hostname = hostname; | |
this.port = port; | |
} | |
@Override | |
protected void before() throws Throwable { | |
super.before(); | |
smtpServer = new GreenMail(new ServerSetup(port, hostname, "smtp")); | |
smtpServer.start(); | |
} | |
public List<ExpectedMail> getMessages() { | |
return Lists.newArrayList(smtpServer.getReceivedMessages()).stream() | |
.parallel() | |
.map(mimeMessage -> ExpectedMail.transformMimeMessage(mimeMessage)).collect(Collectors.toList()); | |
} | |
@Override | |
protected void after() { | |
super.after(); | |
smtpServer.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment