UserService { public Optional<User> requestPasswordReset(final String mail) { return userRepository.findOneByEmail(mail).filter(user -> user.getActivated() == true).map(user -> { user.setResetKey(RandomUtil.generateResetKey()); user.setResetDate(DateTime.now()); userRepository.save(user); return user; }); }  Optional<User> activateRegistration(final String key); Optional<User> completePasswordReset(final String newPassword, final String key); Optional<User> requestPasswordReset(final String mail); User createUserInformation(final String login, final String password, final String firstName, final String lastName, final String email, final String langKey); void updateUserInformation(final String firstName, final String lastName, final String email, final String langKey); void changePassword(final String password); @Transactional(readOnly = true) Optional<User> getUserWithAuthoritiesByLogin(final String login); @Transactional(readOnly = true) User getUserWithAuthorities(final Long id); @Transactional(readOnly = true) User getUserWithAuthorities(); @Scheduled(cron = "0 0 0 * * ?") void removeOldPersistentTokens(); @Scheduled(cron = "0 0 1 * * ?") void removeNotActivatedUsers();  }
@Test public void assertThatUserMustExistToResetPassword() { Optional<User> maybeUser = userService.requestPasswordReset("john.doe@localhost"); assertThat(maybeUser.isPresent()).isFalse(); maybeUser = userService.requestPasswordReset("admin@localhost"); assertThat(maybeUser.isPresent()).isTrue(); assertThat(maybeUser.get().getEmail()).isEqualTo("admin@localhost"); assertThat(maybeUser.get().getResetDate()).isNotNull(); assertThat(maybeUser.get().getResetKey()).isNotNull(); }