### Question:
TracingQueryGateway implements QueryGateway { @Override public <R, Q> Stream<R> scatterGather(String queryName, Q query, ResponseType<R> responseType, long timeout, TimeUnit timeUnit) { Message<?> queryMessage = GenericMessage.asMessage(query); return getWithSpan( "scatterGather_" + SpanUtils.messageName(query.getClass(), queryName), queryMessage, queryName, (childSpan) -> delegate.scatterGather(queryName, queryMessage, responseType, timeout, timeUnit) .onClose(() -> { childSpan.log("resultReceived"); childSpan.finish(); }) ); } protected  TracingQueryGateway(Builder builder); static Builder builder(); @Override CompletableFuture<R> query(String queryName, Q query, ResponseType<R> responseType); @Override Stream<R> scatterGather(String queryName,
                                          Q query,
                                          ResponseType<R> responseType,
                                          long timeout,
                                          TimeUnit timeUnit); @Override SubscriptionQueryResult<I, U> subscriptionQuery(String queryName,
                                                                     Q query,
                                                                     ResponseType<I> initialResponseType,
                                                                     ResponseType<U> updateResponseType,
                                                                     SubscriptionQueryBackpressure backpressure,
                                                                     int updateBufferSize); @Override Registration registerDispatchInterceptor(
            MessageDispatchInterceptor<? super QueryMessage<?, ?>> dispatchInterceptor);  }### Answer:
@Test void testScatterGather() { when(mockQueryBus.scatterGather(any(QueryMessage.class), anyLong(), any())) .thenReturn(Stream.of(answer1, answer2)); MockSpan span = mockTracer.buildSpan("testScatterGather").start(); ScopeManager scopeManager = mockTracer.scopeManager(); try (final Scope ignored = scopeManager.activate(span)) { try (Stream<String> actual = testSubject.scatterGather("query", "Query", ResponseTypes.instanceOf(String.class), 1L, TimeUnit.MILLISECONDS)) { Iterator<String> iterator = actual.iterator(); String firstResult = iterator.next(); assertEquals("answer1", firstResult); String secondResult = iterator.next(); assertEquals("answer2", secondResult); } Span activeSpan = mockTracer.activeSpan(); assertEquals(span, activeSpan); List<MockSpan> mockSpans = mockTracer.finishedSpans(); assertEquals(1, mockSpans.size()); assertEquals("scatterGather_query", 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"); }