UserService extends AbstractUserService implements UserDetailsService { public User findByUsername(String username) { return userRepository.findByUsername(username); }  @Override @CachePut(value = ENTITY_NAME, key = "#result.id", unless = "#result == null") boolean beforeSave(User user); @Override @Cacheable(value = ENTITY_NAME, key = "#id", unless = "#result == null") User findById(String id); @Override UserDetails loadUserByUsername(String username); User findByUsername(String username); User register(User user); User setRoles(String userId, String[] roleIds); User getCurrentUser(); Collection<? extends String> getCurrentUserAuthorities();  }
@Test public void testFindByUsername(){ String username = "administrator"; User user = userService.findByUsername(username); UserDetails userDetails = userDetailsService.loadUserByUsername(username); assertNotNull(user); }