UserService { public Optional<User> completePasswordReset(String password, String key) { return this.userRepository.findByResetKey(key).map(user -> { user.setPassword(this.passwordEncoder.encode(password)); user.setResetKey(null); return user; }); } UserService(UserRepository userRepository, AuthorityRepository authorityRepository, PasswordEncoder passwordEncoder); User register(UserRegister user); void update(UserDTO userDTO); void update(String id, String login, String firstName, String lastName, String email, String langKey); void delete(String login); Optional<User> activateRegistration(String key); Page<UserDTO> search(Pageable pageable, String query); Page<UserDTO> getAll(Pageable pageable); Optional<User> getById(String id); Optional<User> getByLogin(String login); Optional<User> getByEmail(String email); void changePassword(String id, String password); Optional<User> requestPasswordReset(String mail); Optional<User> completePasswordReset(String password, String key); @Scheduled(cron = "0 0 1 * * ?") void removeNotActivatedUsers();  }
@Test public void whenSendValidPasswordResetKey() { User user = this.createUser(); user.setActivated(true); user.setResetKey("12345678910111213141"); this.userRepository.save(user); Optional<User> result = this.userService.completePasswordReset("testtest", user.getResetKey()); assertTrue(result.isPresent()); }