AccountService { public Account findAccount(Integer id) { logger.debug("AccountService.findAccount: id=" + id); Optional<Account> account = accounts.findById(id); if (!account.isPresent()) { 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.get())); return account.get(); }  Account findAccount(Integer id); List<Account> findAccounts(String user); List<Account> findAccountsByType(String id, AccountType type); Integer saveAccount(Account accountRequest);  }
@Test public void doFindAccount() { when(repo.findById(ServiceTestConfiguration.PROFILE_ID)).thenReturn(Optional.of(ServiceTestConfiguration.account())); assertEquals(service.findAccount(ServiceTestConfiguration.PROFILE_ID).toString(),ServiceTestConfiguration.account().toString()); }
@Test(expected=NoRecordsFoundException.class) public void doFindNullAccount() { when(repo.findById(999)).thenReturn(Optional.empty()); service.findAccount(999); }