|
64 | 64 | import org.springframework.boot.test.system.OutputCaptureExtension;
|
65 | 65 | import org.springframework.context.annotation.Bean;
|
66 | 66 | import org.springframework.context.annotation.Configuration;
|
| 67 | +import org.springframework.context.annotation.Import; |
67 | 68 | import org.springframework.context.annotation.Primary;
|
68 | 69 | import org.springframework.core.Ordered;
|
69 | 70 | import org.springframework.core.annotation.Order;
|
|
78 | 79 |
|
79 | 80 | import static org.assertj.core.api.Assertions.assertThat;
|
80 | 81 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
| 82 | +import static org.mockito.ArgumentMatchers.any; |
81 | 83 | import static org.mockito.ArgumentMatchers.anyString;
|
82 | 84 | import static org.mockito.ArgumentMatchers.eq;
|
83 | 85 | import static org.mockito.ArgumentMatchers.isNull;
|
@@ -854,17 +856,20 @@ void whenMultipleConnectionFactoryCustomizersAreDefinedThenTheyAreCalledInOrder(
|
854 | 856 | }
|
855 | 857 |
|
856 | 858 | @Test
|
857 |
| - void simpleContainerCustomizer() { |
858 |
| - this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class).run( |
859 |
| - (context) -> assertThat(context.getBean(SimpleContainerCustomizerConfiguration.class).customizerCalled) |
860 |
| - .isTrue()); |
| 859 | + @SuppressWarnings("unchecked") |
| 860 | + void whenASimpleContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() { |
| 861 | + this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class) |
| 862 | + .run((context) -> verify(context.getBean(ContainerCustomizer.class)) |
| 863 | + .configure(any(SimpleMessageListenerContainer.class))); |
861 | 864 | }
|
862 | 865 |
|
863 | 866 | @Test
|
864 |
| - void directContainerCustomizer() { |
| 867 | + @SuppressWarnings("unchecked") |
| 868 | + void whenADirectContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() { |
865 | 869 | this.contextRunner.withUserConfiguration(DirectContainerCustomizerConfiguration.class)
|
866 |
| - .withPropertyValues("spring.rabbitmq.listener.type:direct").run((context) -> assertThat( |
867 |
| - context.getBean(DirectContainerCustomizerConfiguration.class).customizerCalled).isTrue()); |
| 870 | + .withPropertyValues("spring.rabbitmq.listener.type:direct") |
| 871 | + .run((context) -> verify(context.getBean(ContainerCustomizer.class)) |
| 872 | + .configure(any(DirectMessageListenerContainer.class))); |
868 | 873 | }
|
869 | 874 |
|
870 | 875 | private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(AssertableApplicationContext context) {
|
@@ -1131,36 +1136,36 @@ ConnectionFactoryCustomizer firstCustomizer() {
|
1131 | 1136 |
|
1132 | 1137 | }
|
1133 | 1138 |
|
| 1139 | + @Import(TestListener.class) |
1134 | 1140 | @Configuration(proxyBeanMethods = false)
|
1135 | 1141 | static class SimpleContainerCustomizerConfiguration {
|
1136 | 1142 |
|
1137 |
| - boolean customizerCalled; |
1138 |
| - |
1139 |
| - @RabbitListener(queues = "test", autoStartup = "false") |
1140 |
| - void listen(String in) { |
1141 |
| - } |
1142 |
| - |
1143 | 1143 | @Bean
|
| 1144 | + @SuppressWarnings("unchecked") |
1144 | 1145 | ContainerCustomizer<SimpleMessageListenerContainer> customizer() {
|
1145 |
| - return (container) -> this.customizerCalled = true; |
| 1146 | + return mock(ContainerCustomizer.class); |
1146 | 1147 | }
|
1147 | 1148 |
|
1148 | 1149 | }
|
1149 | 1150 |
|
| 1151 | + @Import(TestListener.class) |
1150 | 1152 | @Configuration(proxyBeanMethods = false)
|
1151 | 1153 | static class DirectContainerCustomizerConfiguration {
|
1152 | 1154 |
|
1153 |
| - boolean customizerCalled; |
| 1155 | + @Bean |
| 1156 | + @SuppressWarnings("unchecked") |
| 1157 | + ContainerCustomizer<DirectMessageListenerContainer> customizer() { |
| 1158 | + return mock(ContainerCustomizer.class); |
| 1159 | + } |
| 1160 | + |
| 1161 | + } |
| 1162 | + |
| 1163 | + static class TestListener { |
1154 | 1164 |
|
1155 | 1165 | @RabbitListener(queues = "test", autoStartup = "false")
|
1156 | 1166 | void listen(String in) {
|
1157 | 1167 | }
|
1158 | 1168 |
|
1159 |
| - @Bean |
1160 |
| - ContainerCustomizer<DirectMessageListenerContainer> customizer() { |
1161 |
| - return (container) -> this.customizerCalled = true; |
1162 |
| - } |
1163 |
| - |
1164 | 1169 | }
|
1165 | 1170 |
|
1166 | 1171 | }
|
0 commit comments