Merge pull request #4 from jonjo-manywho/issue-1-nested-multipart-mails
Issue #1: Add support for nested multipart messages
This commit is contained in:
commit
6b866a0ddd
3 changed files with 17 additions and 10 deletions
|
@ -269,7 +269,13 @@ public final class WiserAssertions {
|
|||
throws MessagingException, IOException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < mimeMultipart.getCount(); i++) {
|
||||
sb.append(mimeMultipart.getBodyPart(i).getContent());
|
||||
Object content = mimeMultipart.getBodyPart(i).getContent();
|
||||
|
||||
if (content instanceof MimeMultipart) {
|
||||
sb.append(getMimeMultipartAsString((MimeMultipart) content));
|
||||
} else {
|
||||
sb.append(content);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public abstract class AbstractWiserTest {
|
|||
|
||||
protected Session getSession() {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("mail.transport.protocol", "smtp");
|
||||
properties.setProperty("mail.smtp.host", "localhost");
|
||||
properties.setProperty("mail.smtp.port", "" + WiserAssertionsTest.PORT);
|
||||
Session session = Session.getDefaultInstance(properties);
|
||||
|
|
|
@ -14,24 +14,24 @@ import javax.mail.Message;
|
|||
*/
|
||||
public class Issue1Test extends AbstractWiserTest {
|
||||
|
||||
/**
|
||||
* Test {@link WiserAssertions#withContentContains(String)} where
|
||||
* the nested multipart message contains the expected text
|
||||
*/
|
||||
@Test
|
||||
public void shouldParseNestedMultiPartEmails() {
|
||||
//given
|
||||
final Email email = new Email();
|
||||
email.addRecipient("Jonjo McKay", "jonjo.mckay@manywho.com",
|
||||
email.addRecipient("Carl", "carl@b.com",
|
||||
Message.RecipientType.TO);
|
||||
email.setFromAddress("ManyWho", "no-reply@manywho.com");
|
||||
email.setSubject("New activity");
|
||||
email.setText("Hi Jonjo McKay,\n\nA new message was just posted in a "
|
||||
+ "stream you follow on ManyWho. The message was:\n\nLance "
|
||||
+ "Drake Mandrell: \"This is a test message\"\n\nJoin the flow "
|
||||
+ "at https://flow.manywho.com to read the stream and reply.\n"
|
||||
+ "\nManyWho Email Bot");
|
||||
email.setFromAddress("Bob", "bob@a.com");
|
||||
email.setSubject("Subject");
|
||||
email.setText("Hi Carl,\n\nA new message was just posted.");
|
||||
Mailer mailer = new Mailer(getSession());
|
||||
//when
|
||||
mailer.sendMail(email);
|
||||
//then
|
||||
getAssertions().withContent("Hi Jonjo McKay");
|
||||
getAssertions().withContentContains("Hi Carl");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue