@Test(expected = NotFoundException.class) public void sendPasswordRecoveryEmailToNonExistentUserTest() { String email = "foo"; when(userRepo.findByEmail(email)).thenReturn(Optional.empty()); passwordRecoveryService.sendPasswordRecoveryEmailTo(email); }
@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);  }