Skip to content

Instantly share code, notes, and snippets.

@xpmatteo
Last active October 18, 2018 12:19
Show Gist options
  • Save xpmatteo/c13463392cbcf9719696e5aa040676bf to your computer and use it in GitHub Desktop.
Save xpmatteo/c13463392cbcf9719696e5aa040676bf to your computer and use it in GitHub Desktop.
private static final int NONSTANDARD_PORT = 9999;
private MailAdapter mailAdapter = new MailAdapter("localhost", NONSTANDARD_PORT);
private SimpleSmtpServer smtpServer;
@Before
public void setUp() throws Exception {
smtpServer = SimpleSmtpServer.start(NONSTANDARD_PORT);
}
@After
public void tearDown() throws Exception {
smtpServer.stop();
}
@Test
public void sendEmailMessage() throws Exception {
mailAdapter.sendMessage("the subject", "the body", "foo@bar.com");
assertEquals("message not sent?", 1, smtpServer.getReceivedEmailSize());
SmtpMessage message = (SmtpMessage) smtpServer.getReceivedEmail().next();
assertEquals("the body", message.getBody());
assertEquals("the subject", message.getHeaderValue("Subject"));
String[] recipients = message.getHeaderValues("To");
assertEquals(1, recipients.length);
assertEquals("foo@bar.com", recipients[0].toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment