@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(); consumerMock = mock(BiConsumer.class); inObj1 = new Object(); inObj2 = new Object(); throwExceptionDuringCall = false; currentSpanStackWhenBiConsumerWasCalled = new ArrayList<>(); currentMdcInfoWhenBiConsumerWasCalled = new ArrayList<>(); doAnswer(invocation -> { currentSpanStackWhenBiConsumerWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy()); currentMdcInfoWhenBiConsumerWasCalled.add(MDC.getCopyOfContextMap()); if (throwExceptionDuringCall) throw new RuntimeException("kaboom"); return null; }).when(consumerMock).accept(inObj1, inObj2); resetTracingAndMdc(); }
consumerMock, spanStack, mdcInfo ); resetTracingAndMdc(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isEmpty();