PortfolioItemEventHandler { @EventHandler public void on(ItemsAddedToPortfolioEvent event) { OrderBookId orderBookId = event.getOrderBookId(); logger.debug("Handle ItemsAddedToPortfolioEvent for orderBook with identifier {}", orderBookId); ItemEntry itemEntry = createItemEntry(orderBookId.getIdentifier(), event.getAmountOfItemsAdded()); PortfolioView portfolioView = portfolioViewRepository.findOne(event.getPortfolioId().getIdentifier()); portfolioView.addItemInPossession(itemEntry); portfolioViewRepository.save(portfolioView); } @Autowired  PortfolioItemEventHandler(PortfolioViewRepository portfolioViewRepository,
                                     OrderBookViewRepository orderBookViewRepository); @EventHandler void on(ItemsAddedToPortfolioEvent event); @EventHandler void on(ItemReservationCancelledForPortfolioEvent event); @EventHandler void on(ItemReservationConfirmedForPortfolioEvent event); @EventHandler void on(ItemsReservedEvent event);  }
@Test public void testHandleEventAddItems() { testSubject.on(new ItemsAddedToPortfolioEvent(portfolioId, itemId, 100)); verify(portfolioViewRepository).save(argThat(new PortfolioEntryMatcher( itemId.getIdentifier(), 1, 2 * DEFAULT_AMOUNT_ITEMS, 1, DEFAULT_AMOUNT_ITEMS ))); }
@Test public void testHandleEventCancelItemReservation() { testSubject.on(new ItemReservationCancelledForPortfolioEvent(portfolioId, itemId, transactionId, DEFAULT_AMOUNT_ITEMS)); verify(portfolioViewRepository).save(argThat(new PortfolioEntryMatcher( itemId.getIdentifier(), 1, 2 * DEFAULT_AMOUNT_ITEMS, 0, 0 ))); }
@Test public void testHandleEventConfirmItemReservation() { testSubject.on(new ItemReservationConfirmedForPortfolioEvent(portfolioId, itemId, transactionId, 50)); verify(portfolioViewRepository).save(argThat(new PortfolioEntryMatcher( itemId.getIdentifier(), 1, DEFAULT_AMOUNT_ITEMS - 50, 1, DEFAULT_AMOUNT_ITEMS - 50 ))); }
@Test public void testHandleItemReservedEvent() { testSubject.on(new ItemsReservedEvent(portfolioId, itemId, transactionId, DEFAULT_AMOUNT_ITEMS)); verify(portfolioViewRepository).save(argThat(new PortfolioEntryMatcher( itemId.getIdentifier(), 1, DEFAULT_AMOUNT_ITEMS, 1, 2 * DEFAULT_AMOUNT_ITEMS ))); }