### Question:
IMDBTransactionDao implements TransactionDao { @Override public long insertTransaction(HttpTransaction httpTransaction) { long newTransactionIndex; if (httpTransaction.getId() == 0) { newTransactionIndex = currentIndex; } else { newTransactionIndex = httpTransaction.getId(); } return addTransactionWithIndex(httpTransaction, newTransactionIndex); } 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 whenZeroIndexTransaction_isInserted_returnedIndexShouldNotBeZero() { assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isNotZero(); }
@Test public void whenZeroIndexTransactions_areInserted_thereIdsShouldIncrementByOneStartingFromOneAndShouldReturnTheSame() { assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isEqualTo(1); assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isEqualTo(2); assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isEqualTo(3); verifyOnlyTransactionsAddedAreWithIndices(1, 2, 3); }
@Test public void whenPositiveIndexTransactionIsInserted_shouldBeAddedAndReturnSameIndex() { int index = 10; HttpTransaction transaction = getHttpTransactionWithIndex(index); assertThat(transactionDao.insertTransaction(transaction)).isEqualTo(10); verifyOnlyTransactionAdded(transaction); }
@Test public void whenATransactionWithZeroIndex_isInserted_transactionIndexShouldAlwaysIncrementByOneFromMaxIndexOfAllTransactions() { assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isEqualTo(1); int transactionIndex = 22; assertThat(transactionDao.insertTransaction(getHttpTransactionWithIndex(transactionIndex))).isEqualTo(22); transactionIndex = 2; assertThat(transactionDao.insertTransaction(getHttpTransactionWithIndex(transactionIndex))).isEqualTo(2); assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isEqualTo(23); transactionIndex = 200; assertThat(transactionDao.insertTransaction(getHttpTransactionWithIndex(transactionIndex))).isEqualTo(200); assertThat(transactionDao.insertTransaction(getHttpTransactionWithZeroIndex())).isEqualTo(201); verifyOnlyTransactionsAddedAreWithIndices(1, 22, 2, 23, 200, 201); }