### Question:
AccountService { public List<Account> getAccounts() { List<Account> accounts = new ArrayList<>(); Iterator<Account> accountIterator = repository.findAll().iterator(); while (accountIterator.hasNext()) { accounts.add(accountIterator.next()); } return accounts; }  boolean isAccountPresent(Long id); Account getAccountById(Long id); List<Account> getAccounts(); Account addAccount(Account account); Account updateAccount(Long id, Account account); void deleteAccount(Long id);  }### Answer:
@Test public void whenAccountIsPresentThenItShouldReturnAccountList() { List<Account> accounts = new ArrayList<>(); Account mockAccount = mock(Account.class); accounts.add(mockAccount); when(mockAccount.getId()).thenReturn(new Long(1)); when(mockAccount.getName()).thenReturn("Sagar Jadhav"); when(repository.findAll()).thenReturn(new Iterable<Account>() { @Override public Iterator<Account> iterator() { return accounts.iterator(); } }); List<Account> retrievedAccounts = service.getAccounts(); assertEquals(retrievedAccounts.size(), accounts.size()); assertEquals(retrievedAccounts.get(0), accounts.get(0)); }