assertEquals("ISO-8859-1", bd.getCharset());
}
public void testGetMimeType() throws Exception {
BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder();
builder.addField(new RawField("Content-Type ", "text/PLAIN"));
BodyDescriptor bd = builder.build();
assertEquals("text/plain", bd.getMimeType());
builder.reset();
builder.addField(new RawField("content-type", " TeXt / html "));
bd = builder.build();
assertEquals("text/html", bd.getMimeType());
builder.reset();
builder.addField(new RawField("CONTENT-TYPE", " x-app/yada ; param = yada"));
bd = builder.build();
assertEquals("x-app/yada", bd.getMimeType());
builder.reset();
builder.addField(new RawField("CONTENT-TYPE", " yada"));
bd = builder.build();
assertEquals("text/plain", bd.getMimeType());
/*
* Make sure that only the first Content-Type header added is used.
*/
builder.reset();
builder.addField(new RawField("Content-Type ", "text/plain"));
bd = builder.build();
assertEquals("text/plain", bd.getMimeType());
builder.addField(new RawField("Content-Type ", "text/html"));
bd = builder.build();
assertEquals("text/plain", bd.getMimeType());
/*
* Implicit mime types.
*/
BodyDescriptorBuilder parent = new DefaultBodyDescriptorBuilder();
parent.addField(new RawField("Content-Type", "mutlipart/alternative; boundary=foo"));
BodyDescriptorBuilder child = parent.newChild();
bd = child.build();
assertEquals("text/plain", bd.getMimeType());
child.addField(new RawField("Content-Type", " child/type"));
bd = child.build();
assertEquals("child/type", bd.getMimeType());
parent.reset();
parent.addField(new RawField("Content-Type", "multipart/digest; boundary=foo"));
child = parent.newChild();
bd = child.build();
assertEquals("message/rfc822", bd.getMimeType());
child.addField(new RawField("Content-Type", " child/type"));
bd = child.build();
assertEquals("child/type", bd.getMimeType());
}