### Question:
DisplayedTransactions extends ObservableListDecorator<TransactionsListItem> { void update() { List<TransactionsListItem> transactionsListItems = getTransactionListItems(); forEach(TransactionsListItem::cleanup); setAll(transactionsListItems); } DisplayedTransactions(BtcWalletService btcWalletService, TradableRepository tradableRepository,
                          TransactionListItemFactory transactionListItemFactory,
                          TransactionAwareTradableFactory transactionAwareTradableFactory);   }### Answer:
@Test public void testUpdate() { Set<Transaction> transactions = Sets.newHashSet(mock(Transaction.class), mock(Transaction.class)); BtcWalletService walletService = mock(BtcWalletService.class); when(walletService.getTransactions(false)).thenReturn(transactions); TransactionListItemFactory transactionListItemFactory = mock(TransactionListItemFactory.class, RETURNS_DEEP_STUBS); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") DisplayedTransactions testedEntity = new DisplayedTransactions( walletService, mock(TradableRepository.class), transactionListItemFactory, mock(TransactionAwareTradableFactory.class)); testedEntity.update(); assertEquals(transactions.size(), testedEntity.size()); }
@Test public void testUpdateWhenRepositoryIsEmpty() { BtcWalletService walletService = mock(BtcWalletService.class); when(walletService.getTransactions(false)) .thenReturn(Collections.singleton(mock(Transaction.class))); TradableRepository tradableRepository = mock(TradableRepository.class); when(tradableRepository.getAll()).thenReturn(Collections.emptySet()); TransactionListItemFactory transactionListItemFactory = mock(TransactionListItemFactory.class); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") DisplayedTransactions testedEntity = new DisplayedTransactions( walletService, tradableRepository, transactionListItemFactory, mock(TransactionAwareTradableFactory.class)); testedEntity.update(); assertEquals(1, testedEntity.size()); verify(transactionListItemFactory).create(any(), nullable(TransactionAwareTradable.class)); }