UserEventHandler { @EventHandler public void on(UserCreatedEvent event) { UserView userView = new UserView(); userView.setIdentifier(event.getUserId().getIdentifier()); userView.setName(event.getName()); userView.setUsername(event.getUsername()); userView.setPassword(event.getPassword()); userRepository.save(userView); } @Autowired  UserEventHandler(UserViewRepository userRepository); @EventHandler void on(UserCreatedEvent event);  }
@Test public void testOnUserCreatedEventAnUserViewIsSaved() { UserId expectedUserId = new UserId(); String expectedName = "name"; String expectedUserName = "userName"; UserCreatedEvent testEvent = new UserCreatedEvent(expectedUserId, expectedName, expectedUserName, "password"); testSubject.on(testEvent); ArgumentCaptor<UserView> userViewCaptor = ArgumentCaptor.forClass(UserView.class); verify(userViewRepository).save(userViewCaptor.capture()); UserView result = userViewCaptor.getValue(); assertNotNull(result); assertEquals(expectedUserId.getIdentifier(), result.getUserId()); assertEquals(expectedName, result.getName()); assertEquals(expectedUserName, result.getUserName()); }