EmailSenderImpl implements EmailSender { @Override public void sendPasswordResetReminder(Map<String, Object> params) { String username = (String) params.get(TEMPLATE_PARAM_USERNAME); LOGGER.info("Sending password change reminder to user: {}", username); try { String text = templateParser.mergeTemplateIntoString(PASSWORD_CHANGE_REMINDER_TEMPLATE, passExpirationTemplateParams(params)); String subject = messageSource.getMessage(PASSWORD_CHANGE_REMINDER_MESSAGE_SUBJECT, null, (Locale) params.get(TEMPLATE_PARAM_LOCALE)); sendEmail((String) params.get(EMAIL_PARAM_TO_ADDRESS), text, subject); } catch (VelocityTemplateParsingException e) { LOGGER.error("Couldn't send password change reminder to user: {}", username, e); } }  @Override void sendRecoveryEmail(final PasswordRecovery recovery); @Override void sendOneTimeToken(final PasswordRecovery recovery); @Override void sendLoginInfo(final MotechUser user, String token); @Override void sendPasswordResetReminder(Map<String, Object> params); @Autowired void setEventRelay(EventRelay eventRelay); @Autowired void setSettingsFacade(SettingsFacade settingsFacade); @Autowired void setMessageSource(ResourceBundleMessageSource messageSource); @Autowired void setTemplateParser(VelocityTemplateParser templateParser);  }
@Test public void shouldSendPasswordResetReminder() throws Exception { when(templateParser.mergeTemplateIntoString(matches(PASSWORD_CHANGE_REMINDER_TEMPLATE), eq(params))) .thenReturn(EMAIL_MESSAGE); emailSender.sendPasswordResetReminder(params); verify(templateParser).mergeTemplateIntoString(matches(PASSWORD_CHANGE_REMINDER_TEMPLATE), eq(params)); verify(eventRelay).sendEventMessage(eq(event)); }
@Test public void shouldNotSendPasswordResetReminderIfParsingThrowsException() throws Exception { when(templateParser.mergeTemplateIntoString(matches(PASSWORD_CHANGE_REMINDER_TEMPLATE), eq(params))) .thenThrow(new VelocityTemplateParsingException("Couldn't send password reminder email", null)); emailSender.sendPasswordResetReminder(params); verify(templateParser).mergeTemplateIntoString(matches(PASSWORD_CHANGE_REMINDER_TEMPLATE), eq(params)); verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class)); }