From ac0d1e0ec65147ee60bfc9d3ae56363c6fceb91d Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 12 Mar 2024 12:09:46 -0500 Subject: [PATCH] Re-enable Spring Pulsar interceptor tests The PulsarTemplate recently replaced its list of ProducerInterceptors with a list of ProducerBuilderCustomizers that customize the builder by adding each interceptor to the builder. The PulsarAutoConfigurationTests previosuly relied on the previous field. This commit adjusts the tests to instead use the Customizers testing utility to verify the interceptors. (cherry picked from commit 9c054a021fc34728a68a835a5c2e421f3e11df9f) See gh-39946 --- .../pulsar/PulsarAutoConfigurationTests.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java index dd8cd2428a9..318554a4ae3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java @@ -283,22 +283,29 @@ class PulsarAutoConfigurationTests { } @Test - void whenHasUseDefinedProducerInterceptorInjectsBean() { + void whenHasUseDefinedProducerInterceptorInjectsBean() { ProducerInterceptor interceptor = mock(ProducerInterceptor.class); this.contextRunner.withBean("customProducerInterceptor", ProducerInterceptor.class, () -> interceptor) - .run((context) -> assertThat(context).getBean(PulsarTemplate.class) - .extracting("interceptors") - .asList() - .contains(interceptor)); + .run((context) -> { + PulsarTemplate pulsarTemplate = context.getBean(PulsarTemplate.class); + Customizers, ProducerBuilder> customizers = Customizers + .of(ProducerBuilder.class, ProducerBuilderCustomizer::customize); + assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers")) + .callsInOrder(ProducerBuilder::intercept, interceptor); + }); } @Test - void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() { - this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class) - .run((context) -> assertThat(context).getBean(PulsarTemplate.class) - .extracting("interceptors") - .asList() - .containsExactly(context.getBean("interceptorBar"), context.getBean("interceptorFoo"))); + void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() { + this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class).run((context) -> { + ProducerInterceptor interceptorFoo = context.getBean("interceptorFoo", ProducerInterceptor.class); + ProducerInterceptor interceptorBar = context.getBean("interceptorBar", ProducerInterceptor.class); + PulsarTemplate pulsarTemplate = context.getBean(PulsarTemplate.class); + Customizers, ProducerBuilder> customizers = Customizers + .of(ProducerBuilder.class, ProducerBuilderCustomizer::customize); + assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers")) + .callsInOrder(ProducerBuilder::intercept, interceptorBar, interceptorFoo); + }); } @Test