Skip to content

Commit be64d5e

Browse files
committed
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. See gh-39912 (cherry picked from commit 9c054a0)
1 parent f324994 commit be64d5e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,29 @@ void injectsExpectedBeans() {
283283
}
284284

285285
@Test
286-
void whenHasUseDefinedProducerInterceptorInjectsBean() {
286+
<T> void whenHasUseDefinedProducerInterceptorInjectsBean() {
287287
ProducerInterceptor interceptor = mock(ProducerInterceptor.class);
288288
this.contextRunner.withBean("customProducerInterceptor", ProducerInterceptor.class, () -> interceptor)
289-
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
290-
.extracting("interceptors")
291-
.asList()
292-
.contains(interceptor));
289+
.run((context) -> {
290+
PulsarTemplate<?> pulsarTemplate = context.getBean(PulsarTemplate.class);
291+
Customizers<ProducerBuilderCustomizer<T>, ProducerBuilder<T>> customizers = Customizers
292+
.of(ProducerBuilder.class, ProducerBuilderCustomizer::customize);
293+
assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers"))
294+
.callsInOrder(ProducerBuilder::intercept, interceptor);
295+
});
293296
}
294297

295298
@Test
296-
void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() {
297-
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class)
298-
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
299-
.extracting("interceptors")
300-
.asList()
301-
.containsExactly(context.getBean("interceptorBar"), context.getBean("interceptorFoo")));
299+
<T> void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() {
300+
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class).run((context) -> {
301+
ProducerInterceptor interceptorFoo = context.getBean("interceptorFoo", ProducerInterceptor.class);
302+
ProducerInterceptor interceptorBar = context.getBean("interceptorBar", ProducerInterceptor.class);
303+
PulsarTemplate<?> pulsarTemplate = context.getBean(PulsarTemplate.class);
304+
Customizers<ProducerBuilderCustomizer<T>, ProducerBuilder<T>> customizers = Customizers
305+
.of(ProducerBuilder.class, ProducerBuilderCustomizer::customize);
306+
assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers"))
307+
.callsInOrder(ProducerBuilder::intercept, interceptorBar, interceptorFoo);
308+
});
302309
}
303310

304311
@Test

0 commit comments

Comments
 (0)