Skip to content

Commit f137f5e

Browse files
committed
Fix testdata and equals checking with different line-endings
1 parent 555779b commit f137f5e

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/main/java/org/simplejavamail/email/EqualsHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import javax.activation.DataSource;
44
import java.util.List;
55

6+
import static org.simplejavamail.internal.util.MiscUtil.normalizeNewlines;
7+
68
/**
79
* Util class to get rid of some boilerplate code in the core classes. The equals code was needed to analyze junit test errors.
810
* <p>
@@ -30,7 +32,7 @@ public static boolean equalsEmail(final Email email1, final Email email2) {
3032
if (email1.getEmailToForward() != null ? email2.getEmailToForward() == null : email2.getEmailToForward() != null) {
3133
return false;
3234
}
33-
if (email1.getHTMLText() != null ? !email1.getHTMLText().equals(email2.getHTMLText()) : email2.getHTMLText() != null) {
35+
if (email1.getHTMLText() != null ? !normalizeNewlines(email1.getHTMLText()).equals(normalizeNewlines(email2.getHTMLText())) : email2.getHTMLText() != null) {
3436
return false;
3537
}
3638
if (email1.getSubject() != null ? !email1.getSubject().equals(email2.getSubject()) : email2.getSubject() != null) {

src/main/java/org/simplejavamail/internal/util/MiscUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,9 @@ public static boolean classAvailable(@Nonnull String className) {
149149
return false;
150150
}
151151
}
152+
153+
@Nullable
154+
public static String normalizeNewlines(final @Nullable String text) {
155+
return text == null ? null : text.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
156+
}
152157
}

src/test/java/org/simplejavamail/mailer/MailerLiveTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import static org.assertj.core.data.MapEntry.entry;
2626
import static org.simplejavamail.converter.EmailConverter.mimeMessageToEmail;
2727
import static org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder;
28-
import static testutil.EmailHelper.normalizeText;
28+
import static org.simplejavamail.internal.util.MiscUtil.normalizeNewlines;
2929
import static testutil.EmailHelper.readOutlookMessage;
3030

3131
@SuppressWarnings("unused")
@@ -86,10 +86,12 @@ public void createMailSession_OutlookMessageTest()
8686
// Outlook overrode this when saving the .email to match the mail account
8787
EmailAssert.assertThat(email).hasRecipients(new Recipient("Bottema, Benny", "[email protected]", TO));
8888
EmailAssert.assertThat(email).hasReplyToRecipient(new Recipient("lollypop-replyto", "[email protected]", null));
89-
assertThat(normalizeText(email.getPlainText())).isEqualTo("We should meet up!\n");
89+
assertThat(normalizeNewlines(email.getPlainText())).isEqualTo("We should meet up!\n");
9090
// Outlook overrode this value too OR converted the original HTML to RTF, from which OutlookMessageParser derived this HTML
91-
assertThat(normalizeText(email.getHTMLText())).contains(
92-
"<html><body style=\"font-family:'Courier',monospace;font-size:10pt;\"> <br/> <br/> <b> We should meet up! <br/> </b> <br/> <img src=\"cid:thumbsup\"> <br/> ");
91+
assertThat(normalizeNewlines(email.getHTMLText())).contains(
92+
"<html><body style=\"font-family:'Courier',monospace;font-size:10pt;\"> <br/> \n" +
93+
" <br/> <b> We should meet up! <br/> </b> <br/> <img src=\"cid:thumbsup\">\n" +
94+
" <br/> </body></html>");
9395
// the RTF was probably created by Outlook based on the HTML when the message was saved
9496
assertThat(email.getAttachments()).hasSize(2);
9597
assertThat(email.getEmbeddedImages()).hasSize(1);
@@ -100,9 +102,9 @@ public void createMailSession_OutlookMessageTest()
100102
assertAttachmentMetadata(attachment1, "text/plain", "dresscode.txt");
101103
assertAttachmentMetadata(attachment2, "text/plain", "location.txt");
102104
assertAttachmentMetadata(embeddedImg, "image/png", "thumbsup");
103-
104-
assertThat(normalizeText(attachment1.readAllData())).isEqualTo("Black Tie Optional");
105-
assertThat(normalizeText(attachment2.readAllData())).isEqualTo("On the moon!");
105+
106+
assertThat(normalizeNewlines(attachment1.readAllData())).isEqualTo("Black Tie Optional");
107+
assertThat(normalizeNewlines(attachment2.readAllData())).isEqualTo("On the moon!");
106108
}
107109

108110
private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopulatingBuilder, boolean compensateForDresscodeAttachmentNameOverrideErasure)

src/test/java/testutil/EmailHelper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,4 @@ public static EmailPopulatingBuilder readOutlookMessage(final String filePath) {
6363
return outlookMsgToEmailBuilder(resourceAsStream);
6464
}
6565

66-
public static String normalizeText(String text) {
67-
return text.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
68-
}
6966
}

0 commit comments

Comments
 (0)