BiConsumerWithTracing implements BiConsumer<T, U> { @Override public void accept(T t, U u) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origBiConsumer.accept(t, u); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } BiConsumerWithTracing(BiConsumer<T, U> origBiConsumer);  BiConsumerWithTracing(BiConsumer<T, U> origBiConsumer,
                                 Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  BiConsumerWithTracing(BiConsumer<T, U> origBiConsumer,
                                 Deque<Span> spanStackForExecution,
                                 Map<String, String> mdcContextMapForExecution); static BiConsumerWithTracing<T, U> withTracing(BiConsumer<T, U> origBiConsumer); static BiConsumerWithTracing<T, U> withTracing(
        BiConsumer<T, U> origBiConsumer,
        Pair<Deque<Span>, Map<String, String>> originalThreadInfo
    ); static BiConsumerWithTracing<T, U> withTracing(BiConsumer<T, U> origBiConsumer,
                                                                 Deque<Span> spanStackForExecution,
                                                                 Map<String, String> mdcContextMapForExecution); @Override void accept(T t, U u);  }
@DataProvider(value = { "true", "false" }) @Test public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) { throwExceptionDuringCall = throwException; Tracer.getInstance().startRequestWithRootSpan("foo"); Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy(); Map<String, String> mdcInfo = MDC.getCopyOfContextMap(); BiConsumerWithTracing instance = new BiConsumerWithTracing( biConsumerMock, spanStack, mdcInfo ); resetTracing(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); Throwable ex = catchThrowable(() -> instance.accept(inObj1, inObj2)); verify(biConsumerMock).accept(inObj1, inObj2); if (throwException) { assertThat(ex).isNotNull(); } else { assertThat(ex).isNull(); } assertThat(currentSpanStackWhenBiConsumerWasCalled.get(0)).isEqualTo(spanStack); assertThat(currentMdcInfoWhenBiConsumerWasCalled.get(0)).isEqualTo(mdcInfo); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); }