CompanyEventHandler { @EventHandler public void on(CompanyCreatedEvent event) { CompanyView companyView = new CompanyView(); companyView.setIdentifier(event.getCompanyId().getIdentifier()); companyView.setValue(event.getCompanyValue()); companyView.setAmountOfShares(event.getAmountOfShares()); companyView.setTradeStarted(true); companyView.setName(event.getCompanyName()); companyRepository.save(companyView); } @Autowired  CompanyEventHandler(CompanyViewRepository companyRepository); @EventHandler void on(CompanyCreatedEvent event);  }
@Test public void testOnCompanyCreatedEventACompanyViewIsSaved() { CompanyId expectedCompanyId = new CompanyId(); String expectedCompanyName = "companyName"; int expectedCompanyValue = 1000; int expectedAmountOfShares = 500; CompanyCreatedEvent testEvent = new CompanyCreatedEvent( expectedCompanyId, expectedCompanyName, expectedCompanyValue, expectedAmountOfShares ); testSubject.on(testEvent); ArgumentCaptor<CompanyView> companyViewCaptor = ArgumentCaptor.forClass(CompanyView.class); verify(companyViewRepository).save(companyViewCaptor.capture()); CompanyView result = companyViewCaptor.getValue(); assertNotNull(result); assertEquals(expectedCompanyId.getIdentifier(), result.getIdentifier()); assertEquals(expectedCompanyName, result.getName()); assertEquals(expectedCompanyValue, result.getValue()); assertEquals(expectedAmountOfShares, result.getAmountOfShares()); }