TransactionEventHandler { @EventHandler public void on(BuyTransactionStartedEvent event) { startTransaction(event, TransactionType.BUY); } @Autowired  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);  }
@Test public void handleBuyTransactionStartedEvent() { testSubject.on(new BuyTransactionStartedEvent(transactionIdentifier, orderBookIdentifier, portfolioIdentifier, DEFAULT_TOTAL_ITEMS, DEFAULT_ITEM_PRICE)); verify(transactionViewRepository).save(argThat(new TransactionEntryMatcher( DEFAULT_TOTAL_ITEMS, 0, DEFAULT_COMPANY_NAME, DEFAULT_ITEM_PRICE, STARTED, BUY ))); }
@Test public void handleSellTransactionStartedEvent() { testSubject.on(new SellTransactionStartedEvent(transactionIdentifier, orderBookIdentifier, portfolioIdentifier, DEFAULT_TOTAL_ITEMS, DEFAULT_ITEM_PRICE)); verify(transactionViewRepository).save(argThat(new TransactionEntryMatcher( DEFAULT_TOTAL_ITEMS, 0, DEFAULT_COMPANY_NAME, DEFAULT_ITEM_PRICE, STARTED, SELL ))); }
@Test public void handleSellTransactionCancelledEvent() { TransactionView transactionView = new TransactionView(); transactionView.setIdentifier(transactionIdentifier.getIdentifier()); transactionView.setAmountOfExecutedItems(0); transactionView.setPricePerItem(DEFAULT_ITEM_PRICE); transactionView.setState(STARTED); transactionView.setAmountOfItems(DEFAULT_TOTAL_ITEMS); transactionView.setCompanyName(DEFAULT_COMPANY_NAME); transactionView.setOrderBookId(orderBookIdentifier.getIdentifier()); transactionView.setPortfolioId(portfolioIdentifier.getIdentifier()); transactionView.setType(SELL); when(transactionViewRepository.findOne(transactionIdentifier.getIdentifier())).thenReturn(transactionView); testSubject.on(new SellTransactionCancelledEvent(transactionIdentifier, DEFAULT_TOTAL_ITEMS, DEFAULT_TOTAL_ITEMS)); verify(transactionViewRepository).save(argThat(new TransactionEntryMatcher( DEFAULT_TOTAL_ITEMS, 0, DEFAULT_COMPANY_NAME, DEFAULT_ITEM_PRICE, CANCELLED, SELL ))); }