@Test public void sendPasswordRecoveryEmailToSimpleTest() { String email = "foo"; User user = new User(); when(userRepo.findByEmail(email)).thenReturn(Optional.of(user)); String token = "bar"; when(jwtTool.generateTokenKey()).thenReturn(token); ReflectionTestUtils.setField(passwordRecoveryService, "tokenExpirationTimeInHours", 24); passwordRecoveryService.sendPasswordRecoveryEmailTo(email); verify(restorePasswordEmailRepo).save(refEq( RestorePasswordEmail.builder() .user(user) .token(token) .build(), "expiryDate" )); verify(rabbitTemplate).convertAndSend( refEq(sendEmailTopic), refEq(PASSWORD_RECOVERY_ROUTING_KEY), refEq(new PasswordRecoveryMessage( user.getId(), user.getName(), user.getEmail(), token )) ); }
@Transactional @Override public void sendPasswordRecoveryEmailTo(String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + email)); RestorePasswordEmail restorePasswordEmail = user.getRestorePasswordEmail(); if (restorePasswordEmail != null) { throw new WrongEmailException(PASSWORD_RESTORE_LINK_ALREADY_SENT + email); } savePasswordRestorationTokenForUser(user, jwtTool.generateTokenKey()); }
PasswordRecoveryServiceImpl implements PasswordRecoveryService { @Transactional @Override public void sendPasswordRecoveryEmailTo(String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + email)); RestorePasswordEmail restorePasswordEmail = user.getRestorePasswordEmail(); if (restorePasswordEmail != null) { throw new WrongEmailException(PASSWORD_RESTORE_LINK_ALREADY_SENT + email); } savePasswordRestorationTokenForUser(user, jwtTool.generateTokenKey()); } }
PasswordRecoveryServiceImpl implements PasswordRecoveryService { @Transactional @Override public void sendPasswordRecoveryEmailTo(String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + email)); RestorePasswordEmail restorePasswordEmail = user.getRestorePasswordEmail(); if (restorePasswordEmail != null) { throw new WrongEmailException(PASSWORD_RESTORE_LINK_ALREADY_SENT + email); } savePasswordRestorationTokenForUser(user, jwtTool.generateTokenKey()); } PasswordRecoveryServiceImpl(
        RestorePasswordEmailRepo restorePasswordEmailRepo,
        UserRepo userRepo,
        ApplicationEventPublisher applicationEventPublisher,
        RabbitTemplate rabbitTemplate,
        JwtTool jwtTool
    ); }
PasswordRecoveryServiceImpl implements PasswordRecoveryService { @Transactional @Override public void sendPasswordRecoveryEmailTo(String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + email)); RestorePasswordEmail restorePasswordEmail = user.getRestorePasswordEmail(); if (restorePasswordEmail != null) { throw new WrongEmailException(PASSWORD_RESTORE_LINK_ALREADY_SENT + email); } savePasswordRestorationTokenForUser(user, jwtTool.generateTokenKey()); } PasswordRecoveryServiceImpl(
        RestorePasswordEmailRepo restorePasswordEmailRepo,
        UserRepo userRepo,
        ApplicationEventPublisher applicationEventPublisher,
        RabbitTemplate rabbitTemplate,
        JwtTool jwtTool
    ); @Transactional @Override void sendPasswordRecoveryEmailTo(String email); @Transactional @Override void updatePasswordUsingToken(String token, String newPassword); }
PasswordRecoveryServiceImpl implements PasswordRecoveryService { @Transactional @Override public void sendPasswordRecoveryEmailTo(String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + email)); RestorePasswordEmail restorePasswordEmail = user.getRestorePasswordEmail(); if (restorePasswordEmail != null) { throw new WrongEmailException(PASSWORD_RESTORE_LINK_ALREADY_SENT + email); } savePasswordRestorationTokenForUser(user, jwtTool.generateTokenKey()); } PasswordRecoveryServiceImpl(
        RestorePasswordEmailRepo restorePasswordEmailRepo,
        UserRepo userRepo,
        ApplicationEventPublisher applicationEventPublisher,
        RabbitTemplate rabbitTemplate,
        JwtTool jwtTool
    ); @Transactional @Override void sendPasswordRecoveryEmailTo(String email); @Transactional @Override void updatePasswordUsingToken(String token, String newPassword);  }