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