From 7e4ec09f35b3a1dc6d1d9765f1b04a1e1998004d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 22 Oct 2015 09:40:44 +0100 Subject: [PATCH 01/10] pom.xml: version set to 0.3.0-SNAPSHOT Signed-off-by: Paul Campbell --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d6d8f01..2676c00 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.kemitix wiser-assertions - 0.2.0 + 0.3.0-SNAPSHOT jar wiser-assertions From 262283d628565cd7b2576495ac8a241367f42572 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 11:53:37 +0000 Subject: [PATCH 02/10] Refactor common elements of testing to AbstractWiserTest Signed-off-by: Paul Campbell --- .../wiser/assertions/AbstractWiserTest.java | 63 +++++++++++++++++++ .../wiser/assertions/WiserAssertionsTest.java | 49 +-------------- 2 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java diff --git a/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java b/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java new file mode 100644 index 0000000..56282f8 --- /dev/null +++ b/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java @@ -0,0 +1,63 @@ +package net.kemitix.wiser.assertions; + +import org.junit.After; +import org.junit.Before; +import org.subethamail.wiser.Wiser; + +import java.util.Properties; + +import javax.mail.Session; + +/** + * Abstract base class for wiser tests. + * + * @author pcampbell + */ +public abstract class AbstractWiserTest { + + /** + * Test mail server port. + */ + protected static final int PORT = 12345; + + /** + * Test mail server. + */ + private Wiser wiser; + + /** + * Prepare each test. + */ + @Before + @SuppressWarnings("magicnumber") + public void setUp() { + wiser = new Wiser(PORT); + wiser.start(); + } + + /** + * Clean up after each test. + */ + @After + public void tearDown() { + wiser.stop(); + } + + /** + * Instantiates the WiserAssertions. + * + * @return the wiser assertions + */ + protected WiserAssertions getAssertions() { + return WiserAssertions.assertReceivedMessage(wiser); + } + + protected Session getSession() { + Properties properties = new Properties(); + properties.setProperty("mail.smtp.host", "localhost"); + properties.setProperty("mail.smtp.port", "" + WiserAssertionsTest.PORT); + Session session = Session.getDefaultInstance(properties); + return session; + } + +} diff --git a/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java b/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java index 891f608..34890a8 100644 --- a/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java +++ b/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java @@ -1,21 +1,17 @@ package net.kemitix.wiser.assertions; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.subethamail.wiser.Wiser; import static org.junit.Assert.assertNotNull; import java.io.IOException; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; -import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; @@ -27,7 +23,7 @@ import javax.mail.internet.MimeMultipart; * * @author pcampbell */ -public class WiserAssertionsTest { +public class WiserAssertionsTest extends AbstractWiserTest { /** * Logger. @@ -35,34 +31,6 @@ public class WiserAssertionsTest { private static final Logger LOG = Logger.getLogger(WiserAssertionsTest.class.getName()); - /** - * Test mail server. - */ - private Wiser wiser; - - /** - * Prepare each test. - */ - @Before - @SuppressWarnings("magicnumber") - public void setUp() { - wiser = new Wiser(PORT); - wiser.start(); - } - - /** - * Test mail server port. - */ - private static final int PORT = 12345; - - /** - * Clean up after each test. - */ - @After - public void tearDown() { - wiser.stop(); - } - /** * Sends a mime multipart message to the Wiser server. * @@ -76,12 +44,8 @@ public class WiserAssertionsTest { final String to, final String subject, final String body) { - Properties properties = new Properties(); - properties.setProperty("mail.smtp.host", "localhost"); - properties.setProperty("mail.smtp.port", "" + PORT); - Session session = Session.getDefaultInstance(properties); try { - MimeMessage message = new MimeMessage(session); + MimeMessage message = new MimeMessage(getSession()); message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, to); message.setSubject(subject, "UTF-8"); @@ -96,15 +60,6 @@ public class WiserAssertionsTest { } } - /** - * Instantiates the WiserAssertions. - * - * @return the wiser assertions - */ - private WiserAssertions getAssertions() { - return WiserAssertions.assertReceivedMessage(wiser); - } - /** * Test {@link WiserAssertions#withContent(java.lang.String)} where the * content of the email matches. From 986daedfb10deac2dd096ceabbcc02c60f6b1439 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 11:54:28 +0000 Subject: [PATCH 03/10] Issue1Test: add draft test for nested multipart messages Signed-off-by: Paul Campbell --- pom.xml | 6 +++ .../kemitix/wiser/assertions/Issue1Test.java | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/java/net/kemitix/wiser/assertions/Issue1Test.java diff --git a/pom.xml b/pom.xml index 2676c00..3d6b5e0 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,12 @@ test jar + + org.codemonkey.simplejavamail + simple-java-mail + 2.5.1 + test + diff --git a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java new file mode 100644 index 0000000..5c313b3 --- /dev/null +++ b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java @@ -0,0 +1,37 @@ +package net.kemitix.wiser.assertions; + +import org.codemonkey.simplejavamail.Email; +import org.codemonkey.simplejavamail.Mailer; +import org.junit.Test; + +import javax.mail.Message; + +/** + * Regression test for issue #1. + * + * @see https://github.com/kemitix/wiser-assertions/issues/1 + * @author pcampbell + */ +public class Issue1Test extends AbstractWiserTest { + + @Test + public void shouldParseNestedMultiPartEmails() { + //given + final Email email = new Email(); + email.addRecipient("Jonjo McKay", "jonjo.mckay@manywho.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"); + Mailer mailer = new Mailer(getSession()); + //when + mailer.sendMail(email); + //then + getAssertions().withContent("Hi Jonjo McKay"); + } + +} From ebba0760c476fe7976bedbf867305fdd5b28860b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 12:11:21 +0000 Subject: [PATCH 04/10] pom.xml: switch parent to kemitix-parent Need to specify versions for junit and mockito-core ourselves now. --- pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2676c00..e5c43e1 100644 --- a/pom.xml +++ b/pom.xml @@ -30,8 +30,8 @@ net.kemitix - kemitix-spring-parent - 1.2.1 + kemitix-parent + 0.6.1 @@ -48,13 +48,14 @@ junit junit + 4.12 test org.mockito mockito-core + 1.10.19 test - jar From 911c0dd3b348cc6a9f8d945f05d4193fd53aa93d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 12:11:42 +0000 Subject: [PATCH 05/10] WiserAssertionsTest: fix line wrapping Signed-off-by: Paul Campbell --- .../java/net/kemitix/wiser/assertions/WiserAssertionsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java b/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java index 891f608..ce9e22c 100644 --- a/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java +++ b/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java @@ -209,7 +209,8 @@ public class WiserAssertionsTest { //given final String fragment = "foo"; //when - sendMimeMultipartMessage("from", "to", "subject " + fragment + " tail", "body"); + sendMimeMultipartMessage( + "from", "to", "subject " + fragment + " tail", "body"); //then getAssertions().withSubjectContains(fragment); } From 8aa0f2c1c554f9a7bbd2cb4a53071a5803fb6e90 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 12:16:57 +0000 Subject: [PATCH 06/10] checkstyle.xml: updated to be slightly less strict Signed-off-by: Paul Campbell --- checkstyle.xml | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 9706c65..ba1e682 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -78,15 +78,19 @@ - - - + + + + + - + + + - + @@ -113,12 +117,7 @@ - - - - - - + @@ -157,7 +156,11 @@ - + + + + + @@ -183,6 +186,7 @@ - + + From d624902cfdbf2d1ce7c28814c924b0867aa8d77e Mon Sep 17 00:00:00 2001 From: Jonjo McKay Date: Mon, 25 Jan 2016 13:03:42 +0000 Subject: [PATCH 07/10] Issue #1: Add support for nested multipart messages --- .../wiser/assertions/WiserAssertions.java | 8 +++++++- .../wiser/assertions/AbstractWiserTest.java | 1 + .../kemitix/wiser/assertions/Issue1Test.java | 18 +++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java b/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java index a2fc2b6..4b74ade 100644 --- a/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java +++ b/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java @@ -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(); } diff --git a/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java b/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java index 56282f8..675bbfa 100644 --- a/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java +++ b/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java @@ -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); diff --git a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java index 5c313b3..d26fd90 100644 --- a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java +++ b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java @@ -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"); } } From 04870102a2ca28dff143b15dfdee492ef31b0909 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 13:20:31 +0000 Subject: [PATCH 08/10] Normalise formatting (comments and white space only). Signed-off-by: Paul Campbell --- .../java/net/kemitix/wiser/assertions/WiserAssertions.java | 1 - src/test/java/net/kemitix/wiser/assertions/Issue1Test.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java b/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java index 4b74ade..07d0c56 100644 --- a/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java +++ b/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java @@ -270,7 +270,6 @@ public final class WiserAssertions { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < mimeMultipart.getCount(); i++) { Object content = mimeMultipart.getBodyPart(i).getContent(); - if (content instanceof MimeMultipart) { sb.append(getMimeMultipartAsString((MimeMultipart) content)); } else { diff --git a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java index d26fd90..76cc6bb 100644 --- a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java +++ b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java @@ -15,8 +15,8 @@ import javax.mail.Message; public class Issue1Test extends AbstractWiserTest { /** - * Test {@link WiserAssertions#withContentContains(String)} where - * the nested multipart message contains the expected text + * Test {@link WiserAssertions#withContentContains(String)} where the nested + * multi-part message contains the expected text. */ @Test public void shouldParseNestedMultiPartEmails() { From b7b5e1d74ff9b265177e1bd02bac15ddf7d612e1 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 13:28:46 +0000 Subject: [PATCH 09/10] pom.xml: version set to 0.3.0 Signed-off-by: Paul Campbell --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 17c8d80..a6080f7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.kemitix wiser-assertions - 0.3.0-SNAPSHOT + 0.3.0 jar wiser-assertions From 78738e83ed0f97c9f63ced0efd73742f7b2797f7 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jan 2016 13:28:46 +0000 Subject: [PATCH 10/10] CHANGELOG Signed-off-by: Paul Campbell --- CHANGELOG | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 684456c..6e97675 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ CHANGELOG ========= +0.3.0 +------ + +* Add support for nested multi-part emails [jonjo-manywho] [#1] + 0.2.0 ------