@Test void testValidateToken() { User user = mock(User.class); String token = "MyToken"; @SuppressWarnings("unchecked") Query<PasswordResetToken> passwordResetTokenQuery = mock(Query.class, RETURNS_SELF); when(dataService.query(PASSWORD_RESET_TOKEN, PasswordResetToken.class)) .thenReturn(passwordResetTokenQuery); PasswordResetToken passwordResetToken = mock(PasswordResetToken.class); when(passwordResetTokenQuery.eq(PasswordResetTokenMetadata.USER, user).findOne()) .thenReturn(passwordResetToken); String tokenHash = "MyTokenHash"; when(passwordResetToken.getToken()).thenReturn(tokenHash); when(passwordResetToken.getExpirationDate()).thenReturn(Instant.now().plus(1, HOURS)); when(passwordEncoder.matches(token, tokenHash)).thenReturn(true); passwordResetTokenRepositoryImpl.validateToken(user, token); }
@Transactional(readOnly = true) @Override public void validateToken(User user, String token) { PasswordResetToken passwordResetToken = getPasswordResetToken(user, token); if (passwordResetToken.getExpirationDate().isBefore(now())) { throw new ExpiredPasswordResetTokenException(passwordResetToken); } }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional(readOnly = true) @Override public void validateToken(User user, String token) { PasswordResetToken passwordResetToken = getPasswordResetToken(user, token); if (passwordResetToken.getExpirationDate().isBefore(now())) { throw new ExpiredPasswordResetTokenException(passwordResetToken); } } }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional(readOnly = true) @Override public void validateToken(User user, String token) { PasswordResetToken passwordResetToken = getPasswordResetToken(user, token); if (passwordResetToken.getExpirationDate().isBefore(now())) { throw new ExpiredPasswordResetTokenException(passwordResetToken); } } PasswordResetTokenRepositoryImpl(
      PasswordResetTokenFactory passwordResetTokenFactory,
      PasswordEncoder passwordEncoder,
      DataService dataService); }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional(readOnly = true) @Override public void validateToken(User user, String token) { PasswordResetToken passwordResetToken = getPasswordResetToken(user, token); if (passwordResetToken.getExpirationDate().isBefore(now())) { throw new ExpiredPasswordResetTokenException(passwordResetToken); } } PasswordResetTokenRepositoryImpl(
      PasswordResetTokenFactory passwordResetTokenFactory,
      PasswordEncoder passwordEncoder,
      DataService dataService); @Transactional @Override String createToken(User user); @Transactional(readOnly = true) @Override void validateToken(User user, String token); @Transactional @Override void deleteToken(User user, String token); }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional(readOnly = true) @Override public void validateToken(User user, String token) { PasswordResetToken passwordResetToken = getPasswordResetToken(user, token); if (passwordResetToken.getExpirationDate().isBefore(now())) { throw new ExpiredPasswordResetTokenException(passwordResetToken); } } PasswordResetTokenRepositoryImpl(
      PasswordResetTokenFactory passwordResetTokenFactory,
      PasswordEncoder passwordEncoder,
      DataService dataService); @Transactional @Override String createToken(User user); @Transactional(readOnly = true) @Override void validateToken(User user, String token); @Transactional @Override void deleteToken(User user, String token);  }