@SuppressWarnings("unchecked") @Test void testSendAndWaitWithTimeoutNullOnInterrupt() { doAnswer(invocation -> { Thread.currentThread().interrupt(); return null; }).when(mockCommandBus).dispatch(isA(CommandMessage.class), isA(CommandCallback.class)); try { testSubject.sendAndWait("Hello", 60, TimeUnit.SECONDS); testSubject.sendAndWait("Hello", 60, TimeUnit.SECONDS); fail("Expected interrupted exception"); } catch (CommandExecutionException e) { assertTrue(e.getCause() instanceof InterruptedException); } assertTrue(Thread.interrupted(), "Interrupt flag should be set on thread"); verify(mockCommandBus).dispatch(isA(CommandMessage.class), isA(CommandCallback.class)); }
@Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); }
DefaultCommandGateway extends AbstractCommandGateway implements CommandGateway { @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); } }
DefaultCommandGateway extends AbstractCommandGateway implements CommandGateway { @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); } protected  DefaultCommandGateway(Builder builder); }
DefaultCommandGateway extends AbstractCommandGateway implements CommandGateway { @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); } protected  DefaultCommandGateway(Builder builder); static Builder builder(); @Override void send(C command, CommandCallback<? super C, ? super R> callback); @Override @SuppressWarnings("unchecked") R sendAndWait(Object command); @Override @SuppressWarnings("unchecked") R sendAndWait(Object command, long timeout, TimeUnit unit); @Override CompletableFuture<R> send(Object command); @Override Registration registerDispatchInterceptor(
            MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor); }
DefaultCommandGateway extends AbstractCommandGateway implements CommandGateway { @Override @SuppressWarnings("unchecked") public <R> R sendAndWait(Object command) { FutureCallback<Object, R> futureCallback = new FutureCallback<>(); send(command, futureCallback); CommandResultMessage<? extends R> commandResultMessage = futureCallback.getResult(); if (commandResultMessage.isExceptional()) { throw asRuntime(commandResultMessage.exceptionResult()); } return commandResultMessage.getPayload(); } protected  DefaultCommandGateway(Builder builder); static Builder builder(); @Override void send(C command, CommandCallback<? super C, ? super R> callback); @Override @SuppressWarnings("unchecked") R sendAndWait(Object command); @Override @SuppressWarnings("unchecked") R sendAndWait(Object command, long timeout, TimeUnit unit); @Override CompletableFuture<R> send(Object command); @Override Registration registerDispatchInterceptor(
            MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor);  }