@SuppressWarnings("UnnecessaryLocalVariable") @Test public void testOnItemsAddedToPortfolioEventItemsAreAdded() { int expectedNumberOfPossessedItems = 1; int expectedAmountOfPossessedItems = 2 * DEFAULT_AMOUNT_ITEMS; int expectedNumberOfReservedItems = 1; int expectedAmountOfReservedItems = DEFAULT_AMOUNT_ITEMS; testSubject.on(new ItemsAddedToPortfolioEvent(portfolioId, itemId, 100)); verify(orderBookViewRepository).getOne(itemId.getIdentifier()); verify(portfolioViewRepository).save(viewCaptor.capture()); PortfolioView result = viewCaptor.getValue(); assertEquals(portfolioId.getIdentifier(), result.getIdentifier()); assertEquals(userId.getIdentifier(), result.getUserId()); Map<String, ItemEntry> resultItemsInPossession = result.getItemsInPossession(); assertEquals(expectedNumberOfPossessedItems, resultItemsInPossession.size()); assertEquals(expectedAmountOfPossessedItems, resultItemsInPossession.get(itemId.getIdentifier()).getAmount()); Map<String, ItemEntry> resultItemsReserved = result.getItemsReserved(); assertEquals(expectedNumberOfReservedItems, resultItemsReserved.size()); assertEquals(expectedAmountOfReservedItems, resultItemsReserved.get(itemId.getIdentifier()).getAmount()); }
@EventHandler public void on(PortfolioCreatedEvent event) { PortfolioView portfolioView = new PortfolioView(); portfolioView.setIdentifier(event.getPortfolioId().getIdentifier()); portfolioView.setUserId(event.getUserId().getIdentifier()); portfolioView.setAmountOfMoney(0); portfolioView.setReservedAmountOfMoney(0); portfolioViewRepository.save(portfolioView); }
PortfolioEventHandler { @EventHandler public void on(PortfolioCreatedEvent event) { PortfolioView portfolioView = new PortfolioView(); portfolioView.setIdentifier(event.getPortfolioId().getIdentifier()); portfolioView.setUserId(event.getUserId().getIdentifier()); portfolioView.setAmountOfMoney(0); portfolioView.setReservedAmountOfMoney(0); portfolioViewRepository.save(portfolioView); } }
PortfolioEventHandler { @EventHandler public void on(PortfolioCreatedEvent event) { PortfolioView portfolioView = new PortfolioView(); portfolioView.setIdentifier(event.getPortfolioId().getIdentifier()); portfolioView.setUserId(event.getUserId().getIdentifier()); portfolioView.setAmountOfMoney(0); portfolioView.setReservedAmountOfMoney(0); portfolioViewRepository.save(portfolioView); } PortfolioEventHandler(PortfolioViewRepository portfolioViewRepository,
                                 OrderBookViewRepository orderBookViewRepository); }
PortfolioEventHandler { @EventHandler public void on(PortfolioCreatedEvent event) { PortfolioView portfolioView = new PortfolioView(); portfolioView.setIdentifier(event.getPortfolioId().getIdentifier()); portfolioView.setUserId(event.getUserId().getIdentifier()); portfolioView.setAmountOfMoney(0); portfolioView.setReservedAmountOfMoney(0); portfolioViewRepository.save(portfolioView); } PortfolioEventHandler(PortfolioViewRepository portfolioViewRepository,
                                 OrderBookViewRepository orderBookViewRepository); @EventHandler void on(PortfolioCreatedEvent event); @EventHandler void on(ItemsAddedToPortfolioEvent event); @EventHandler void on(ItemsReservedEvent event); @EventHandler void on(ItemReservationConfirmedForPortfolioEvent event); @EventHandler void on(ItemReservationCancelledForPortfolioEvent event); @EventHandler void on(CashDepositedEvent event); @EventHandler void on(CashWithdrawnEvent event); @EventHandler void on(CashReservedEvent event); @EventHandler void on(CashReservationCancelledEvent event); @EventHandler void on(CashReservationConfirmedEvent event); @QueryHandler PortfolioView find(PortfolioByIdQuery query); @QueryHandler PortfolioView find(PortfolioByUserIdQuery query); }
PortfolioEventHandler { @EventHandler public void on(PortfolioCreatedEvent event) { PortfolioView portfolioView = new PortfolioView(); portfolioView.setIdentifier(event.getPortfolioId().getIdentifier()); portfolioView.setUserId(event.getUserId().getIdentifier()); portfolioView.setAmountOfMoney(0); portfolioView.setReservedAmountOfMoney(0); portfolioViewRepository.save(portfolioView); } PortfolioEventHandler(PortfolioViewRepository portfolioViewRepository,
                                 OrderBookViewRepository orderBookViewRepository); @EventHandler void on(PortfolioCreatedEvent event); @EventHandler void on(ItemsAddedToPortfolioEvent event); @EventHandler void on(ItemsReservedEvent event); @EventHandler void on(ItemReservationConfirmedForPortfolioEvent event); @EventHandler void on(ItemReservationCancelledForPortfolioEvent event); @EventHandler void on(CashDepositedEvent event); @EventHandler void on(CashWithdrawnEvent event); @EventHandler void on(CashReservedEvent event); @EventHandler void on(CashReservationCancelledEvent event); @EventHandler void on(CashReservationConfirmedEvent event); @QueryHandler PortfolioView find(PortfolioByIdQuery query); @QueryHandler PortfolioView find(PortfolioByUserIdQuery query);  }