75
75
import static org .mockito .ArgumentMatchers .anyString ;
76
76
import static org .mockito .ArgumentMatchers .isNull ;
77
77
import static org .mockito .BDDMockito .given ;
78
- import static org .mockito .Mockito . doAnswer ;
78
+ import static org .mockito .BDDMockito . willReturn ;
79
79
import static org .mockito .Mockito .mock ;
80
80
import static org .mockito .Mockito .spy ;
81
81
import static org .mockito .Mockito .when ;
@@ -90,9 +90,9 @@ public class InboundEndpointTests {
90
90
91
91
@ Test
92
92
public void testInt2809JavaTypePropertiesToAmqp () throws Exception {
93
- Connection connection = mock (Connection . class );
94
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
95
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
93
+ Connection connection = mock ();
94
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
95
+ ConnectionFactory connectionFactory = mock ();
96
96
when (connectionFactory .createConnection ()).thenReturn (connection );
97
97
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
98
98
container .setConnectionFactory (connectionFactory );
@@ -104,7 +104,7 @@ public void testInt2809JavaTypePropertiesToAmqp() throws Exception {
104
104
PollableChannel channel = new QueueChannel ();
105
105
106
106
adapter .setOutputChannel (channel );
107
- adapter .setBeanFactory (mock (BeanFactory . class ));
107
+ adapter .setBeanFactory (mock ());
108
108
adapter .setBindSourceMessage (true );
109
109
adapter .afterPropertiesSet ();
110
110
@@ -134,9 +134,9 @@ public void testInt2809JavaTypePropertiesToAmqp() throws Exception {
134
134
135
135
@ Test
136
136
public void testInt2809JavaTypePropertiesFromAmqp () throws Exception {
137
- Connection connection = mock (Connection . class );
138
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
139
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
137
+ Connection connection = mock ();
138
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
139
+ ConnectionFactory connectionFactory = mock ();
140
140
when (connectionFactory .createConnection ()).thenReturn (connection );
141
141
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
142
142
container .setConnectionFactory (connectionFactory );
@@ -169,9 +169,9 @@ public void testInt2809JavaTypePropertiesFromAmqp() throws Exception {
169
169
170
170
@ Test
171
171
public void testMessageConverterJsonHeadersHavePrecedenceOverMessageHeaders () throws Exception {
172
- Connection connection = mock (Connection . class );
173
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
174
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
172
+ Connection connection = mock ();
173
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
174
+ ConnectionFactory connectionFactory = mock ();
175
175
when (connectionFactory .createConnection ()).thenReturn (connection );
176
176
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
177
177
container .setConnectionFactory (connectionFactory );
@@ -235,9 +235,9 @@ public void testMessageConverterJsonHeadersHavePrecedenceOverMessageHeaders() th
235
235
236
236
@ Test
237
237
public void testAdapterConversionError () throws Exception {
238
- Connection connection = mock (Connection . class );
239
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
240
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
238
+ Connection connection = mock ();
239
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
240
+ ConnectionFactory connectionFactory = mock ();
241
241
when (connectionFactory .createConnection ()).thenReturn (connection );
242
242
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
243
243
container .setConnectionFactory (connectionFactory );
@@ -285,9 +285,9 @@ public Object fromMessage(org.springframework.amqp.core.Message message) throws
285
285
286
286
@ Test
287
287
public void testGatewayConversionError () throws Exception {
288
- Connection connection = mock (Connection . class );
289
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
290
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
288
+ Connection connection = mock ();
289
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
290
+ ConnectionFactory connectionFactory = mock ();
291
291
when (connectionFactory .createConnection ()).thenReturn (connection );
292
292
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
293
293
container .setConnectionFactory (connectionFactory );
@@ -339,7 +339,7 @@ public Object fromMessage(org.springframework.amqp.core.Message message) throws
339
339
340
340
@ Test
341
341
public void testRetryWithinOnMessageAdapter () throws Exception {
342
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
342
+ ConnectionFactory connectionFactory = mock ();
343
343
AbstractMessageListenerContainer container = new SimpleMessageListenerContainer (connectionFactory );
344
344
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
345
345
adapter .setOutputChannel (new DirectChannel ());
@@ -367,7 +367,7 @@ public void testRetryWithinOnMessageAdapter() throws Exception {
367
367
368
368
@ Test
369
369
public void testRetryWithMessageRecovererOnMessageAdapter () throws Exception {
370
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
370
+ ConnectionFactory connectionFactory = mock ();
371
371
AbstractMessageListenerContainer container = new SimpleMessageListenerContainer (connectionFactory );
372
372
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
373
373
adapter .setOutputChannel (new DirectChannel ());
@@ -400,7 +400,7 @@ public void testRetryWithMessageRecovererOnMessageAdapter() throws Exception {
400
400
401
401
@ Test
402
402
public void testRetryWithinOnMessageGateway () throws Exception {
403
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
403
+ ConnectionFactory connectionFactory = mock ();
404
404
AbstractMessageListenerContainer container = new SimpleMessageListenerContainer (connectionFactory );
405
405
AmqpInboundGateway adapter = new AmqpInboundGateway (container );
406
406
adapter .setRequestChannel (new DirectChannel ());
@@ -428,7 +428,7 @@ public void testRetryWithinOnMessageGateway() throws Exception {
428
428
429
429
@ Test
430
430
public void testRetryWithMessageRecovererOnMessageGateway () throws Exception {
431
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
431
+ ConnectionFactory connectionFactory = mock ();
432
432
AbstractMessageListenerContainer container = new SimpleMessageListenerContainer (connectionFactory );
433
433
AmqpInboundGateway adapter = new AmqpInboundGateway (container );
434
434
adapter .setRequestChannel (new DirectChannel ());
@@ -462,7 +462,7 @@ public void testRetryWithMessageRecovererOnMessageGateway() throws Exception {
462
462
@ SuppressWarnings ({"unchecked" })
463
463
@ Test
464
464
public void testBatchAdapter () throws Exception {
465
- SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock (ConnectionFactory . class ));
465
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock ());
466
466
container .setDeBatchingEnabled (false );
467
467
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
468
468
QueueChannel out = new QueueChannel ();
@@ -486,7 +486,7 @@ public void testBatchAdapter() throws Exception {
486
486
@ SuppressWarnings ({"unchecked" })
487
487
@ Test
488
488
public void testBatchGateway () throws Exception {
489
- SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock (ConnectionFactory . class ));
489
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock ());
490
490
container .setDeBatchingEnabled (false );
491
491
AmqpInboundGateway gateway = new AmqpInboundGateway (container );
492
492
QueueChannel out = new QueueChannel ();
@@ -514,12 +514,13 @@ public void testBatchGateway() throws Exception {
514
514
@ SuppressWarnings ({"unchecked" })
515
515
@ Test
516
516
public void testConsumerBatchExtract () {
517
- SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock (ConnectionFactory . class ));
517
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock ());
518
518
container .setConsumerBatchEnabled (true );
519
519
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
520
520
QueueChannel out = new QueueChannel ();
521
521
adapter .setOutputChannel (out );
522
522
adapter .setBatchMode (BatchMode .EXTRACT_PAYLOADS_WITH_HEADERS );
523
+ adapter .setHeaderNameForBatchedHeaders ("some_batch_headers" );
523
524
adapter .afterPropertiesSet ();
524
525
ChannelAwareBatchMessageListener listener = (ChannelAwareBatchMessageListener ) container .getMessageListener ();
525
526
MessageProperties messageProperties = new MessageProperties ();
@@ -531,14 +532,14 @@ public void testConsumerBatchExtract() {
531
532
Message <?> received = out .receive (0 );
532
533
assertThat (received ).isNotNull ();
533
534
assertThat (((List <String >) received .getPayload ())).contains ("test1" , "test2" );
534
- assertThat (received .getHeaders ().get (AmqpInboundChannelAdapter . CONSOLIDATED_HEADERS , List .class ))
535
+ assertThat (received .getHeaders ().get ("some_batch_headers" , List .class ))
535
536
.hasSize (2 );
536
537
}
537
538
538
539
@ SuppressWarnings ({"unchecked" })
539
540
@ Test
540
541
public void testConsumerBatch () {
541
- SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock (ConnectionFactory . class ));
542
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock ());
542
543
container .setConsumerBatchEnabled (true );
543
544
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
544
545
QueueChannel out = new QueueChannel ();
@@ -560,7 +561,7 @@ public void testConsumerBatch() {
560
561
561
562
@ Test
562
563
public void testConsumerBatchAndWrongMessageRecoverer () {
563
- SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock (ConnectionFactory . class ));
564
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (mock ());
564
565
container .setConsumerBatchEnabled (true );
565
566
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
566
567
adapter .setRetryTemplate (new RetryTemplate ());
@@ -574,7 +575,7 @@ public void testConsumerBatchAndWrongMessageRecoverer() {
574
575
575
576
@ Test
576
577
public void testExclusiveRecover () {
577
- AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (mock (AbstractMessageListenerContainer . class ));
578
+ AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (mock ());
578
579
adapter .setRetryTemplate (new RetryTemplate ());
579
580
adapter .setMessageRecoverer ((message , cause ) -> {
580
581
});
@@ -587,9 +588,9 @@ public void testExclusiveRecover() {
587
588
588
589
@ Test
589
590
public void testAdapterConversionErrorConsumerBatchExtract () {
590
- Connection connection = mock (Connection . class );
591
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
592
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
591
+ Connection connection = mock ();
592
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
593
+ ConnectionFactory connectionFactory = mock ();
593
594
when (connectionFactory .createConnection ()).thenReturn (connection );
594
595
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
595
596
container .setConnectionFactory (connectionFactory );
@@ -644,9 +645,9 @@ public Object fromMessage(org.springframework.amqp.core.Message message) throws
644
645
645
646
@ Test
646
647
public void testAdapterConversionErrorConsumerBatch () {
647
- Connection connection = mock (Connection . class );
648
- doAnswer ( invocation -> mock (Channel .class )).when (connection ).createChannel (anyBoolean ());
649
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
648
+ Connection connection = mock ();
649
+ willReturn ( mock (Channel .class )).given (connection ).createChannel (anyBoolean ());
650
+ ConnectionFactory connectionFactory = mock ();
650
651
when (connectionFactory .createConnection ()).thenReturn (connection );
651
652
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
652
653
container .setConnectionFactory (connectionFactory );
@@ -700,7 +701,7 @@ public Object fromMessage(org.springframework.amqp.core.Message message) throws
700
701
701
702
@ Test
702
703
public void testRetryWithinOnMessageAdapterConsumerBatch () {
703
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
704
+ ConnectionFactory connectionFactory = mock ();
704
705
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (connectionFactory );
705
706
container .setConsumerBatchEnabled (true );
706
707
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
@@ -746,7 +747,7 @@ public void testRetryWithinOnMessageAdapterConsumerBatch() {
746
747
747
748
@ Test
748
749
public void testRetryWithMessageRecovererOnMessageAdapterConsumerBatch () throws InterruptedException {
749
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
750
+ ConnectionFactory connectionFactory = mock ();
750
751
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer (connectionFactory );
751
752
container .setConsumerBatchEnabled (true );
752
753
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter (container );
0 commit comments