### Question:
MailService { @SuppressWarnings("deprecation") public String processTemplate(String templateUrl, Map<String, Object> model) { try { if(templateUrl != null) { String mailBody = mailContentBuilderService.getRemoteMailContent(templateUrl); Configuration cfg = new Configuration(); cfg.setObjectWrapper(new DefaultObjectWrapper()); Template t = new Template(UUID.randomUUID().toString(), new StringReader(mailBody), cfg); Writer out = new StringWriter(); t.process(model, out); return out.toString(); } } catch (Exception exception) { Log.error(exception.getMessage()); } return null; } @Autowired  MailService(JavaMailSender mailSender, MailContentBuilderService mailContentBuilderService); void prepareAndSendMail(String cc,String from, List<String> to, String subject, String mailMessageUrlOrBody, Map<String, Object> placeholderValues, final String attachmentUrl, final Boolean isPlainMessage); void prepareTemplateAndSendMail(String from, List<String> to, String subject, String mailMessageUrlOrBody, Map<String, Object> placeholderValues, final String attachmentUrl, final Boolean isPlainMessage); void prepareTemplateAndSendMail(String from, List<String> to, String subject, String mailContent , final String attachmentUrl); @SuppressWarnings("deprecation") String processTemplate(String templateUrl, Map<String, Object> model);  }### Answer:
@Test public void processTemplate1() throws Exception { mailService = PowerMockito.spy(new MailService(mailSender, mailContentBuilderService)); String templateUrl = "templateUrl"; when(mailContentBuilderService.getRemoteMailContent(anyString())).thenReturn("TEST"); assertNotNull(mailService.processTemplate(templateUrl, Maps.newHashMap())); }
@SuppressWarnings("unchecked") @Test public void processTemplate2() throws Exception { mailService = PowerMockito.spy(new MailService(mailSender, mailContentBuilderService)); String templateUrl = "templateUrl"; when(mailContentBuilderService.getRemoteMailContent(anyString())).thenThrow(Exception.class); assertNull(mailService.processTemplate(templateUrl, Maps.newHashMap())); }