@Test void testCreateTokenDeleteExistingToken() { User user = when(mock(User.class).isActive()).thenReturn(true).getMock(); PasswordResetToken existingPasswordResetToken = mock(PasswordResetToken.class); @SuppressWarnings("unchecked") Query<PasswordResetToken> passwordResetTokenQuery = mock(Query.class, RETURNS_SELF); when(dataService.query(PASSWORD_RESET_TOKEN, PasswordResetToken.class)) .thenReturn(passwordResetTokenQuery); when(passwordResetTokenQuery.eq(PasswordResetTokenMetadata.USER, user).findOne()) .thenReturn(existingPasswordResetToken); PasswordResetToken passwordResetToken = mock(PasswordResetToken.class); when(passwordResetTokenFactory.create()).thenReturn(passwordResetToken); passwordResetTokenRepositoryImpl.createToken(user); verify(dataService).delete(PASSWORD_RESET_TOKEN, existingPasswordResetToken); verify(passwordResetToken).setUser(user); verify(passwordResetToken).setToken(any()); verify(passwordResetToken).setExpirationDate(any()); verify(dataService).add(PASSWORD_RESET_TOKEN, passwordResetToken); }
@Transactional @Override public String createToken(User user) { if (!user.isActive()) { throw new PasswordResetTokenCreationException(); } deleteTokenIfExists(user); return addPasswordResetToken(user); }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional @Override public String createToken(User user) { if (!user.isActive()) { throw new PasswordResetTokenCreationException(); } deleteTokenIfExists(user); return addPasswordResetToken(user); } }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional @Override public String createToken(User user) { if (!user.isActive()) { throw new PasswordResetTokenCreationException(); } deleteTokenIfExists(user); return addPasswordResetToken(user); } PasswordResetTokenRepositoryImpl(
      PasswordResetTokenFactory passwordResetTokenFactory,
      PasswordEncoder passwordEncoder,
      DataService dataService); }
PasswordResetTokenRepositoryImpl implements PasswordResetTokenRepository { @Transactional @Override public String createToken(User user) { if (!user.isActive()) { throw new PasswordResetTokenCreationException(); } deleteTokenIfExists(user); return addPasswordResetToken(user); } 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 @Override public String createToken(User user) { if (!user.isActive()) { throw new PasswordResetTokenCreationException(); } deleteTokenIfExists(user); return addPasswordResetToken(user); } 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);  }