|
35 | 35 | import org.junit.jupiter.params.provider.Arguments;
|
36 | 36 | import org.junit.jupiter.params.provider.MethodSource;
|
37 | 37 |
|
| 38 | +import org.springframework.context.support.GenericApplicationContext; |
| 39 | +import org.springframework.kafka.listener.ConcurrentMessageListenerContainer; |
38 | 40 | import org.springframework.kafka.listener.MessageListenerContainer;
|
39 | 41 |
|
40 | 42 | /**
|
41 | 43 | * @author Gary Russell
|
42 | 44 | * @author Joo Hyuk Kim
|
| 45 | + * @author Artem Bilan |
| 46 | + * |
43 | 47 | * @since 2.8.9
|
44 | 48 | */
|
45 | 49 | public class KafkaListenerEndpointRegistryTests {
|
@@ -139,6 +143,21 @@ void getListenerContainersMatchingBiPredicate(List<String> names, BiPredicate<St
|
139 | 143 | assertThat(listeners).hasSize(expectedCount);
|
140 | 144 | }
|
141 | 145 |
|
| 146 | + @Test |
| 147 | + void verifyUnregisteredListenerContainer() { |
| 148 | + KafkaListenerEndpointRegistry registry = new KafkaListenerEndpointRegistry(); |
| 149 | + GenericApplicationContext applicationContext = new GenericApplicationContext(); |
| 150 | + ConcurrentMessageListenerContainer<?, ?> listenerContainerMock = mock(ConcurrentMessageListenerContainer.class); |
| 151 | + given(listenerContainerMock.getListenerId()).willReturn("testListenerContainer"); |
| 152 | + applicationContext.registerBean(ConcurrentMessageListenerContainer.class, () -> listenerContainerMock); |
| 153 | + applicationContext.refresh(); |
| 154 | + registry.setApplicationContext(applicationContext); |
| 155 | + // Lazy-load from application context |
| 156 | + assertThat(registry.getUnregisteredListenerContainer("testListenerContainer")).isNotNull(); |
| 157 | + // From internal map |
| 158 | + assertThat(registry.getUnregisteredListenerContainer("testListenerContainer")).isNotNull(); |
| 159 | + } |
| 160 | + |
142 | 161 | /**
|
143 | 162 | * Provides parameters for the getListenerContainersMatchingBiPredicate test.
|
144 | 163 | * Each set of parameters includes a list of names, a bi-predicate, and the expected count of matching containers.
|
|
0 commit comments