-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ctabin/test-cleanup
Cleanup of tests and constants usage
- Loading branch information
Showing
3 changed files
with
23 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import javax.mail.Message; | ||
import javax.mail.MessagingException; | ||
|
@@ -28,9 +29,9 @@ public void testBasicGeneration() throws Exception { | |
|
||
MimeMessage mimeMessage1 = message.toMimeMessage(); | ||
|
||
ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); | ||
mimeMessage1.writeTo(baos1); | ||
baos1.close(); | ||
try(ByteArrayOutputStream baos1 = new ByteArrayOutputStream()) { | ||
mimeMessage1.writeTo(baos1); | ||
} | ||
|
||
assertNull(mimeMessage1.getFrom()); | ||
assertNull(mimeMessage1.getSubject()); | ||
|
@@ -43,7 +44,7 @@ public void testBasicGeneration() throws Exception { | |
assertEquals(1, multipart1.getCount()); | ||
assertEquals("body", multipart1.getBodyPart(0).getFileName()); | ||
|
||
String body1 = IOUtils.toString(multipart1.getBodyPart(0).getInputStream()); | ||
String body1 = IOUtils.toString(multipart1.getBodyPart(0).getInputStream(), StandardCharsets.UTF_8); | ||
assertEquals(message.getPlainTextBody(), body1); | ||
} | ||
|
||
|
@@ -57,15 +58,15 @@ public void testSimpleDoubleGeneration() throws Exception { | |
message.addRecipient(OutlookMessageRecipient.Type.TO, "[email protected]", "Cédric"); | ||
message.addRecipient(OutlookMessageRecipient.Type.TO, "[email protected]"); | ||
message.addRecipient(OutlookMessageRecipient.Type.CC, "[email protected]", "Copy"); | ||
message.addAttachment("message.txt", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes("UTF-8"))); | ||
message.addAttachment("message.txt", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes(StandardCharsets.UTF_8))); | ||
|
||
// ----------------------------------------------------- | ||
|
||
MimeMessage mimeMessage1 = message.toMimeMessage(); | ||
|
||
ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); | ||
mimeMessage1.writeTo(baos1); | ||
baos1.close(); | ||
try(ByteArrayOutputStream baos1 = new ByteArrayOutputStream()) { | ||
mimeMessage1.writeTo(baos1); | ||
} | ||
|
||
assertEquals(1, mimeMessage1.getFrom().length); | ||
assertEquals("[email protected]", mimeMessage1.getFrom()[0].toString()); | ||
|
@@ -80,18 +81,18 @@ public void testSimpleDoubleGeneration() throws Exception { | |
assertEquals("body", multipart1.getBodyPart(0).getFileName()); | ||
assertEquals("message.txt", multipart1.getBodyPart(1).getFileName()); | ||
|
||
String body1 = IOUtils.toString(multipart1.getBodyPart(0).getInputStream()); | ||
String body1 = IOUtils.toString(multipart1.getBodyPart(0).getInputStream(), StandardCharsets.UTF_8); | ||
assertEquals(message.getPlainTextBody(), body1); | ||
|
||
String text1 = IOUtils.toString(multipart1.getBodyPart(1).getInputStream()); | ||
String text1 = IOUtils.toString(multipart1.getBodyPart(1).getInputStream(), StandardCharsets.UTF_8); | ||
assertEquals("Hello, World!", text1); | ||
|
||
// ----------------------------------------------------- | ||
|
||
MimeMessage mimeMessage2 = message.toMimeMessage(); | ||
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); | ||
mimeMessage2.writeTo(baos2); | ||
baos2.close(); | ||
try(ByteArrayOutputStream baos2 = new ByteArrayOutputStream()) { | ||
mimeMessage2.writeTo(baos2); | ||
} | ||
|
||
assertEquals(1, mimeMessage2.getFrom().length); | ||
assertEquals("[email protected]", mimeMessage2.getFrom()[0].toString()); | ||
|
@@ -106,10 +107,10 @@ public void testSimpleDoubleGeneration() throws Exception { | |
assertEquals("body", multipart2.getBodyPart(0).getFileName()); | ||
assertEquals("message.txt", multipart2.getBodyPart(1).getFileName()); | ||
|
||
String body2 = IOUtils.toString(multipart2.getBodyPart(0).getInputStream()); | ||
String body2 = IOUtils.toString(multipart2.getBodyPart(0).getInputStream(), StandardCharsets.UTF_8); | ||
assertEquals(message.getPlainTextBody(), body2); | ||
|
||
String text2 = IOUtils.toString(multipart2.getBodyPart(1).getInputStream()); | ||
String text2 = IOUtils.toString(multipart2.getBodyPart(1).getInputStream(), StandardCharsets.UTF_8); | ||
assertEquals("Hello, World!", text2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.text.SimpleDateFormat; | ||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
@@ -44,7 +45,7 @@ public void testMessageWithAttachment() throws Exception { | |
message.addRecipient(OutlookMessageRecipient.Type.TO, "[email protected]", "Cédric"); | ||
message.addRecipient(OutlookMessageRecipient.Type.TO, "[email protected]"); | ||
message.addRecipient(OutlookMessageRecipient.Type.CC, "[email protected]", "Copy"); | ||
message.addAttachment("message.txt", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes("UTF-8"))); | ||
message.addAttachment("message.txt", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes(StandardCharsets.UTF_8))); | ||
|
||
testMessage(message); | ||
} | ||
|
@@ -62,9 +63,9 @@ public void testMessageWithAttachment2() throws Exception { | |
message.addRecipient(OutlookMessageRecipient.Type.CC, "[email protected]", "John"); | ||
message.addRecipient(OutlookMessageRecipient.Type.CC, "[email protected]"); | ||
message.addRecipient(OutlookMessageRecipient.Type.BCC, "[email protected]"); | ||
message.addAttachment("message.txt", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes("UTF-8"))); | ||
message.addAttachment("message2.txt", "text/plain", new ByteArrayInputStream("Another attachment with content".getBytes("UTF-8"))); | ||
message.addAttachment("message3.txt", "text/html", new ByteArrayInputStream("<html><body>Some html page</body></html>".getBytes("UTF-8"))); | ||
message.addAttachment("message.txt", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes(StandardCharsets.UTF_8))); | ||
message.addAttachment("message2.txt", "text/plain", new ByteArrayInputStream("Another attachment with content".getBytes(StandardCharsets.UTF_8))); | ||
message.addAttachment("message3.txt", "text/html", new ByteArrayInputStream("<html><body>Some html page</body></html>".getBytes(StandardCharsets.UTF_8))); | ||
|
||
testMessage(message); | ||
testBinary(message, "generated/with-attachments-2.msg"); | ||
|
@@ -165,7 +166,6 @@ public void addManyRecipients() throws Exception { | |
|
||
@Test | ||
public void addManyAttachments() throws Exception { | ||
String testFilename = "test.msg"; | ||
int count = 40; | ||
|
||
OutlookMessage message = new OutlookMessage(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters