@After public void afterMethod() { resetTracingAndMdc(); }
@Before public void beforeMethod() { channelMock = mock(Channel.class); ctxMock = mock(ChannelHandlerContext.class); stateAttributeMock = mock(Attribute.class); state = new HttpProcessingState(); doReturn(channelMock).when(ctxMock).channel(); doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY); doReturn(state).when(stateAttributeMock).get(); supplierMock = mock(Supplier.class); outObj = new Object(); throwExceptionDuringCall = false; currentSpanStackWhenSupplierWasCalled = new ArrayList<>(); currentMdcInfoWhenSupplierWasCalled = new ArrayList<>(); doAnswer(invocation -> { currentSpanStackWhenSupplierWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy()); currentMdcInfoWhenSupplierWasCalled.add(MDC.getCopyOfContextMap()); if (throwExceptionDuringCall) throw new RuntimeException("kaboom"); return outObj; }).when(supplierMock).get(); resetTracingAndMdc(); }
supplierMock, spanStack, mdcInfo ); resetTracingAndMdc(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isEmpty();