### Question:
AuthUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = repository.findOne(username); if (user == null) { throw new UsernameNotFoundException(username); } log.debug(" User from username ", user.toString()); return user; }  @Override UserDetails loadUserByUsername(String username);  }### Answer:
@Test public void getUsernameWhenUserExists() { final User user = new User(); when(repository.findOne(any())).thenReturn(user); UserDetails loaded = service.loadUserByUsername("Username"); assertEquals(user, loaded); }
@Test(expected = UsernameNotFoundException.class) public void getUsernameWhenUserNotExists() { service.loadUserByUsername("Username"); }