### Question:
UserService { public User register(User user) { setPasswordAndRole(user); return userRepository.save(user); } UserService(UserRepository userRepository, BCryptPasswordEncoder encoder); User register(User user); Optional<User> findByUsername(String username);  }### Answer:
@Test public void register() { User user = createTestUser(); when(userRepository.save(user)) .thenReturn(user); userService.register(user); verify(userRepository, times(1)).save(user); }