AccountService { @Cacheable(value = "authorizationCache") public Account findAccountprofileByAuthtoken(String token) { logger.debug("AccountService.findAccountprofileByAuthtoken looking for authToken: " + token); if (token == null) { logger.error("AccountService.findAccountprofileByAuthtoken(): token is null"); throw new AuthenticationException("Authorization Token is null"); } Account accountProfile = null; accountProfile = accounts.findByAuthtoken(token); if (accountProfile == null) { logger.error("AccountService.findAccountprofileByAuthtoken(): accountProfile is null for token=" + token); throw new AuthenticationException("Authorization Token not found"); } return accountProfile; }  Account findAccount(Integer id); Account findAccount(String id); @Cacheable(value = "authorizationCache") Account findAccountprofileByAuthtoken(String token); Integer saveAccount(Account accountRequest); Map<String, Object> login(String username, String password); Account logout(String userId);  }
@Test public void doFindAccountByAuthToken() { when(repo.findByAuthtoken(ServiceTestConfiguration.AUTH_TOKEN)).thenReturn(ServiceTestConfiguration.account()); assertEquals(service.findAccountprofileByAuthtoken(ServiceTestConfiguration.AUTH_TOKEN).toString(),ServiceTestConfiguration.account().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); }