### Question:
TransactionEventHandler { @QueryHandler public TransactionView find(TransactionByIdQuery query) { String transactionId = query.getTransactionId().getIdentifier(); return Optional.ofNullable(transactionViewRepository.getOne(transactionId)) .orElseGet(() -> { logger.warn( "Tried to retrieve a Transaction query model with a non existent transaction id [{}]", transactionId ); return null; }); } TransactionEventHandler(OrderBookViewRepository orderBookViewRepository,
                                   TransactionViewRepository transactionViewRepository); @EventHandler void on(BuyTransactionStartedEvent event); @EventHandler void on(SellTransactionStartedEvent event); @EventHandler void on(BuyTransactionCancelledEvent event); @EventHandler void on(SellTransactionCancelledEvent event); @EventHandler void on(BuyTransactionConfirmedEvent event); @EventHandler void on(SellTransactionConfirmedEvent event); @EventHandler void on(BuyTransactionExecutedEvent event); @EventHandler void on(SellTransactionExecutedEvent event); @EventHandler void on(BuyTransactionPartiallyExecutedEvent event); @EventHandler void on(SellTransactionPartiallyExecutedEvent event); @QueryHandler TransactionView find(TransactionByIdQuery query); @QueryHandler List<TransactionView> find(TransactionsByPortfolioIdQuery query);  }### Answer:
@Test public void testFindTransactionByIdReturnsATransactionView() { TransactionView testView = new TransactionView(); when(transactionViewRepository.getOne(transactionId.getIdentifier())).thenReturn(testView); TransactionView result = testSubject.find(new TransactionByIdQuery(transactionId)); assertNotNull(result); assertEquals(testView, result); }
@Test public void testFindTransactionByIdReturnsNullForNonExistentTransactionId() { when(transactionViewRepository.getOne(transactionId.getIdentifier())).thenReturn(null); assertNull(testSubject.find(new TransactionByIdQuery(transactionId))); }
@Test public void testFindTransactionsByPortfolioIdReturnsATransactionView() { List<TransactionView> testViews = new ArrayList<>(); testViews.add(new TransactionView()); when(transactionViewRepository.findByPortfolioId(portfolioId.getIdentifier())).thenReturn(testViews); List<TransactionView> results = testSubject.find(new TransactionsByPortfolioIdQuery(portfolioId)); assertNotNull(results); assertFalse(results.isEmpty()); assertEquals(testViews, results); }
@Test public void testFindTransactionsByIdReturnsAnEmptyListForNonExistentTransactionId() { when(transactionViewRepository.findByPortfolioId(portfolioId.getIdentifier())).thenReturn(null); assertTrue(testSubject.find(new TransactionsByPortfolioIdQuery(portfolioId)).isEmpty()); }