### Question:
TracingCommandGateway implements CommandGateway { @Override public <R> R sendAndWait(Object command) { return doSendAndExtract(command, FutureCallback::getResult); } protected  TracingCommandGateway(Builder builder); static Builder builder(); @Override void send(C command, CommandCallback<? super C, ? super R> callback); @Override R sendAndWait(Object command); @Override R sendAndWait(Object command, long timeout, TimeUnit unit); @Override CompletableFuture<R> send(Object command); @Override Registration registerDispatchInterceptor(
            MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor);  }### Answer:
@Test void testSendAndWait() { MockSpan span = mockTracer.buildSpan("test").start(); ScopeManager scopeManager = mockTracer.scopeManager(); try (final Scope ignored = scopeManager.activate(span)) { Object result = testSubject.sendAndWait(new MyCommand()); verify(mockCommandBus, times(1)) .dispatch(isA(CommandMessage.class), isA(CommandCallback.class)); assertTrue(result instanceof String); assertEquals("result", result); Span activeSpan = mockTracer.activeSpan(); assertEquals(span, activeSpan); List<MockSpan> mockSpans = mockTracer.finishedSpans(); assertEquals(1, mockSpans.size()); assertEquals("sendAndWait_MyCommand", mockSpans.get(0).operationName()); assertNotNull(mockSpans.get(0).logEntries()); assertFalse(mockSpans.get(0).logEntries().isEmpty()); assertNotNull(mockSpans.get(0).tags()); assertFalse(mockSpans.get(0).tags().isEmpty()); } assertNull(scopeManager.activeSpan(), "There should be no activeSpan"); }
@Test void testSendAndWaitWithTimeout() { MockSpan span = mockTracer.buildSpan("test").start(); ScopeManager scopeManager = mockTracer.scopeManager(); try (final Scope ignored = scopeManager.activate(span)) { Object result = testSubject.sendAndWait(new MyCommand(), 10, TimeUnit.MILLISECONDS); verify(mockCommandBus, times(1)) .dispatch(isA(CommandMessage.class), isA(CommandCallback.class)); assertTrue(result instanceof String); assertEquals("result", result); Span activeSpan = mockTracer.activeSpan(); assertEquals(span, activeSpan); List<MockSpan> mockSpans = mockTracer.finishedSpans(); assertEquals(1, mockSpans.size()); assertEquals("sendAndWait_MyCommand", mockSpans.get(0).operationName()); assertNotNull(mockSpans.get(0).logEntries()); assertFalse(mockSpans.get(0).logEntries().isEmpty()); assertNotNull(mockSpans.get(0).tags()); assertFalse(mockSpans.get(0).tags().isEmpty()); } assertNull(scopeManager.activeSpan(), "There should be no activeSpan"); }