BiPredicateWithTracing implements BiPredicate<T, U> { public static <T, U> BiPredicateWithTracing<T, U> withTracing(BiPredicate<T, U> origBiPredicate) { return new BiPredicateWithTracing<>(origBiPredicate); } BiPredicateWithTracing(BiPredicate<T, U> origBiPredicate);  BiPredicateWithTracing(BiPredicate<T, U> origBiPredicate,
                                  Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  BiPredicateWithTracing(BiPredicate<T, U> origBiPredicate,
                                  Deque<Span> spanStackForExecution,
                                  Map<String, String> mdcContextMapForExecution); static BiPredicateWithTracing<T, U> withTracing(BiPredicate<T, U> origBiPredicate); static BiPredicateWithTracing<T, U> withTracing(
        BiPredicate<T, U> origBiPredicate,
        Pair<Deque<Span>, Map<String, String>> originalThreadInfo
    ); static BiPredicateWithTracing<T, U> withTracing(BiPredicate<T, U> origBiPredicate,
                                                                  Deque<Span> spanStackForExecution,
                                                                  Map<String, String> mdcContextMapForExecution); @Override boolean test(T t, U u);  }
@DataProvider(value = { "true", "false" }) @Test public void current_thread_info_constructor_sets_fields_as_expected(boolean useStaticFactory) { Tracer.getInstance().startRequestWithRootSpan("request-" + UUID.randomUUID().toString()); Deque<Span> spanStackMock = Tracer.getInstance().getCurrentSpanStackCopy(); Map<String, String> mdcInfoMock = MDC.getCopyOfContextMap(); BiPredicateWithTracing instance = (useStaticFactory) ? withTracing(biPredicateMock) : new BiPredicateWithTracing(biPredicateMock); assertThat(instance.origBiPredicate).isSameAs(biPredicateMock); assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock); assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock); }
@DataProvider(value = { "true | true | true", "true | false | true", "false | true | true", "false | false | true", "true | true | false", "true | false | false", "false | true | false", "false | false | false", }, splitBy = "\\|") @Test public void pair_constructor_sets_fields_as_expected( boolean nullSpanStack, boolean nullMdcInfo, boolean useStaticFactory ) { Deque<Span> spanStackMock = (nullSpanStack) ? null : mock(Deque.class); Map<String, String> mdcInfoMock = (nullMdcInfo) ? null : mock(Map.class); BiPredicateWithTracing instance = (useStaticFactory) ? withTracing(biPredicateMock, Pair.of(spanStackMock, mdcInfoMock)) : new BiPredicateWithTracing(biPredicateMock, Pair.of(spanStackMock, mdcInfoMock) ); assertThat(instance.origBiPredicate).isSameAs(biPredicateMock); assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock); assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock); }
@DataProvider(value = { "true", "false" }) @Test public void pair_constructor_sets_fields_as_expected_when_pair_is_null(boolean useStaticFactory) { BiPredicateWithTracing instance = (useStaticFactory) ? withTracing(biPredicateMock, (Pair)null) : new BiPredicateWithTracing(biPredicateMock, (Pair)null); assertThat(instance.origBiPredicate).isSameAs(biPredicateMock); assertThat(instance.spanStackForExecution).isNull(); assertThat(instance.mdcContextMapForExecution).isNull(); }
@DataProvider(value = { "true", "false" }) @Test public void kitchen_sink_constructor_sets_fields_as_expected(boolean useStaticFactory) { Deque<Span> spanStackMock = mock(Deque.class); Map<String, String> mdcInfoMock = mock(Map.class); BiPredicateWithTracing instance = (useStaticFactory) ? withTracing(biPredicateMock, spanStackMock, mdcInfoMock) : new BiPredicateWithTracing(biPredicateMock, spanStackMock, mdcInfoMock); assertThat(instance.origBiPredicate).isSameAs(biPredicateMock); assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock); assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock); }
@Test public void constructors_throw_exception_if_passed_null_operator() { final Deque<Span> spanStackMock = mock(Deque.class); final Map<String, String> mdcInfoMock = mock(Map.class); assertThat(catchThrowable(() -> new BiPredicateWithTracing(null))) .isInstanceOf(IllegalArgumentException.class); assertThat(catchThrowable(() -> withTracing(null))) .isInstanceOf(IllegalArgumentException.class); assertThat(catchThrowable(() -> new BiPredicateWithTracing(null, Pair.of(spanStackMock, mdcInfoMock)))) .isInstanceOf(IllegalArgumentException.class); assertThat(catchThrowable(() -> withTracing(null, Pair.of(spanStackMock, mdcInfoMock)))) .isInstanceOf(IllegalArgumentException.class); assertThat(catchThrowable(() -> new BiPredicateWithTracing(null, spanStackMock, mdcInfoMock))) .isInstanceOf(IllegalArgumentException.class); assertThat(catchThrowable(() -> withTracing(null, spanStackMock, mdcInfoMock))) .isInstanceOf(IllegalArgumentException.class); }