AccountEventHandlers { public DomainEventHandlers domainEventHandlers() { return DomainEventHandlersBuilder .forAggregateType("net.chrisrichardson.bankingexample.customerservice.backend.Customer") .onEvent(CustomerValidatedEvent.class, this::handleCustomerValidatedEvent) .onEvent(CustomerValidationFailedEvent.class, this::handleCustomerValidationFailedEvent) .build(); } AccountEventHandlers(AccountService accountService); DomainEventHandlers domainEventHandlers();  }
@Test public void shouldHandleCustomerValidatedEvent() { given(). eventHandlers(accountEventHandlers.domainEventHandlers()). when(). aggregate("net.chrisrichardson.bankingexample.customerservice.backend.Customer", customerId). publishes(new CustomerValidatedEvent(accountId)). then(). verify(() -> { verify(accountService).noteCustomerValidated(accountId); }) ; }
@Test public void shouldHandleCustomerValidationFailedEvent() { given(). eventHandlers(accountEventHandlers.domainEventHandlers()). when(). aggregate("net.chrisrichardson.bankingexample.customerservice.backend.Customer", customerId). publishes(new CustomerValidationFailedEvent(accountId)). then(). verify(() -> { verify(accountService).noteCustomerValidationFailed(accountId); }) ; }