Skip to content

Commit

Permalink
#98: added live test for this
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Aug 21, 2017
1 parent a7b6c96 commit f27c8b3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testBuilderSimpleBuildWithStandardEmail()
.embedImage("thumbsup", parseBase64Binary(base64String), "image/png")
.build();

assertThat(EmailHelper.createDummyEmail(true, false)).isEqualTo(email);
assertThat(EmailHelper.createDummyEmail(true, true, false)).isEqualTo(email);
}

@Test
Expand All @@ -55,6 +55,6 @@ public void testBuilderSimpleBuildWithStandardEmail_PlusOptionals()
.addHeader("dummyHeader", "dummyHeaderValue")
.build();

assertThat(EmailHelper.createDummyEmail(false, true)).isEqualTo(email);
assertThat(EmailHelper.createDummyEmail(true, false, true)).isEqualTo(email);
}
}
14 changes: 10 additions & 4 deletions src/test/java/org/simplejavamail/mailer/MailerLiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,35 @@ public void setup() {
mailer = new Mailer(SERVER_CONFIG);
}

@Test
public void createMailSession_EmptySubjectAndBody()
throws IOException, MessagingException {
assertSendingEmail(EmailHelper.createDummyEmail(true, true, false));
}

@Test
public void createMailSession_StandardDummyMailBasicFields()
throws IOException, MessagingException {
assertSendingEmail(EmailHelper.createDummyEmail(true, false));
assertSendingEmail(EmailHelper.createDummyEmail(true, true, false));
}

@Test
public void createMailSession_StandardDummyMail_AllFields()
throws IOException, MessagingException {
assertSendingEmail(EmailHelper.createDummyEmail(false, false));
assertSendingEmail(EmailHelper.createDummyEmail(true, false, false));
}

@Test
public void createMailSession_StandardDummyMail_IncludingCustomHeaders()
throws IOException, MessagingException {
assertSendingEmail(EmailHelper.createDummyEmail(false, true));
assertSendingEmail(EmailHelper.createDummyEmail(true, false, true));
}

@Test
@Ignore("Unfortunately, Wiser doesn't seem to get the ID back, but I confirmed with gmail that the (correct) ID should be there")
public void createMailSession_StandardDummyMailWithId()
throws IOException, MessagingException {
assertSendingEmail(EmailHelper.createDummyEmail("<123@456>", false, false));
assertSendingEmail(EmailHelper.createDummyEmail("<123@456>", true, false, false));
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/simplejavamail/mailer/MailerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void createMailSession_MaximumConstructor_WithConfig()
@Test
public void testDKIMPriming()
throws IOException, MessagingException {
final Email email = EmailHelper.createDummyEmail(false, false);
final Email email = EmailHelper.createDummyEmail(true, false, false);

// System.out.println(printBase64Binary(Files.readAllBytes(Paths.get("D:\\keys\\dkim.der")))); // needs jdk 1.7
String privateDERkeyBase64 =
Expand All @@ -183,7 +183,7 @@ public void testDKIMPriming()
@Test
public void testParser()
throws Exception {
final Email emailNormal = EmailHelper.createDummyEmail(false, false);
final Email emailNormal = EmailHelper.createDummyEmail(true, false, false);

// let's try producing and then consuming a MimeMessage ->
final MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(emailNormal);
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/testutil/EmailHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

public class EmailHelper {

public static Email createDummyEmail(boolean basicFields, boolean includeCustomHeaders) throws IOException {
return createDummyEmail(null, basicFields, includeCustomHeaders);
public static Email createDummyEmail(boolean includeSubjectAndBody, boolean basicFields, boolean includeCustomHeaders) throws IOException {
return createDummyEmail(null, includeSubjectAndBody, basicFields, includeCustomHeaders);
}

public static Email createDummyEmail(@Nullable String id, boolean basicFields, boolean includeCustomHeaders)
public static Email createDummyEmail(@Nullable String id, boolean includeSubjectAndBody, boolean basicFields, boolean includeCustomHeaders)
throws IOException {
final Email emailNormal = new Email();
emailNormal.setId(id);
Expand All @@ -31,9 +31,11 @@ public static Email createDummyEmail(@Nullable String id, boolean basicFields, b
}
// don't forget to add your own address here ->
emailNormal.addNamedRecipient("C.Cane", TO, "candycane@candyshop.org");
emailNormal.setText("We should meet up!");
emailNormal.setTextHTML("<b>We should meet up!</b><img src='cid:thumbsup'>");
emailNormal.setSubject("hey");
if (includeSubjectAndBody) {
emailNormal.setSubject("hey");
emailNormal.setText("We should meet up!");
emailNormal.setTextHTML("<b>We should meet up!</b><img src='cid:thumbsup'>");
}

if (includeCustomHeaders) {
emailNormal.addHeader("dummyHeader", "dummyHeaderValue");
Expand Down

0 comments on commit f27c8b3

Please sign in to comment.