Skip to content

Commit

Permalink
Merge pull request #43 from ctabin/test-cleanup
Browse files Browse the repository at this point in the history
Cleanup of tests and constants usage
  • Loading branch information
ctabin authored Feb 1, 2020
2 parents ca5ab65 + efbf6ad commit bee57eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
31 changes: 16 additions & 15 deletions src/test/java/ch/astorm/jotlmsg/OutlookMessageMIMETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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);
}

Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/test/java/ch/astorm/jotlmsg/OutlookMessageMSGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/ch/astorm/jotlmsg/OutlookMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ch.astorm.jotlmsg.OutlookMessageRecipient.Type;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void testParsingAttachment() throws IOException {

assertEquals("myAttachement.txt", message.getAttachments().get(0).getName());

String data = IOUtils.toString(message.getAttachments().get(0).getNewInputStream(), "UTF-8");
String data = IOUtils.toString(message.getAttachments().get(0).getNewInputStream(), StandardCharsets.UTF_8);
assertEquals("This is some basic content of attached file.", data);
}

Expand Down

0 comments on commit bee57eb

Please sign in to comment.