### Question:
OpenTraceDispatchInterceptor implements MessageDispatchInterceptor<Message<?>> { @Override public BiFunction<Integer, Message<?>, Message<?>> handle(List<? extends Message<?>> messages) { ScopeManager scopeManager = tracer.scopeManager(); Optional<SpanContext> spanContextOptional = Optional.ofNullable(scopeManager) .map(ScopeManager::activeSpan) .map(Span::context); return spanContextOptional.<BiFunction<Integer, Message<?>, Message<?>>>map(spanContext -> (index, message) -> { MapInjector injector = new MapInjector(); tracer.inject(spanContext, Format.Builtin.TEXT_MAP, injector); return message.andMetaData(injector.getMetaData()); }).orElseGet(() -> (i, m) -> m); } OpenTraceDispatchInterceptor(Tracer tracer); @Override BiFunction<Integer, Message<?>, Message<?>> handle(List<? extends Message<?>> messages);  }### Answer:
@Test void testDispatch() { MockSpan span = mockTracer.buildSpan("test").start(); ScopeManager scopeManager = mockTracer.scopeManager(); try (final Scope ignored = scopeManager.activate(span)) { GenericMessage<String> msg = new GenericMessage<>("Payload"); BiFunction<Integer, Message<?>, Message<?>> handle = openTraceDispatchInterceptor.handle(Collections.singletonList(msg)); List<MockSpan> mockSpans = mockTracer.finishedSpans(); assertTrue(mockSpans.isEmpty()); Message<?> apply = handle.apply(0, msg); MetaData metaData = apply.getMetaData(); assertEquals(2, metaData.size()); assertEquals(String.valueOf(span.context().spanId()), metaData.get("spanid")); assertEquals(String.valueOf(span.context().traceId()), metaData.get("traceid")); } }