@Test public void deleteTransactionsBefore_shouldReturnCountOfDeletedTransactions() throws ParseException { when(transactionDataStore.removeTransactionWithIndex(anyLong())).thenReturn(true); Date einsteinBornTime = getDate("18-Mar-1879 11:30:00"); Date dateBeforeEinsteinBorn1 = getDate("09-Apr-1869 05:35:58"); Date dateBeforeEinsteinBorn2 = getDate("22-May-1859 12:00:10"); Date dateAfterEinsteinBorn1 = getDate("29-Jun-2079 01:09:46"); Date dateAfterEinsteinBorn2 = getDate("10-Jan-1899 09:57:03"); Date dateAfterEinsteinBorn3 = getDate("01-Feb-1979 10:10:40"); List<HttpTransaction> list = new ArrayList<>(); list.add(getHttpTransactionWithIndexAndDate(1, dateAfterEinsteinBorn1, dateAfterEinsteinBorn3)); list.add(getHttpTransactionWithIndexAndDate(2, dateAfterEinsteinBorn1, dateBeforeEinsteinBorn2)); list.add(getHttpTransactionWithIndexAndDate(3, dateBeforeEinsteinBorn1, dateAfterEinsteinBorn2)); list.add(getHttpTransactionWithIndexAndDate(4, dateBeforeEinsteinBorn2, dateBeforeEinsteinBorn1)); list.add(getHttpTransactionWithIndexAndDate(5, einsteinBornTime, dateBeforeEinsteinBorn1)); list.add(getHttpTransactionWithIndex(99)); when(transactionDataStore.getDataList()).thenReturn(list); assertThat(transactionDao.deleteTransactionsBefore(einsteinBornTime)).isEqualTo(2); }
@Override public int deleteTransactionsBefore(Date beforeDate) { int deletedTransactionCount = 0; List<HttpTransaction> httpTransactionList = transactionDataStore.getDataList(); for (HttpTransaction transaction : httpTransactionList) { if (transaction.getRequestDate() != null && transaction.getRequestDate().before(beforeDate)) { if (transactionDataStore.removeTransactionWithIndex(transaction.getId())) { deletedTransactionCount++; } } } return deletedTransactionCount; }
IMDBTransactionDao implements TransactionDao { @Override public int deleteTransactionsBefore(Date beforeDate) { int deletedTransactionCount = 0; List<HttpTransaction> httpTransactionList = transactionDataStore.getDataList(); for (HttpTransaction transaction : httpTransactionList) { if (transaction.getRequestDate() != null && transaction.getRequestDate().before(beforeDate)) { if (transactionDataStore.removeTransactionWithIndex(transaction.getId())) { deletedTransactionCount++; } } } return deletedTransactionCount; } }
IMDBTransactionDao implements TransactionDao { @Override public int deleteTransactionsBefore(Date beforeDate) { int deletedTransactionCount = 0; List<HttpTransaction> httpTransactionList = transactionDataStore.getDataList(); for (HttpTransaction transaction : httpTransactionList) { if (transaction.getRequestDate() != null && transaction.getRequestDate().before(beforeDate)) { if (transactionDataStore.removeTransactionWithIndex(transaction.getId())) { deletedTransactionCount++; } } } return deletedTransactionCount; } IMDBTransactionDao(TransactionDataStore transactionDataStore, TransactionArchComponentProvider transactionArchComponentProvider, TransactionPredicateProvider transactionPredicateProvider); }
IMDBTransactionDao implements TransactionDao { @Override public int deleteTransactionsBefore(Date beforeDate) { int deletedTransactionCount = 0; List<HttpTransaction> httpTransactionList = transactionDataStore.getDataList(); for (HttpTransaction transaction : httpTransactionList) { if (transaction.getRequestDate() != null && transaction.getRequestDate().before(beforeDate)) { if (transactionDataStore.removeTransactionWithIndex(transaction.getId())) { deletedTransactionCount++; } } } return deletedTransactionCount; } 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); }
IMDBTransactionDao implements TransactionDao { @Override public int deleteTransactionsBefore(Date beforeDate) { int deletedTransactionCount = 0; List<HttpTransaction> httpTransactionList = transactionDataStore.getDataList(); for (HttpTransaction transaction : httpTransactionList) { if (transaction.getRequestDate() != null && transaction.getRequestDate().before(beforeDate)) { if (transactionDataStore.removeTransactionWithIndex(transaction.getId())) { deletedTransactionCount++; } } } return deletedTransactionCount; } 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);  }