### Question:
HandlerRegistry { public <T, R> HandlerRegistry serveQuery(String resource, QueryHandler<T, R> handler){ return serveQuery(resource, handler, inferGenericParameterType(handler)); }  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(expected = RuntimeException.class) public void handleQueryWithoutTypeShouldFail() { registry.serveQuery(name, (SomeDataClass query) -> Mono.empty()); }
@Test public void serveQueryWithLambda() { registry.serveQuery(name, message -> Mono.empty(), SomeDataClass.class); assertThat(registry.getHandlers()).anySatisfy(registered -> { assertThat(registered).extracting(RegisteredQueryHandler::getPath, RegisteredQueryHandler::getQueryClass) .containsExactly(name, SomeDataClass.class); }).hasSize(1); }
@Test public void serveQueryWithTypeInference() { QueryHandler<SomeDataClass, SomeDataClass> handler = new SomeQueryHandler(); registry.serveQuery(name, handler); assertThat(registry.getHandlers()).anySatisfy(registered -> { assertThat(registered).extracting(RegisteredQueryHandler::getPath, RegisteredQueryHandler::getQueryClass, RegisteredQueryHandler::getHandler) .containsExactly(name, SomeDataClass.class, handler); }).hasSize(1); }