22
22
import static org .mockito .ArgumentMatchers .any ;
23
23
import static org .mockito .ArgumentMatchers .anyBoolean ;
24
24
import static org .mockito .BDDMockito .given ;
25
+ import static org .mockito .BDDMockito .willAnswer ;
25
26
import static org .mockito .BDDMockito .willReturn ;
26
27
import static org .mockito .Mockito .atLeastOnce ;
27
28
import static org .mockito .Mockito .spy ;
@@ -135,14 +136,21 @@ public void clear() throws Exception {
135
136
@ Test
136
137
public void testChangeQueues () throws Exception {
137
138
CountDownLatch latch = new CountDownLatch (30 );
138
- container =
139
- createContainer (new MessageListenerAdapter (new PojoListener (latch )), queue .getName (), queue1 .getName ());
139
+ AtomicInteger restarts = new AtomicInteger ();
140
+ container = spy (createContainer (new MessageListenerAdapter (new PojoListener (latch )), false , queue .getName (),
141
+ queue1 .getName ()));
142
+ willAnswer (invocation -> {
143
+ restarts .incrementAndGet ();
144
+ invocation .callRealMethod ();
145
+ return null ;
146
+ }).given (container ).addAndStartConsumers (1 );
140
147
final CountDownLatch consumerLatch = new CountDownLatch (1 );
141
148
this .container .setApplicationEventPublisher (e -> {
142
149
if (e instanceof AsyncConsumerStoppedEvent ) {
143
150
consumerLatch .countDown ();
144
151
}
145
152
});
153
+ this .container .start ();
146
154
for (int i = 0 ; i < 10 ; i ++) {
147
155
template .convertAndSend (queue .getName (), i + "foo" );
148
156
template .convertAndSend (queue1 .getName (), i + "foo" );
@@ -156,6 +164,7 @@ public void testChangeQueues() throws Exception {
156
164
assertThat (waited ).as ("Timed out waiting for message" ).isTrue ();
157
165
assertThat (template .receiveAndConvert (queue .getName ())).isNull ();
158
166
assertThat (template .receiveAndConvert (queue1 .getName ())).isNull ();
167
+ assertThat (restarts .get ()).isEqualTo (1 );
159
168
}
160
169
161
170
@ Test
0 commit comments