DefaultTemplateProvider implements TemplateProvider { @Override public String process(final String templateId, final Object data) { String renderedTemplate; try { Template template = handlebars.compile(templateId); renderedTemplate = template.apply(data); } catch (IOException e) { throw new MailException("Exception occurs", e); } return renderedTemplate; }  @Override String process(final String templateId, final Object data);  }
@Test public void testProcess() throws Exception { String templateId = "templateId"; Object data = "data"; String renderedHtml = "<html>name</html>"; when(handlebars.compile(anyString())).thenReturn(template); when(template.apply(any())).thenReturn(renderedHtml); unit.process(templateId, data); verify(template).apply(data); verify(handlebars).compile(templateId); }
@Test(expected = MailException.class) public void testProcessWithException() throws Exception { String templateId = "templateId"; Object data = "data"; doThrow(IOException.class).when(handlebars).compile(anyString()); unit.process(templateId, data); verify(handlebars).compile(templateId); }