UserService { @Cacheable(value = "authorizationCache") public User findAccountprofileByAuthtoken(String token) { logger.debug("UserService.findAccountprofileByAuthtoken looking for authToken: " + token); if (token == null) { logger.error("UserService.findAccountprofileByAuthtoken(): token is null"); throw new AuthenticationException("Authorization Token is null"); } User accountProfile = null; accountProfile = user.findByAuthtoken(token); if (accountProfile == null) { logger.error("UserService.findAccountprofileByAuthtoken(): accountProfile is null for token=" + token); throw new AuthenticationException("Authorization Token not found"); } return accountProfile; }  User findUser(Integer id); User findUser(String username); @Cacheable(value = "authorizationCache") User findAccountprofileByAuthtoken(String token); Integer saveUser(User userRequest); Map<String, Object> login(String username, String password); User logout(String userId);  }
@Test public void doFindAccountByAuthToken() { when(repo.findByAuthtoken(ServiceTestConfiguration.AUTH_TOKEN)).thenReturn(ServiceTestConfiguration.user()); assertEquals(service.findAccountprofileByAuthtoken(ServiceTestConfiguration.AUTH_TOKEN).toString(),ServiceTestConfiguration.user().toString()); }
@Test(expected=AuthenticationException.class) public void doFindNullAccountByAuthToken() { when(repo.findByAuthtoken("faef8649-280d-4ba4-bdf6-574e758a04a8")).thenReturn(null); service.findAccountprofileByAuthtoken("faef8649-280d-4ba4-bdf6-574e758a04a8"); }
@Test(expected=AuthenticationException.class) public void doFindAccountByAuthTokenNull() { service.findAccountprofileByAuthtoken(null); }