69
69
import org .eclipse .hono .service .monitoring .ConnectionEventProducer ;
70
70
import org .eclipse .hono .service .resourcelimits .ResourceLimitChecks ;
71
71
import org .eclipse .hono .service .test .ProtocolAdapterTestSupport ;
72
+ import org .eclipse .hono .test .TracingMockSupport ;
73
+ import org .eclipse .hono .test .VertxMockSupport ;
72
74
import org .eclipse .hono .util .Adapter ;
73
75
import org .eclipse .hono .util .CommandConstants ;
74
76
import org .eclipse .hono .util .Constants ;
@@ -136,16 +138,9 @@ public void setup() {
136
138
137
139
metrics = mock (AmqpAdapterMetrics .class );
138
140
vertx = mock (Vertx .class );
139
- context = mock (Context .class );
140
- doAnswer (invocation -> {
141
- final Handler <Void > codeToRun = invocation .getArgument (0 );
142
- codeToRun .handle (null );
143
- return null ;
144
- }).when (context ).runOnContext (any ());
141
+ context = VertxMockSupport .mockContext (vertx );
145
142
146
- span = mock (Span .class );
147
- final SpanContext spanContext = mock (SpanContext .class );
148
- when (span .context ()).thenReturn (spanContext );
143
+ span = TracingMockSupport .mockSpan ();
149
144
150
145
this .properties = givenDefaultConfigurationProperties ();
151
146
createClientFactories ();
@@ -179,7 +174,6 @@ protected AmqpAdapterProperties givenDefaultConfigurationProperties() {
179
174
*
180
175
* @param ctx The test context to use for running asynchronous tests.
181
176
*/
182
- @ SuppressWarnings ("unchecked" )
183
177
@ Test
184
178
public void testStartUsesClientProvidedAmqpServer (final VertxTestContext ctx ) {
185
179
// GIVEN an adapter with a client provided Amqp Server
@@ -192,8 +186,8 @@ public void testStartUsesClientProvidedAmqpServer(final VertxTestContext ctx) {
192
186
startupTracker .future ().onComplete (ctx .succeeding (result -> {
193
187
ctx .verify (() -> {
194
188
// THEN the client provided server is started
195
- verify (server ).connectHandler (any ( Handler . class ));
196
- verify (server ).listen (any ( Handler . class ));
189
+ verify (server ).connectHandler (VertxMockSupport . anyHandler ( ));
190
+ verify (server ).listen (VertxMockSupport . anyHandler ( ));
197
191
});
198
192
ctx .completeNow ();
199
193
}));
@@ -461,7 +455,6 @@ public void testUploadEventRejectsPresettledMessage(final VertxTestContext ctx)
461
455
* <em>EventConstants.CONTENT_TYPE_EMPTY_NOTIFICATION</em> event a with TTD -1. An unauthenticated device is used in
462
456
* this test setup to simulate the client device.
463
457
*/
464
- @ SuppressWarnings ("unchecked" )
465
458
@ Test
466
459
public void testAdapterOpensSenderLinkAndNotifyDownstreamApplication () {
467
460
// GIVEN an AMQP adapter configured to use a user-defined server
@@ -471,7 +464,7 @@ public void testAdapterOpensSenderLinkAndNotifyDownstreamApplication() {
471
464
// WHEN an unauthenticated device opens a receiver link with a valid source address
472
465
final ProtonConnection deviceConnection = mock (ProtonConnection .class );
473
466
when (deviceConnection .attachments ()).thenReturn (mock (Record .class ));
474
- when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), any ( Handler . class ), any (), any ()))
467
+ when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), VertxMockSupport . anyHandler ( ), any (), any ()))
475
468
.thenReturn (Future .succeededFuture (mock (CommandConsumer .class )));
476
469
final String sourceAddress = String .format ("%s/%s/%s" , getCommandEndpoint (), TEST_TENANT_ID , TEST_DEVICE );
477
470
final ProtonSender sender = getSender (sourceAddress );
@@ -501,7 +494,7 @@ public void testAdapterClosesCommandConsumerWhenDeviceClosesReceiverLink() {
501
494
// and a device that wants to receive commands
502
495
final CommandConsumer commandConsumer = mock (CommandConsumer .class );
503
496
when (commandConsumer .close (any ())).thenReturn (Future .succeededFuture ());
504
- when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), any ( Handler . class ), any (), any ()))
497
+ when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), VertxMockSupport . anyHandler ( ), any (), any ()))
505
498
.thenReturn (Future .succeededFuture (commandConsumer ));
506
499
final String sourceAddress = String .format ("%s" , getCommandEndpoint ());
507
500
final ProtonSender sender = getSender (sourceAddress );
@@ -596,7 +589,7 @@ private void testAdapterClosesCommandConsumer(
596
589
// that wants to receive commands
597
590
final CommandConsumer commandConsumer = mock (CommandConsumer .class );
598
591
when (commandConsumer .close (any ())).thenReturn (Future .succeededFuture ());
599
- when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), any ( Handler . class ), any (), any ()))
592
+ when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), VertxMockSupport . anyHandler ( ), any (), any ()))
600
593
.thenReturn (Future .succeededFuture (commandConsumer ));
601
594
final String sourceAddress = getCommandEndpoint ();
602
595
final ProtonSender sender = getSender (sourceAddress );
@@ -647,7 +640,7 @@ public void testAdapterSkipsTtdEventOnCmdConnectionCloseIfRemoveConsumerFails(fi
647
640
// that wants to receive commands
648
641
final CommandConsumer commandConsumer = mock (CommandConsumer .class );
649
642
when (commandConsumer .close (any ())).thenReturn (Future .failedFuture (new ClientErrorException (HttpURLConnection .HTTP_PRECON_FAILED )));
650
- when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), any ( Handler . class ), any (), any ()))
643
+ when (commandConsumerFactory .createCommandConsumer (eq (TEST_TENANT_ID ), eq (TEST_DEVICE ), VertxMockSupport . anyHandler ( ), any (), any ()))
651
644
.thenReturn (Future .succeededFuture (commandConsumer ));
652
645
final String sourceAddress = getCommandEndpoint ();
653
646
final ProtonSender sender = getSender (sourceAddress );
@@ -1144,7 +1137,7 @@ public void testLinkForSendingCommandsCloseAfterTimeout() {
1144
1137
final Handler <Long > task = invocation .getArgument (1 );
1145
1138
task .handle (1L );
1146
1139
return 1L ;
1147
- }).when (vertx ).setTimer (anyLong (), any ( Handler . class ));
1140
+ }).when (vertx ).setTimer (anyLong (), VertxMockSupport . anyHandler ( ));
1148
1141
1149
1142
adapter .onCommandReceived (tenantObject , deviceLink , context );
1150
1143
// THEN the adapter releases the command
@@ -1405,13 +1398,12 @@ private VertxBasedAmqpProtocolAdapter newAdapter(
1405
1398
*
1406
1399
* @return The configured server instance.
1407
1400
*/
1408
- @ SuppressWarnings ("unchecked" )
1409
1401
private ProtonServer getAmqpServer () {
1410
1402
1411
1403
final ProtonServer server = mock (ProtonServer .class );
1412
1404
when (server .actualPort ()).thenReturn (0 , Constants .PORT_AMQP );
1413
- when (server .connectHandler (any ( Handler . class ))).thenReturn (server );
1414
- when (server .listen (any ( Handler . class ))).then (invocation -> {
1405
+ when (server .connectHandler (VertxMockSupport . anyHandler ( ))).thenReturn (server );
1406
+ when (server .listen (VertxMockSupport . anyHandler ( ))).then (invocation -> {
1415
1407
final Handler <AsyncResult <ProtonServer >> handler = invocation .getArgument (0 );
1416
1408
handler .handle (Future .succeededFuture (server ));
1417
1409
return server ;
0 commit comments