### Question:
UserDetailsServiceImpl implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username); if (user != null) { return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), mapRoles(user)); } throw new UsernameNotFoundException(String.format("Username '%s' not found", username)); } @Autowired  UserDetailsServiceImpl(UserRepository userRepository); @Override UserDetails loadUserByUsername(String username);  }### Answer:
@Test public void testLoadUserByUsername() throws Exception { UserDetails userDetails = userDetailsService.loadUserByUsername(ADMIN); assertNotNull(userDetails); assertEquals(ADMIN, userDetails.getUsername()); assertFalse(userDetails.getAuthorities().isEmpty()); assertEquals(ADMIN, userDetails.getAuthorities().iterator().next().getAuthority()); }
@Test(expected = UsernameNotFoundException.class) public void testLoadUserByUsernameNotFound() throws Exception { userDetailsService.loadUserByUsername("customer"); }