ErrorListener implements ApplicationListener<ErrorEvent> { @Override public void onApplicationEvent(ErrorEvent event) { errorMessageConsumer.consumeMessage(ErrorMessage.of(UUID.randomUUID().toString(), event.message)); } ErrorListener(ErrorMessageConsumer errorMessageConsumer); @Override void onApplicationEvent(ErrorEvent event);  }
@Test void should_pass_error_message_to_consumer(@Mock ErrorMessageConsumer errorMessageConsumer) { String text = "error"; ErrorListener errorListener = new ErrorListener(errorMessageConsumer); errorListener.onApplicationEvent(new ErrorEvent(this, text)); verify(errorMessageConsumer).consumeMessage(argumentCaptor.capture()); ErrorMessage capturedMessage = argumentCaptor.getValue(); assertThat(capturedMessage.text).isEqualTo(text); assertThat(capturedMessage.id).isNotNull(); }