/** Test sendEmail() for a multipart template. */
@Test public void testSendTemplateMultipart() {
Map<String, Object> context = new HashMap<String, Object>();
EmailTemplate template = new EmailTemplate();
template.setFormat(EmailFormat.MULTIPART);
template.setSender(new EmailAddress("sender-name", "sender-address"));
template.setReplyTo(new EmailAddress("reply-name", "reply-address"));
template.setTemplateGroup("g");
template.setTemplateName("n");
template.setTemplateContext(context);
ArgumentCaptor<EmailMessage> email = ArgumentCaptor.forClass(EmailMessage.class);
GaeEmailService service = createService();
Message message = mock(Message.class);
when(service.getGaeEmailUtils().createMessage(isA(EmailMessage.class))).thenReturn(message);
when(service.getTemplateService().renderTemplate("g", "n", SUBJECT, context)).thenReturn("subject-rendered");
when(service.getTemplateService().renderTemplate("g", "n", PLAINTEXT, context)).thenReturn("plaintext-rendered");
when(service.getTemplateService().renderTemplate("g", "n", HTML, context)).thenReturn("html-rendered");
service.sendEmail(template);
verify(service.getGaeEmailUtils()).sendMessage(message);
verify(service.getGaeEmailUtils()).createMessage(email.capture());
assertEquals(template.getFormat(), email.getValue().getFormat());
assertEquals(template.getSender(), email.getValue().getSender());
assertEquals(template.getReplyTo(), email.getValue().getReplyTo());
assertEquals(template.getRecipients(), email.getValue().getRecipients());
assertEquals("subject-rendered", email.getValue().getSubject());
assertEquals("plaintext-rendered", email.getValue().getPlaintext());
assertEquals("html-rendered", email.getValue().getHtml());
}