UserService { public Optional<User> requestPasswordReset(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(String key); Optional<User> completePasswordReset(String newPassword, String key); Optional<User> requestPasswordReset(String mail); User createUserInformation(String login, String password, String firstName, String lastName, String email,
                                      String langKey); void updateUserInformation(String firstName, String lastName, String email, String langKey); void changePassword(String password); @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(); }