SupplierWithTracing implements Supplier<U> { @Override public U get() { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); return origSupplier.get(); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } SupplierWithTracing(Supplier<U> origSupplier);  SupplierWithTracing(Supplier<U> origSupplier,
                               Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  SupplierWithTracing(Supplier<U> origSupplier,
                               Deque<Span> spanStackForExecution,
                               Map<String, String> mdcContextMapForExecution); static SupplierWithTracing<U> withTracing(Supplier<U> origSupplier); static SupplierWithTracing<U> withTracing(Supplier<U> origSupplier,
                                                         Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static SupplierWithTracing<U> withTracing(Supplier<U> origSupplier,
                                                         Deque<Span> spanStackForExecution,
                                                         Map<String, String> mdcContextMapForExecution); @Override U get();  }
@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(); SupplierWithTracing instance = new SupplierWithTracing( supplierMock, spanStack, mdcInfo ); resetTracing(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); Throwable ex = null; Object result = null; try { result = instance.get(); } catch(Throwable t) { ex = t; } verify(supplierMock).get(); if (throwException) { assertThat(ex).isNotNull(); assertThat(result).isNull(); } else { assertThat(ex).isNull(); assertThat(result).isSameAs(outObj); } assertThat(currentSpanStackWhenSupplierWasCalled.get(0)).isEqualTo(spanStack); assertThat(currentMdcInfoWhenSupplierWasCalled.get(0)).isEqualTo(mdcInfo); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); }