@Test(expected=NoRecordsFoundException.class) public void doFindNullAccount() { when(repo.findById(999)).thenReturn(Optional.empty()); service.findAccount(999); }
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(); }
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(); } }
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(); }  }
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); }
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);  }