AccountService { public Account findAccount(Integer id) { logger.debug("AccountService.findAccount: id=" + id); Account account = accounts.findOne(id); if (account == null) { logger.warn("AccountService.findAccount: could not find account with id: " + id); throw new NoRecordsFoundException(); } logger.info(String.format("AccountService.findAccount - retrieved account with id: %s. Payload is: %s", id, account)); return account; }  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(expected=NoRecordsFoundException.class) public void doFindAccountUserIdNotFound() { when(repo.findByUserid(ServiceTestConfiguration.BAD_USER_ID)).thenReturn(null); service.findAccount(ServiceTestConfiguration.BAD_USER_ID); }
@Test(expected=NoRecordsFoundException.class) public void doFindNullAccount() { when(repo.findOne(999)).thenReturn(null); service.findAccount(999); }
@Test public void doFindAccount() { when(repo.findOne(ServiceTestConfiguration.PROFILE_ID)).thenReturn(ServiceTestConfiguration.account()); assertEquals(service.findAccount(ServiceTestConfiguration.PROFILE_ID).toString(),ServiceTestConfiguration.account().toString()); }
@Test public void doFindAccountUserId() { when(repo.findByUserid(ServiceTestConfiguration.USER_ID)).thenReturn(ServiceTestConfiguration.account()); assertEquals(service.findAccount(ServiceTestConfiguration.USER_ID).toString(),ServiceTestConfiguration.account().toString()); }