DefaultSendRequestContext implements ConversationContext.SendRequestContext<T> { @Override public ConversationContext.SendRequestContext<T> expectResponse(Class<T> clazz, Duration timeout) { this.timeout = timeout; if (expectClazz != null) { throw new ConversationContext.PlcWiringException("can't expect class of type " + clazz + " as we already expecting clazz of type " + expectClazz); } expectClazz = clazz; commands.addLast(Either.right(clazz::isInstance)); return this; } DefaultSendRequestContext(Consumer<HandlerRegistration> finisher, T request, ConversationContext<T> context); protected  DefaultSendRequestContext(Deque<Either<Function<?, ?>, Predicate<?>>> commands, Duration timeout, Consumer<HandlerRegistration> finisher, Object request, ConversationContext<?> context, Class<?> expectClazz, Consumer<?> packetConsumer, Consumer<TimeoutException> onTimeoutConsumer, BiConsumer<?, ? extends Throwable> errorConsumer); @Override ConversationContext.SendRequestContext<T> expectResponse(Class<T> clazz, Duration timeout); @Override ConversationContext.SendRequestContext<T> check(Predicate<T> checker); @Override DefaultContextHandler handle(Consumer<T> packetConsumer); @Override ConversationContext.SendRequestContext<T> onTimeout(Consumer<TimeoutException> onTimeoutConsumer); @Override ConversationContext.SendRequestContext<T> onError(BiConsumer<T, E> errorConsumer); @Override ConversationContext.SendRequestContext<R> unwrap(Function<T, R> unwrapper); @Override ConversationContext.SendRequestContext<R> only(Class<R> clazz);  }
@Test void expectResponse() { SUT.expectResponse(Object.class, Duration.ZERO); assertThat(SUT.expectClazz, is(Object.class)); assertThat(SUT.commands, hasSize(1)); assertThat(SUT.commands.getLast().get(), notNullValue()); assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.expectResponse(Object.class, Duration.ZERO)); }