### Question:
IMDBTransactionDao implements TransactionDao { @Override public int deleteTransactions(HttpTransaction... httpTransactions) { int updates = 0; for (HttpTransaction httpTransaction : httpTransactions) { if (httpTransaction.getId() > 0 && transactionDataStore.removeTransactionWithIndex(httpTransaction.getId())) { updates++; } } return updates; } IMDBTransactionDao(TransactionDataStore transactionDataStore, TransactionArchComponentProvider transactionArchComponentProvider, TransactionPredicateProvider transactionPredicateProvider); @Override long insertTransaction(HttpTransaction httpTransaction); @Override int updateTransaction(HttpTransaction httpTransaction); @Override int deleteTransactions(HttpTransaction... httpTransactions); @Override int deleteTransactionsBefore(Date beforeDate); @Override int clearAll(); @Override DataSource.Factory<Integer, HttpTransaction> getAllTransactions(); @Override LiveData<HttpTransaction> getTransactionsWithId(long id); @Override DataSource.Factory<Integer, HttpTransaction> getAllTransactionsWith(String key, SearchType searchType);  }### Answer:
@Test public void whenTransactions_areDeleted_shouldReturnTotalNoOfDeletedTransactions() { when(transactionDataStore.removeTransactionWithIndex(anyLong())).thenAnswer( new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { long a = (Long) invocation.getArguments()[0]; return a % 2 == 0; } } ); assertThat(transactionDao.deleteTransactions(getHttpTransactionsWithIndices(1, 2, 4, 5, 10, 30, 99))).isEqualTo(4); }
@Test public void whenZeroAndNegativeTransactions_areDeleted_shouldReturnZero() { assertThat(transactionDao.deleteTransactions(getHttpTransactionsWithIndices(0, -1, -40, -100))).isZero(); }
@Test public void whenTransaction_areDeleted_onlyPositiveIndexShouldBeForwardedToData() { transactionDao.deleteTransactions(getHttpTransactionsWithIndices(0, -1, -40, -100, 2, 350)); verifyOnlyTransactionsDeletedAreWithIndices(2, 350); }