@Test
public void resource() throws Exception {
// null resourceName
try {
new AttachmentContent((String) null);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("resourceName"));
}
try {
new AttachmentContent((String) null, null);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("resourceName"));
}
try {
content.setResource(null);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("resourceName"));
}
try {
content.setResource(" ");
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("resourceName"));
}
// no resourceLoader
content = new AttachmentContent("testfile.txt");
builder.setContent(content);
try {
getMessageAsText();
fail();
} catch (MailBuilderException e) {
assertThat(e, exception("Could not find resource \"testfile.txt\": no resourceLoader specified"));
}
// resource not found
content = new AttachmentContent("notExist.txt");
content.setResourceLoader(factory);
builder.setContent(content);
try {
getMessageAsText();
fail();
} catch (MailBuilderException e) {
assertThat(e, exception("Could not find resource \"notExist.txt\""));
}
// stream only resource
content = new AttachmentContent("/asStream/testfile.txt");
content.setResourceLoader(factory);
builder.setContent(content);
assert_AppOctet_testfile_base64();
// Resource: text, default name
content = new AttachmentContent("testfile.txt");
content.setResourceLoader(factory);
builder.setContent(content);
assert_TextPlain_testfile_QuotedPrintable();
// Resource: gif image, name specified
content = new AttachmentContent("java.gif", "我的图片.gif");
content.setResourceLoader(factory);
builder.setContent(content);
assert_ImageGif_javagif_我的图片_base64();