@Test void testResetPassword() { String emailAddress = "my@email.com"; User user = mock(User.class); when(user.getEmail()).thenReturn(emailAddress); when(userService.getUserByEmail(emailAddress)).thenReturn(user); String token = "MyToken"; when(passwordResetTokenRepository.createToken(user)).thenReturn(token); MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("my.host.org"); request.setServerPort(80); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); String appTitle = "MyAppTitle"; when(appSettings.getTitle()).thenReturn(appTitle); passwordResetServiceImpl.resetPassword(emailAddress); SimpleMailMessage simpleMessage = new SimpleMailMessage(); simpleMessage.setTo(emailAddress); simpleMessage.setSubject("Password reset on MyAppTitle"); simpleMessage.setText( "Hello,\n" + "\n" + "You are receiving this email because we received a password reset request for your account.\n" + "\n" + "http: + "\n" + "If you did not request a password reset, you can safely ignore this email."); verify(mailSender).send(simpleMessage); }
@Transactional @RunAsSystem @Override public void resetPassword(String emailAddress) { User user = getUserByEmail(emailAddress); String token = passwordResetTokenService.createToken(user); sendPasswordResetMail(user, token); }
PasswordResetterImpl implements PasswordResetter { @Transactional @RunAsSystem @Override public void resetPassword(String emailAddress) { User user = getUserByEmail(emailAddress); String token = passwordResetTokenService.createToken(user); sendPasswordResetMail(user, token); } }
PasswordResetterImpl implements PasswordResetter { @Transactional @RunAsSystem @Override public void resetPassword(String emailAddress) { User user = getUserByEmail(emailAddress); String token = passwordResetTokenService.createToken(user); sendPasswordResetMail(user, token); } PasswordResetterImpl(
      PasswordResetTokenRepository passwordResetTokenRepository,
      UserService userService,
      MailSender mailSender,
      AppSettings appSettings); }
PasswordResetterImpl implements PasswordResetter { @Transactional @RunAsSystem @Override public void resetPassword(String emailAddress) { User user = getUserByEmail(emailAddress); String token = passwordResetTokenService.createToken(user); sendPasswordResetMail(user, token); } PasswordResetterImpl(
      PasswordResetTokenRepository passwordResetTokenRepository,
      UserService userService,
      MailSender mailSender,
      AppSettings appSettings); @Transactional @RunAsSystem @Override void resetPassword(String emailAddress); @Transactional(readOnly = true) @RunAsSystem @Override void validatePasswordResetToken(String username, String token); @Transactional @RunAsSystem @Override void changePassword(String username, String token, String password); @Transactional @Override void changePasswordAuthenticatedUser(String password); }
PasswordResetterImpl implements PasswordResetter { @Transactional @RunAsSystem @Override public void resetPassword(String emailAddress) { User user = getUserByEmail(emailAddress); String token = passwordResetTokenService.createToken(user); sendPasswordResetMail(user, token); } PasswordResetterImpl(
      PasswordResetTokenRepository passwordResetTokenRepository,
      UserService userService,
      MailSender mailSender,
      AppSettings appSettings); @Transactional @RunAsSystem @Override void resetPassword(String emailAddress); @Transactional(readOnly = true) @RunAsSystem @Override void validatePasswordResetToken(String username, String token); @Transactional @RunAsSystem @Override void changePassword(String username, String token, String password); @Transactional @Override void changePasswordAuthenticatedUser(String password);  }