### Question:
HandlerRegistry { public <T> HandlerRegistry listenEvent(String eventName, EventHandler<T> fn, Class<T> eventClass){ eventListeners.add(new RegisteredEventListener<>(eventName, fn, eventClass)); return this; }  static HandlerRegistry register(); HandlerRegistry listenEvent(String eventName, EventHandler<T> fn, Class<T> eventClass); HandlerRegistry listenEvent(String eventName, EventHandler<T> handler); HandlerRegistry listenNotificationEvent(String eventName, EventHandler<T> fn, Class<T> eventClass); HandlerRegistry handleCommand(String commandName, CommandHandler<T> fn, Class<T> commandClass); HandlerRegistry handleCommand(String commandName, CommandHandler<T> fn); HandlerRegistry serveQuery(String resource, QueryHandler<T, R> handler); HandlerRegistry serveQuery(String resource, QueryHandler<T, R> handler, Class<R> queryClass);  }### Answer:
@Test public void shouldListenEventWithTypeInferenceWhenClassInstanceIsUsed(){ SomeEventHandler eventHandler = new SomeEventHandler(); registry.listenEvent(name, eventHandler); assertThat(registry.getEventListeners()).anySatisfy(registered -> { assertThat(registered).extracting(RegisteredEventListener::getPath, RegisteredEventListener::getInputClass, RegisteredEventListener::getHandler) .containsExactly(name, SomeDataClass.class, eventHandler); }).hasSize(1); }
@Test @SuppressWarnings("unchecked") public void listenEvent() { EventHandler<SomeDataClass> handler = mock(EventHandler.class); registry.listenEvent(name, handler, SomeDataClass.class); assertThat(registry.getEventListeners()).anySatisfy(registered -> { assertThat(registered).extracting(RegisteredEventListener::getPath, RegisteredEventListener::getInputClass, RegisteredEventListener::getHandler) .containsExactly(name, SomeDataClass.class, handler); }).hasSize(1); }
@Test(expected = RuntimeException.class) public void listenEventWithoutTypeShouldFail() { registry.listenEvent(name, (DomainEvent<SomeDataClass> message) -> Mono.empty()); }