HtmlMailService extends AbstractMailService<T> { @Override public void send(final T resource) { EmailSenderAdapter adapter = getMailSenderAdapter(); String content = templateProvider.process(templateURI, resource); Email email = new Email(getMail()); email.setContent(content); adapter.send(email); }  @Override void send(final T resource); void setTemplateProvider(final TemplateProvider templateProvider); void setTemplateURI(final String templateURI);  }
@Test public void testSend() throws Exception { String content = "sfsa"; Email email = new Email(mail); email.setContent(content); when(templateProvider.process(anyString(), anyString())).thenReturn(content); unit.send(content); verify(templateProvider).process(templateURI, content); verify(mailSenderAdapter).send(email); }
@Test(expected = MailException.class) public void testSendWithException() throws Exception { String content = "sfsa"; Email email = new Email(mail); email.setContent(content); when(templateProvider.process(anyString(), anyString())).thenReturn(content); doThrow(MailException.class).when(mailSenderAdapter).send(email); unit.send(content); verify(templateProvider).process(templateURI, content); verify(mailSenderAdapter).send(email); }