### Question:
WebClientBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof WebClient) { WebClient webClient = (WebClient) bean; return wrapBuilder(webClient.mutate()).build(); } else if (bean instanceof WebClient.Builder) { WebClient.Builder webClientBuilder = (WebClient.Builder) bean; return wrapBuilder(webClientBuilder); } return bean; } WebClientBeanPostProcessor(Tracer tracer); @Override Object postProcessAfterInitialization(Object bean, String beanName);  }### Answer:
@Test @DisplayName( "when processed bean is NOT of type WebClient or WebClientBuilder should return Object") void returnsObject() { assertThat( webClientBeanPostProcessor.postProcessAfterInitialization(new Object(), "testObject")) .isExactlyInstanceOf(Object.class); }
@Test @DisplayName("when processed bean is of type WebClient should return WebClient") void returnsWebClient() { assertThat( webClientBeanPostProcessor.postProcessAfterInitialization( WebClient.create(), "testWebClient")) .isInstanceOf(WebClient.class); }
@Test @DisplayName("when processed bean is of type WebClientBuilder should return WebClientBuilder") void returnsWebClientBuilder() { assertThat( webClientBeanPostProcessor.postProcessAfterInitialization( WebClient.builder(), "testWebClientBuilder")) .isInstanceOf(WebClient.Builder.class); }
@Test @DisplayName("when processed bean is of type WebClient should add exchange filter to WebClient") void addsExchangeFilterWebClient() { WebClient webClient = WebClient.create(); Object processedWebClient = webClientBeanPostProcessor.postProcessAfterInitialization(webClient, "testWebClient"); assertThat(processedWebClient).isInstanceOf(WebClient.class); ((WebClient) processedWebClient) .mutate() .filters( functions -> { assertThat( functions.stream() .filter(wctf -> wctf instanceof WebClientTracingFilter) .count()) .isEqualTo(1); }); }
@Test @DisplayName( "when processed bean is of type WebClientBuilder should add ONE exchange filter to WebClientBuilder") void addsExchangeFilterWebClientBuilder() { WebClient.Builder webClientBuilder = WebClient.builder(); webClientBeanPostProcessor.postProcessAfterInitialization( webClientBuilder, "testWebClientBuilder"); webClientBeanPostProcessor.postProcessAfterInitialization( webClientBuilder, "testWebClientBuilder"); webClientBeanPostProcessor.postProcessAfterInitialization( webClientBuilder, "testWebClientBuilder"); webClientBuilder.filters( functions -> { assertThat( functions.stream().filter(wctf -> wctf instanceof WebClientTracingFilter).count()) .isEqualTo(1); }); }