package com.vtence.molecule;

import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class BodyPartTest {

    @Test
    public void decodesTextContentAccordingToContentTypeCharset() throws IOException {
        String originalText = "Les naïfs ægithales hâtifs pondant à Noël où il gèle...";

        BodyPart part = new BodyPart().contentType("text/plain; charset=utf-16").content(originalText);

        assertThat("decoded text", part.content(), equalTo(originalText));
    }

    @Test
    public void defaultsToUTF8DecodingWhenNoContentTypeIsSpecified() throws IOException {
        String originalText = "sont sûrs d'être déçus...";

        BodyPart part = new BodyPart().content(originalText);

        assertThat("decoded text", part.content(), equalTo(originalText));
    }

    @Test
    public void defaultsToUTF8DecodingWhenNoCharsetIsSpecified() throws IOException {
        String originalText = "en voyant leurs drôles d'oeufs abîmés.";

        BodyPart part = new BodyPart().contentType("text/plain").content(originalText);

        assertThat("decoded text", part.content(), equalTo(originalText));
    }
}
@@ -76,16 +76,133 @@
 ption;%0A%0A
+import static com.vtence.molecule.helpers.Charsets.UTF_16;%0Aimport static com.vtence.molecule.helpers.Charsets.UTF_8;%0A
 import s
@@ -246,16 +246,16 @@
 rtThat;%0A
-
 import s
@@ -601,32 +601,49 @@
 ent(originalText
+.getBytes(UTF_16)
 );%0A%0A        asse
@@ -923,32 +923,48 @@
 ent(originalText
+.getBytes(UTF_8)
 );%0A%0A        asse
@@ -1198,24 +1198,24 @@
  ab%C3%AEm%C3%A9s.%22;%0A%0A
-
         Body
@@ -1287,16 +1287,32 @@
 inalText
+.getBytes(UTF_8)
 );%0A%0A    

Make sure our body part test actually proves we're using the right encoding