@Test public void generatesANewRandomUserPassword() throws Exception { User user = user().build(); given(passwordGenerator.get()).willReturn("somepassword"); GeneratePasswordResetResponse password = underTest.resetPassword(user); assertThat(password.password(), is("somepassword")); }
@Transactional GeneratePasswordResetResponse resetPassword(User user) { log.info("Generating new password for user={}. User performed self-reset via password reset loop", user); String newPassword = passwordGenerator.get(); String passwordHash = passwordEncoder.encode(newPassword); user.setPasswordHash(passwordHash); userRepository.save(user); return ImmutableGeneratePasswordResetResponse.builder() .withPassword(newPassword) .build(); }
PasswordResetService { @Transactional GeneratePasswordResetResponse resetPassword(User user) { log.info("Generating new password for user={}. User performed self-reset via password reset loop", user); String newPassword = passwordGenerator.get(); String passwordHash = passwordEncoder.encode(newPassword); user.setPasswordHash(passwordHash); userRepository.save(user); return ImmutableGeneratePasswordResetResponse.builder() .withPassword(newPassword) .build(); } }
PasswordResetService { @Transactional GeneratePasswordResetResponse resetPassword(User user) { log.info("Generating new password for user={}. User performed self-reset via password reset loop", user); String newPassword = passwordGenerator.get(); String passwordHash = passwordEncoder.encode(newPassword); user.setPasswordHash(passwordHash); userRepository.save(user); return ImmutableGeneratePasswordResetResponse.builder() .withPassword(newPassword) .build(); } @Autowired  PasswordResetService(StrongPasswordEncoder passwordEncoder,
                                PasswordGenerator passwordGenerator,
                                UserRepository userRepository); }
PasswordResetService { @Transactional GeneratePasswordResetResponse resetPassword(User user) { log.info("Generating new password for user={}. User performed self-reset via password reset loop", user); String newPassword = passwordGenerator.get(); String passwordHash = passwordEncoder.encode(newPassword); user.setPasswordHash(passwordHash); userRepository.save(user); return ImmutableGeneratePasswordResetResponse.builder() .withPassword(newPassword) .build(); } @Autowired  PasswordResetService(StrongPasswordEncoder passwordEncoder,
                                PasswordGenerator passwordGenerator,
                                UserRepository userRepository);  }
PasswordResetService { @Transactional GeneratePasswordResetResponse resetPassword(User user) { log.info("Generating new password for user={}. User performed self-reset via password reset loop", user); String newPassword = passwordGenerator.get(); String passwordHash = passwordEncoder.encode(newPassword); user.setPasswordHash(passwordHash); userRepository.save(user); return ImmutableGeneratePasswordResetResponse.builder() .withPassword(newPassword) .build(); } @Autowired  PasswordResetService(StrongPasswordEncoder passwordEncoder,
                                PasswordGenerator passwordGenerator,
                                UserRepository userRepository);   }