How to use same method of org.mockito.ArgumentMatchers class

Best Mockito code snippet using org.mockito.ArgumentMatchers.same

Source:SyncPlanPushStrategyIncrementalImplTest.java Github

copy

Full Screen

...204 }205 @Test206 public void testAddMissingFlows() throws Exception {207 Mockito.when(flowCommitter.add(ArgumentMatchers.<InstanceIdentifier<Flow>>any(), flowCaptor.capture(),208 ArgumentMatchers.same(NODE_IDENT)))209 .thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());210 final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();211 flowBox.getItemsToPush().add(DSInputFactory.createFlow("f3", 3));212 flowBox.getItemsToPush().add(DSInputFactory.createFlow("f4", 4));213 final Map<TableKey, ItemSyncBox<Flow>> flowBoxMap = new LinkedHashMap<>();214 flowBoxMap.put(new TableKey((short) 0), flowBox);215 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingFlows(216 NODE_ID, NODE_IDENT, flowBoxMap, counters);217 Assert.assertTrue(result.isDone());218 Assert.assertTrue(result.get().isSuccessful());219 final List<Flow> flowCaptorAllValues = flowCaptor.getAllValues();220 Assert.assertEquals(2, flowCaptorAllValues.size());221 Assert.assertEquals("f3", flowCaptorAllValues.get(0).getId().getValue());222 Assert.assertEquals("f4", flowCaptorAllValues.get(1).getId().getValue());223 final InOrder inOrderFlow = Mockito.inOrder(flowCapableTxService, flowCommitter);224 inOrderFlow.verify(flowCommitter, Mockito.times(2)).add(ArgumentMatchers.<InstanceIdentifier<Flow>>any(),225 ArgumentMatchers.<Flow>any(), ArgumentMatchers.eq(NODE_IDENT));226 //TODO: uncomment when enabled in impl227// inOrderFlow.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());228 inOrderFlow.verifyNoMoreInteractions();229 }230 @Test231 public void testRemoveRedundantFlows() throws Exception {232 Mockito.when(flowCommitter.remove(ArgumentMatchers.<InstanceIdentifier<Flow>>any(), flowCaptor.capture(),233 ArgumentMatchers.same(NODE_IDENT)))234 .thenReturn(RpcResultBuilder.success(new RemoveFlowOutputBuilder().build()).buildFuture());235 final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();236 flowBox.getItemsToPush().add(DSInputFactory.createFlow("f3", 3));237 flowBox.getItemsToPush().add(DSInputFactory.createFlow("f4", 4));238 final Map<TableKey, ItemSyncBox<Flow>> flowBoxMap = new LinkedHashMap<>();239 flowBoxMap.put(new TableKey((short) 0), flowBox);240 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.removeRedundantFlows(241 NODE_ID, NODE_IDENT, flowBoxMap, counters);242 Assert.assertTrue(result.isDone());243 Assert.assertTrue(result.get().isSuccessful());244 final List<Flow> flowCaptorAllValues = flowCaptor.getAllValues();245 Assert.assertEquals(2, flowCaptorAllValues.size());246 Assert.assertEquals("f3", flowCaptorAllValues.get(0).getId().getValue());247 Assert.assertEquals("f4", flowCaptorAllValues.get(1).getId().getValue());248 final InOrder inOrderFlow = Mockito.inOrder(flowCapableTxService, flowCommitter);249 inOrderFlow.verify(flowCommitter, Mockito.times(2)).remove(ArgumentMatchers.<InstanceIdentifier<Flow>>any(),250 ArgumentMatchers.<Flow>any(), ArgumentMatchers.eq(NODE_IDENT));251 inOrderFlow.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());252 inOrderFlow.verifyNoMoreInteractions();253 }254 @Test255 public void testAddMissingFlows_withUpdate() throws Exception {256 Mockito.when(flowCommitter.add(ArgumentMatchers.<InstanceIdentifier<Flow>>any(), flowCaptor.capture(),257 ArgumentMatchers.same(NODE_IDENT)))258 .thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());259 Mockito.when(flowCommitter.update(ArgumentMatchers.<InstanceIdentifier<Flow>>any(),260 flowUpdateCaptor.capture(), flowUpdateCaptor.capture(),261 ArgumentMatchers.same(NODE_IDENT)))262 .thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().build()).buildFuture());263 final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();264 flowBox.getItemsToPush().add(DSInputFactory.createFlow("f3", 3));265 flowBox.getItemsToPush().add(DSInputFactory.createFlow("f4", 4));266 flowBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(267 DSInputFactory.createFlow("f1", 1), DSInputFactory.createFlowWithInstruction("f1", 1)));268 final Map<TableKey, ItemSyncBox<Flow>> flowBoxMap = new LinkedHashMap<>();269 flowBoxMap.put(new TableKey((short) 0), flowBox);270 //TODO: replace null271 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingFlows(272 NODE_ID, NODE_IDENT, flowBoxMap, counters);273 Assert.assertTrue(result.isDone());274 Assert.assertTrue(result.get().isSuccessful());275 final List<Flow> flowCaptorAllValues = flowCaptor.getAllValues();276 Assert.assertEquals(2, flowCaptorAllValues.size());277 Assert.assertEquals("f3", flowCaptorAllValues.get(0).getId().getValue());278 Assert.assertEquals("f4", flowCaptorAllValues.get(1).getId().getValue());279 final List<Flow> flowUpdateCaptorAllValues = flowUpdateCaptor.getAllValues();280 Assert.assertEquals(2, flowUpdateCaptorAllValues.size());281 Assert.assertEquals("f1", flowUpdateCaptorAllValues.get(0).getId().getValue());282 Assert.assertEquals("f1", flowUpdateCaptorAllValues.get(1).getId().getValue());283 final InOrder inOrderFlow = Mockito.inOrder(flowCapableTxService, flowCommitter);284 // add f3, f4285 inOrderFlow.verify(flowCommitter, Mockito.times(2)).add(ArgumentMatchers.<InstanceIdentifier<Flow>>any(),286 ArgumentMatchers.<Flow>any(), ArgumentMatchers.eq(NODE_IDENT));287 // update f1288 inOrderFlow.verify(flowCommitter).update(ArgumentMatchers.<InstanceIdentifier<Flow>>any(),289 ArgumentMatchers.<Flow>any(), ArgumentMatchers.<Flow>any(), ArgumentMatchers.eq(NODE_IDENT));290 //TODO: uncomment when enabled in impl291// inOrderFlow.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());292 inOrderFlow.verifyNoMoreInteractions();293 }294 @Test295 public void testAddMissingMeters() throws Exception {296 Mockito.when(meterCommitter.add(ArgumentMatchers.<InstanceIdentifier<Meter>>any(), meterCaptor.capture(),297 ArgumentMatchers.same(NODE_IDENT)))298 .thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().build()).buildFuture());299 final ItemSyncBox<Meter> meterSyncBox = new ItemSyncBox<>();300 meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(2L));301 meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(4L));302 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingMeters(303 NODE_ID, NODE_IDENT, meterSyncBox, counters);304 Assert.assertTrue(result.isDone());305 Assert.assertTrue(result.get().isSuccessful());306 final List<Meter> metercaptorAllValues = meterCaptor.getAllValues();307 Assert.assertEquals(2, metercaptorAllValues.size());308 Assert.assertEquals(2L, metercaptorAllValues.get(0).getMeterId().getValue().longValue());309 Assert.assertEquals(4L, metercaptorAllValues.get(1).getMeterId().getValue().longValue());310 final InOrder inOrderMeter = Mockito.inOrder(flowCapableTxService, meterCommitter);311 inOrderMeter.verify(meterCommitter, Mockito.times(2)).add(ArgumentMatchers.<InstanceIdentifier<Meter>>any(),312 ArgumentMatchers.<Meter>any(), ArgumentMatchers.eq(NODE_IDENT));313 //TODO: uncomment when enabled in impl314// inOrderMeter.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());315 inOrderMeter.verifyNoMoreInteractions();316 }317 @Test318 public void testAddMissingMeters_withUpdate() throws Exception {319 Mockito.when(meterCommitter.add(ArgumentMatchers.<InstanceIdentifier<Meter>>any(), meterCaptor.capture(),320 ArgumentMatchers.same(NODE_IDENT)))321 .thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().build()).buildFuture());322 Mockito.when(meterCommitter.update(ArgumentMatchers.<InstanceIdentifier<Meter>>any(),323 meterUpdateCaptor.capture(), meterUpdateCaptor.capture(), ArgumentMatchers.same(NODE_IDENT)))324 .thenReturn(RpcResultBuilder.success(new UpdateMeterOutputBuilder().build()).buildFuture());325 final ItemSyncBox<Meter> meterSyncBox = new ItemSyncBox<>();326 meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(2L));327 meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(4L));328 meterSyncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(329 DSInputFactory.createMeter(1L), DSInputFactory.createMeterWithBody(1L)));330 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingMeters(331 NODE_ID, NODE_IDENT, meterSyncBox, counters);332 Assert.assertTrue(result.isDone());333 Assert.assertTrue(result.get().isSuccessful());334 final List<Meter> meterCaptorAllValues = meterCaptor.getAllValues();335 Assert.assertEquals(2, meterCaptorAllValues.size());336 Assert.assertEquals(2L, meterCaptorAllValues.get(0).getMeterId().getValue().longValue());337 Assert.assertEquals(4L, meterCaptorAllValues.get(1).getMeterId().getValue().longValue());338 final List<Meter> meterUpdateCaptorAllValues = meterUpdateCaptor.getAllValues();339 Assert.assertEquals(2, meterUpdateCaptorAllValues.size());340 Assert.assertEquals(1L, meterUpdateCaptorAllValues.get(0).getMeterId().getValue().longValue());341 Assert.assertEquals(1L, meterUpdateCaptorAllValues.get(1).getMeterId().getValue().longValue());342 final InOrder inOrderMeters = Mockito.inOrder(flowCapableTxService, meterCommitter);343 inOrderMeters.verify(meterCommitter, Mockito.times(2)).add(ArgumentMatchers.<InstanceIdentifier<Meter>>any(),344 ArgumentMatchers.<Meter>any(), ArgumentMatchers.eq(NODE_IDENT));345 inOrderMeters.verify(meterCommitter).update(ArgumentMatchers.<InstanceIdentifier<Meter>>any(),346 ArgumentMatchers.<Meter>any(), ArgumentMatchers.<Meter>any(), ArgumentMatchers.eq(NODE_IDENT));347 //TODO: uncomment when enabled in impl348// inOrderMeters.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());349 inOrderMeters.verifyNoMoreInteractions();350 }351 @Test352 public void testRemoveRedundantMeters() throws Exception {353 Mockito.when(meterCommitter.remove(ArgumentMatchers.<InstanceIdentifier<Meter>>any(), meterCaptor.capture(),354 ArgumentMatchers.same(NODE_IDENT)))355 .thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().build()).buildFuture());356 final ItemSyncBox<Meter> meterSyncBox = new ItemSyncBox<>();357 meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(2L));358 meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(4L));359 meterSyncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(360 DSInputFactory.createMeter(1L), DSInputFactory.createMeterWithBody(1L)));361 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.removeRedundantMeters(362 NODE_ID, NODE_IDENT, meterSyncBox, counters);363 Assert.assertTrue(result.isDone());364 Assert.assertTrue(result.get().isSuccessful());365 final List<Meter> metercaptorAllValues = meterCaptor.getAllValues();366 Assert.assertEquals(2, metercaptorAllValues.size());367 Assert.assertEquals(2L, metercaptorAllValues.get(0).getMeterId().getValue().longValue());368 Assert.assertEquals(4L, metercaptorAllValues.get(1).getMeterId().getValue().longValue());369 final InOrder inOrderMeter = Mockito.inOrder(flowCapableTxService, meterCommitter);370 inOrderMeter.verify(meterCommitter, Mockito.times(2)).remove(ArgumentMatchers.<InstanceIdentifier<Meter>>any(),371 ArgumentMatchers.<Meter>any(), ArgumentMatchers.eq(NODE_IDENT));372 //TODO: uncomment when enabled in impl373// inOrderMeter.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());374 inOrderMeter.verifyNoMoreInteractions();375 }376 @Test377 public void testAddMissingGroups() throws Exception {378 Mockito.when(groupCommitter.add(ArgumentMatchers.<InstanceIdentifier<Group>>any(), groupCaptor.capture(),379 ArgumentMatchers.same(NODE_IDENT)))380 .thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture());381 ItemSyncBox<Group> groupBox1 = new ItemSyncBox<>();382 groupBox1.getItemsToPush().add(DSInputFactory.createGroup(2L));383 ItemSyncBox<Group> groupBox2 = new ItemSyncBox<>();384 groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(3L, 2L));385 groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(4L, 2L));386 ItemSyncBox<Group> groupBox3 = new ItemSyncBox<>();387 groupBox3.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(5L, 3L, 4L));388 final List<ItemSyncBox<Group>> groupBoxLot = Lists.newArrayList(groupBox1, groupBox2, groupBox3);389 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingGroups(390 NODE_ID, NODE_IDENT, groupBoxLot, counters);391 Assert.assertTrue(result.isDone());392 Assert.assertTrue(result.get().isSuccessful());393 final List<Group> groupCaptorAllValues = groupCaptor.getAllValues();394 Assert.assertEquals(4, groupCaptorAllValues.size());395 Assert.assertEquals(2L, groupCaptorAllValues.get(0).getGroupId().getValue().longValue());396 Assert.assertEquals(3L, groupCaptorAllValues.get(1).getGroupId().getValue().longValue());397 Assert.assertEquals(4L, groupCaptorAllValues.get(2).getGroupId().getValue().longValue());398 Assert.assertEquals(5L, groupCaptorAllValues.get(3).getGroupId().getValue().longValue());399 final InOrder inOrderGroups = Mockito.inOrder(flowCapableTxService, groupCommitter);400 // add 2401 inOrderGroups.verify(groupCommitter).add(ArgumentMatchers.<InstanceIdentifier<Group>>any(),402 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));403 inOrderGroups.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());404 // add 3, 4405 inOrderGroups.verify(groupCommitter, Mockito.times(2)).add(ArgumentMatchers.<InstanceIdentifier<Group>>any(),406 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));407 inOrderGroups.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());408 // add 5409 inOrderGroups.verify(groupCommitter).add(ArgumentMatchers.<InstanceIdentifier<Group>>any(),410 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));411 inOrderGroups.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());412 inOrderGroups.verifyNoMoreInteractions();413 }414 @Test415 public void testAddMissingGroups_withUpdate() throws Exception {416 Mockito.when(groupCommitter.add(ArgumentMatchers.<InstanceIdentifier<Group>>any(), groupCaptor.capture(),417 ArgumentMatchers.same(NODE_IDENT)))418 .thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture());419 Mockito.when(groupCommitter.update(ArgumentMatchers.<InstanceIdentifier<Group>>any(),420 groupUpdateCaptor.capture(), groupUpdateCaptor.capture(),421 ArgumentMatchers.same(NODE_IDENT)))422 .thenReturn(RpcResultBuilder.success(new UpdateGroupOutputBuilder().build()).buildFuture());423 ItemSyncBox<Group> groupBox1 = new ItemSyncBox<>();424 groupBox1.getItemsToPush().add(DSInputFactory.createGroup(2L));425 groupBox1.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(426 DSInputFactory.createGroup(1L), DSInputFactory.createGroupWithAction(1L)));427 ItemSyncBox<Group> groupBox2 = new ItemSyncBox<>();428 groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(3L, 2L));429 groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(4L, 2L));430 ItemSyncBox<Group> groupBox3 = new ItemSyncBox<>();431 groupBox3.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(5L, 3L, 4L));432 final List<ItemSyncBox<Group>> groupBoxLot = Lists.newArrayList(groupBox1, groupBox2, groupBox3);433 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingGroups(434 NODE_ID, NODE_IDENT, groupBoxLot, counters);435 Assert.assertTrue(result.isDone());436 Assert.assertTrue(result.get().isSuccessful());437 final List<Group> groupCaptorAllValues = groupCaptor.getAllValues();438 Assert.assertEquals(4, groupCaptorAllValues.size());439 Assert.assertEquals(2L, groupCaptorAllValues.get(0).getGroupId().getValue().longValue());440 Assert.assertEquals(3L, groupCaptorAllValues.get(1).getGroupId().getValue().longValue());441 Assert.assertEquals(4L, groupCaptorAllValues.get(2).getGroupId().getValue().longValue());442 Assert.assertEquals(5L, groupCaptorAllValues.get(3).getGroupId().getValue().longValue());443 final List<Group> groupUpdateCaptorAllValues = groupUpdateCaptor.getAllValues();444 Assert.assertEquals(2, groupUpdateCaptorAllValues.size());445 Assert.assertEquals(1L, groupUpdateCaptorAllValues.get(0).getGroupId().getValue().longValue());446 Assert.assertEquals(1L, groupUpdateCaptorAllValues.get(1).getGroupId().getValue().longValue());447 final InOrder inOrderGroups = Mockito.inOrder(flowCapableTxService, groupCommitter);448 // add 2, update 1449 inOrderGroups.verify(groupCommitter).add(ArgumentMatchers.<InstanceIdentifier<Group>>any(),450 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));451 inOrderGroups.verify(groupCommitter).update(ArgumentMatchers.<InstanceIdentifier<Group>>any(),452 ArgumentMatchers.<Group>any(), ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));453 inOrderGroups.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());454 // add 3, 4455 inOrderGroups.verify(groupCommitter, Mockito.times(2)).add(ArgumentMatchers.<InstanceIdentifier<Group>>any(),456 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));457 inOrderGroups.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());458 // add 5459 inOrderGroups.verify(groupCommitter).add(ArgumentMatchers.<InstanceIdentifier<Group>>any(),460 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));461 inOrderGroups.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());462 inOrderGroups.verifyNoMoreInteractions();463 }464 @Test465 public void testRemoveRedundantGroups() throws Exception {466 Mockito.when(groupCommitter.remove(ArgumentMatchers.<InstanceIdentifier<Group>>any(), groupCaptor.capture(),467 ArgumentMatchers.same(NODE_IDENT)))468 .thenReturn(RpcResultBuilder.success(new RemoveGroupOutputBuilder().build()).buildFuture());469 ItemSyncBox<Group> groupBox1 = new ItemSyncBox<>();470 groupBox1.getItemsToPush().add(DSInputFactory.createGroup(2L));471 groupBox1.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(472 DSInputFactory.createGroup(1L), DSInputFactory.createGroupWithAction(1L)));473 ItemSyncBox<Group> groupBox2 = new ItemSyncBox<>();474 groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(3L, 2L));475 groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(4L, 2L));476 ItemSyncBox<Group> groupBox3 = new ItemSyncBox<>();477 groupBox3.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(5L, 3L, 4L));478 final List<ItemSyncBox<Group>> groupBoxLot = Lists.newArrayList(groupBox1, groupBox2, groupBox3);479 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.removeRedundantGroups(480 NODE_ID, NODE_IDENT, groupBoxLot, counters);481 Assert.assertTrue(result.isDone());482 Assert.assertTrue(result.get().isSuccessful());483 final List<Group> groupCaptorAllValues = groupCaptor.getAllValues();484 Assert.assertEquals(4, groupCaptorAllValues.size());485 Assert.assertEquals(5L, groupCaptorAllValues.get(0).getGroupId().getValue().longValue());486 Assert.assertEquals(3L, groupCaptorAllValues.get(1).getGroupId().getValue().longValue());487 Assert.assertEquals(4L, groupCaptorAllValues.get(2).getGroupId().getValue().longValue());488 Assert.assertEquals(2L, groupCaptorAllValues.get(3).getGroupId().getValue().longValue());489 final InOrder inOrderGroup = Mockito.inOrder(flowCapableTxService, groupCommitter);490 // remove 5491 inOrderGroup.verify(groupCommitter).remove(ArgumentMatchers.<InstanceIdentifier<Group>>any(),492 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));493 inOrderGroup.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());494 // remove 3, 4495 inOrderGroup.verify(groupCommitter, Mockito.times(2)).remove(ArgumentMatchers.<InstanceIdentifier<Group>>any(),496 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));497 inOrderGroup.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());498 // remove 2499 inOrderGroup.verify(groupCommitter).remove(ArgumentMatchers.<InstanceIdentifier<Group>>any(),500 ArgumentMatchers.<Group>any(), ArgumentMatchers.eq(NODE_IDENT));501 inOrderGroup.verify(flowCapableTxService).sendBarrier(ArgumentMatchers.<SendBarrierInput>any());502 inOrderGroup.verifyNoMoreInteractions();503 }504 @Test505 public void testUpdateTableFeatures() throws Exception {506 Mockito.lenient().when(tableCommitter.update(ArgumentMatchers.<InstanceIdentifier<TableFeatures>>any(),507 ArgumentMatchers.isNull(TableFeatures.class), tableFeaturesCaptor.capture(),508 ArgumentMatchers.same(NODE_IDENT)))509 .thenReturn(RpcResultBuilder.success(new UpdateTableOutputBuilder().build()).buildFuture());510 final FlowCapableNode operational = new FlowCapableNodeBuilder()511 .setTable(Collections.singletonList(new TableBuilder()512 .setId((short) 1)513 .build()))514 .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()515 .setName("test table features")516 .setTableId((short) 1)517 .build()))518 .build();519 final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.updateTableFeatures(520 NODE_IDENT, operational);521 Assert.assertTrue(result.isDone());522 Assert.assertTrue(result.get().isSuccessful());...

Full Screen

Full Screen

Source:BluetoothDiscoveryServiceTest.java Github

copy

Full Screen

...76 discoveryService.deviceDiscovered(device);77 // this second call should not produce another result78 discoveryService.deviceDiscovered(device);79 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(80 ArgumentMatchers.same(discoveryService),81 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));82 }83 @Test84 public void ignoreOtherDuplicateTest() {85 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();86 BluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();87 BluetoothAddress address = TestUtils.randomAddress();88 BluetoothDevice device1 = mockAdapter1.getDevice(address);89 BluetoothDevice device2 = mockAdapter2.getDevice(address);90 discoveryService.deviceDiscovered(device1);91 discoveryService.deviceDiscovered(device2);92 // this should not produce another result93 discoveryService.deviceDiscovered(device1);94 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(95 ArgumentMatchers.same(discoveryService),96 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));97 }98 @Test99 public void ignoreRssiDuplicateTest() {100 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();101 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());102 discoveryService.deviceDiscovered(device);103 // changing the rssi should not result in a new discovery104 device.setRssi(100);105 discoveryService.deviceDiscovered(device);106 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(107 ArgumentMatchers.same(discoveryService),108 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));109 }110 @Test111 public void nonDuplicateNameTest() throws InterruptedException {112 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();113 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());114 discoveryService.deviceDiscovered(device);115 // this second call should produce another result116 device.setName("sdfad");117 discoveryService.deviceDiscovered(device);118 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(119 ArgumentMatchers.same(discoveryService),120 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));121 }122 @Test123 public void nonDuplicateTxPowerTest() {124 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();125 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());126 discoveryService.deviceDiscovered(device);127 // this second call should produce another result128 device.setTxPower(10);129 discoveryService.deviceDiscovered(device);130 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(131 ArgumentMatchers.same(discoveryService),132 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));133 }134 @Test135 public void nonDuplicateManufacturerIdTest() {136 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();137 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());138 discoveryService.deviceDiscovered(device);139 // this second call should produce another result140 device.setManufacturerId(100);141 discoveryService.deviceDiscovered(device);142 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(143 ArgumentMatchers.same(discoveryService),144 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));145 }146 @Test147 public void useResultFromAnotherAdapterTest() {148 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();149 BluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();150 BluetoothAddress address = TestUtils.randomAddress();151 discoveryService.deviceDiscovered(mockAdapter1.getDevice(address));152 discoveryService.deviceDiscovered(mockAdapter2.getDevice(address));153 ArgumentCaptor<DiscoveryResult> resultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class);154 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2))155 .thingDiscovered(ArgumentMatchers.same(discoveryService), resultCaptor.capture());156 List<DiscoveryResult> results = resultCaptor.getAllValues();157 DiscoveryResult result1 = results.get(0);158 DiscoveryResult result2 = results.get(1);159 Assert.assertNotEquals(result1.getBridgeUID(), result2.getBridgeUID());160 Assert.assertThat(result1.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(mockAdapter2.getUID())));161 Assert.assertThat(result2.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(mockAdapter2.getUID())));162 Assert.assertEquals(result1.getThingUID().getId(), result2.getThingUID().getId());163 Assert.assertEquals(result1.getLabel(), result2.getLabel());164 Assert.assertEquals(result1.getRepresentationProperty(), result2.getRepresentationProperty());165 }166 @Test167 public void connectionParticipantTest() {168 Mockito.doReturn(true).when(participant1).requiresConnection(ArgumentMatchers.any());169 BluetoothAddress address = TestUtils.randomAddress();170 MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();171 MockBluetoothDevice mockDevice = mockAdapter1.getDevice(address);172 String deviceName = RandomStringUtils.randomAlphanumeric(10);173 mockDevice.setDeviceName(deviceName);174 BluetoothDevice device = Mockito.spy(mockDevice);175 discoveryService.deviceDiscovered(device);176 Mockito.verify(device, Mockito.timeout(TIMEOUT).times(1)).connect();177 Mockito.verify(device, Mockito.timeout(TIMEOUT).times(1)).readCharacteristic(178 ArgumentMatchers.argThat(ch -> ch.getGattCharacteristic() == GattCharacteristic.DEVICE_NAME));179 Mockito.verify(device, Mockito.timeout(TIMEOUT).times(1)).disconnect();180 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(181 ArgumentMatchers.same(discoveryService),182 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)183 && arg.getThingUID().getId().equals(deviceName)));184 }185 @Test186 public void multiDiscoverySingleConnectionTest() {187 Mockito.doReturn(true).when(participant1).requiresConnection(ArgumentMatchers.any());188 BluetoothAddress address = TestUtils.randomAddress();189 MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();190 MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();191 MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);192 MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);193 String deviceName = RandomStringUtils.randomAlphanumeric(10);194 mockDevice1.setDeviceName(deviceName);195 mockDevice2.setDeviceName(deviceName);196 BluetoothDevice device1 = Mockito.spy(mockDevice1);197 BluetoothDevice device2 = Mockito.spy(mockDevice2);198 discoveryService.deviceDiscovered(device1);199 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(200 ArgumentMatchers.same(discoveryService),201 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)202 && mockAdapter1.getUID().equals(arg.getBridgeUID())203 && arg.getThingUID().getId().equals(deviceName)));204 Mockito.verify(device1, Mockito.times(1)).connect();205 Mockito.verify(device1, Mockito.times(1)).readCharacteristic(206 ArgumentMatchers.argThat(ch -> ch.getGattCharacteristic() == GattCharacteristic.DEVICE_NAME));207 Mockito.verify(device1, Mockito.times(1)).disconnect();208 discoveryService.deviceDiscovered(device2);209 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(210 ArgumentMatchers.same(discoveryService),211 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)212 && mockAdapter2.getUID().equals(arg.getBridgeUID())213 && arg.getThingUID().getId().equals(deviceName)));214 Mockito.verify(device2, Mockito.never()).connect();215 Mockito.verify(device2, Mockito.never()).readCharacteristic(216 ArgumentMatchers.argThat(ch -> ch.getGattCharacteristic() == GattCharacteristic.DEVICE_NAME));217 Mockito.verify(device2, Mockito.never()).disconnect();218 }219 @Test220 public void nonConnectionParticipantTest() {221 MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();222 MockBluetoothDevice mockDevice = mockAdapter1.getDevice(TestUtils.randomAddress());223 String deviceName = RandomStringUtils.randomAlphanumeric(10);224 mockDevice.setDeviceName(deviceName);225 BluetoothDevice device = Mockito.spy(mockDevice);226 discoveryService.deviceDiscovered(device);227 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(228 ArgumentMatchers.same(discoveryService),229 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)230 && !arg.getThingUID().getId().equals(deviceName)));231 Mockito.verify(device, Mockito.never()).connect();232 Mockito.verify(device, Mockito.never()).readCharacteristic(233 ArgumentMatchers.argThat(ch -> ch.getGattCharacteristic() == GattCharacteristic.DEVICE_NAME));234 Mockito.verify(device, Mockito.never()).disconnect();235 }236 @Test237 public void defaultResultTest() {238 Mockito.doReturn(null).when(participant1).createResult(ArgumentMatchers.any());239 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();240 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());241 discoveryService.deviceDiscovered(device);242 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))243 .thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers244 .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));245 }246 @Test247 public void removeDefaultDeviceTest() {248 Mockito.doReturn(null).when(participant1).createResult(ArgumentMatchers.any());249 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();250 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());251 discoveryService.deviceDiscovered(device);252 discoveryService.deviceRemoved(device);253 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))254 .thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers255 .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));256 }257 @Test258 public void removeUpdatedDefaultDeviceTest() {259 Mockito.doReturn(null).when(participant1).createResult(ArgumentMatchers.any());260 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();261 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());262 discoveryService.deviceDiscovered(device);263 device.setName("somename");264 discoveryService.deviceDiscovered(device);265 discoveryService.deviceRemoved(device);266 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))267 .thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers268 .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));269 }270 @Test271 public void bluezConnectionTimeoutTest() {272 Mockito.doReturn(true).when(participant1).requiresConnection(ArgumentMatchers.any());273 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();274 BadConnectionDevice device = new BadConnectionDevice(mockAdapter1, TestUtils.randomAddress(), 100);275 discoveryService.deviceDiscovered(device);276 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))277 .thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers278 .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));279 }280 @Test281 public void replaceOlderDiscoveryTest() {282 Mockito.doReturn(null).when(participant1).createResult(ArgumentMatchers.any());283 BluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();284 BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());285 MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {286 @Override287 public @Nullable DiscoveryResult createResult(BluetoothDevice device) {288 Integer manufacturer = device.getManufacturerId();289 if (manufacturer != null && manufacturer.equals(10)) {290 // without a device name it should produce a random ThingUID291 return super.createResult(device);292 }293 return null;294 }295 };296 discoveryService.addBluetoothDiscoveryParticipant(participant2);297 // lets start with producing a default result298 discoveryService.deviceDiscovered(device);299 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))300 .thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers301 .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));302 device.setManufacturerId(10);303 // lets start with producing a default result304 discoveryService.deviceDiscovered(device);305 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))306 .thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers307 .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));308 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(309 ArgumentMatchers.same(discoveryService),310 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant2.typeUID)));311 }312 @Test313 public void recursiveFutureTest() throws InterruptedException {314 /*315 * 1. deviceDiscovered(device1)316 * 2. cause discovery to pause at participant1317 * participant1 should make a field non-null for device1 upon unpause318 * 3. make the same field non-null for device2319 * 4. deviceDiscovered(device2)320 * this discovery should be waiting for first discovery to finish321 * 5. unpause participant322 * End result:323 * - participant should only have been called once324 * - thingDiscovered should have been called twice325 */326 Mockito.doReturn(null).when(participant1).createResult(ArgumentMatchers.any());327 AtomicInteger callCount = new AtomicInteger(0);328 final CountDownLatch pauseLatch = new CountDownLatch(1);329 BluetoothAddress address = TestUtils.randomAddress();330 MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();331 MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();332 MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);333 MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);334 String deviceName = RandomStringUtils.randomAlphanumeric(10);335 MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {336 @Override337 public @Nullable DiscoveryResult createResult(BluetoothDevice device) {338 try {339 pauseLatch.await();340 } catch (InterruptedException e) {341 // do nothing342 }343 device.setName(deviceName);344 callCount.incrementAndGet();345 return super.createResult(device);346 }347 };348 discoveryService.addBluetoothDiscoveryParticipant(participant2);349 discoveryService.deviceDiscovered(mockDevice1);350 mockDevice2.setName(deviceName);351 discoveryService.deviceDiscovered(mockDevice2);352 pauseLatch.countDown();353 Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(354 ArgumentMatchers.same(discoveryService),355 ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant2.typeUID)));356 Assert.assertEquals(1, callCount.get());357 }358 private class MockDiscoveryParticipant implements BluetoothDiscoveryParticipant {359 private ThingTypeUID typeUID;360 public MockDiscoveryParticipant() {361 this.typeUID = new ThingTypeUID("mock", RandomStringUtils.randomAlphabetic(6));362 }363 @Override364 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {365 return Collections.singleton(typeUID);366 }367 @Override368 public @Nullable DiscoveryResult createResult(BluetoothDevice device) {...

Full Screen

Full Screen

Source:TestRedirectExec.java Github

copy

Full Screen

...102 .setStream(inStream2)103 .build();104 response2.setEntity(entity2);105 Mockito.when(chain.proceed(106 ArgumentMatchers.same(request),107 ArgumentMatchers.any())).thenReturn(response1);108 Mockito.when(chain.proceed(109 HttpRequestMatcher.matchesRequestUri(redirect),110 ArgumentMatchers.any())).thenReturn(response2);111 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);112 redirectExec.execute(request, scope, chain);113 final ArgumentCaptor<ClassicHttpRequest> reqCaptor = ArgumentCaptor.forClass(ClassicHttpRequest.class);114 Mockito.verify(chain, Mockito.times(2)).proceed(reqCaptor.capture(), ArgumentMatchers.same(scope));115 final List<ClassicHttpRequest> allValues = reqCaptor.getAllValues();116 Assert.assertNotNull(allValues);117 Assert.assertEquals(2, allValues.size());118 Assert.assertSame(request, allValues.get(0));119 Mockito.verify(response1, Mockito.times(1)).close();120 Mockito.verify(inStream1, Mockito.times(2)).close();121 Mockito.verify(response2, Mockito.never()).close();122 Mockito.verify(inStream2, Mockito.never()).close();123 }124 @Test125 public void testMaxRedirect() throws Exception {126 final HttpRoute route = new HttpRoute(target);127 final HttpGet request = new HttpGet("/test");128 final HttpClientContext context = HttpClientContext.create();129 final RequestConfig config = RequestConfig.custom()130 .setRedirectsEnabled(true)131 .setMaxRedirects(3)132 .build();133 context.setRequestConfig(config);134 final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));135 final URI redirect = new URI("http://localhost:80/redirect");136 response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());137 Mockito.when(chain.proceed(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(response1);138 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);139 Assert.assertThrows(RedirectException.class, () ->140 redirectExec.execute(request, scope, chain));141 }142 @Test143 public void testRelativeRedirect() throws Exception {144 final HttpRoute route = new HttpRoute(target);145 final HttpGet request = new HttpGet("/test");146 final HttpClientContext context = HttpClientContext.create();147 final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));148 final URI redirect = new URI("/redirect");149 response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());150 Mockito.when(chain.proceed(151 ArgumentMatchers.same(request),152 ArgumentMatchers.any())).thenReturn(response1);153 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);154 Assert.assertThrows(HttpException.class, () ->155 redirectExec.execute(request, scope, chain));156 }157 @Test158 public void testCrossSiteRedirect() throws Exception {159 final HttpHost proxy = new HttpHost("proxy");160 final HttpRoute route = new HttpRoute(target, proxy);161 final HttpGet request = new HttpGet("/test");162 final HttpClientContext context = HttpClientContext.create();163 final AuthExchange targetAuthExchange = new AuthExchange();164 targetAuthExchange.setState(AuthExchange.State.SUCCESS);165 targetAuthExchange.select(new BasicScheme());166 final AuthExchange proxyAuthExchange = new AuthExchange();167 proxyAuthExchange.setState(AuthExchange.State.SUCCESS);168 proxyAuthExchange.select(new NTLMScheme());169 context.setAuthExchange(target, targetAuthExchange);170 context.setAuthExchange(proxy, proxyAuthExchange);171 final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));172 final URI redirect = new URI("http://otherhost:8888/redirect");173 response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());174 final ClassicHttpResponse response2 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_OK));175 final HttpHost otherHost = new HttpHost("otherhost", 8888);176 Mockito.when(chain.proceed(177 ArgumentMatchers.same(request),178 ArgumentMatchers.any())).thenReturn(response1);179 Mockito.when(chain.proceed(180 HttpRequestMatcher.matchesRequestUri(redirect),181 ArgumentMatchers.any())).thenReturn(response2);182 Mockito.when(httpRoutePlanner.determineRoute(183 ArgumentMatchers.eq(otherHost),184 ArgumentMatchers.<HttpClientContext>any())).thenReturn(new HttpRoute(otherHost));185 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);186 redirectExec.execute(request, scope, chain);187 final AuthExchange authExchange1 = context.getAuthExchange(target);188 Assert.assertNotNull(authExchange1);189 Assert.assertEquals(AuthExchange.State.UNCHALLENGED, authExchange1.getState());190 Assert.assertNull(authExchange1.getAuthScheme());191 final AuthExchange authExchange2 = context.getAuthExchange(proxy);192 Assert.assertNotNull(authExchange2);193 Assert.assertEquals(AuthExchange.State.UNCHALLENGED, authExchange2.getState());194 Assert.assertNull(authExchange2.getAuthScheme());195 }196 @Test197 public void testAllowCircularRedirects() throws Exception {198 final HttpRoute route = new HttpRoute(target);199 final HttpClientContext context = HttpClientContext.create();200 context.setRequestConfig(RequestConfig.custom()201 .setCircularRedirectsAllowed(true)202 .build());203 final URI uri = URI.create("http://localhost/");204 final HttpGet request = new HttpGet(uri);205 final URI uri1 = URI.create("http://localhost/stuff1");206 final URI uri2 = URI.create("http://localhost/stuff2");207 final ClassicHttpResponse response1 = new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY);208 response1.addHeader("Location", uri1.toASCIIString());209 final ClassicHttpResponse response2 = new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY);210 response2.addHeader("Location", uri2.toASCIIString());211 final ClassicHttpResponse response3 = new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY);212 response3.addHeader("Location", uri1.toASCIIString());213 final ClassicHttpResponse response4 = new BasicClassicHttpResponse(HttpStatus.SC_OK);214 Mockito.when(chain.proceed(215 HttpRequestMatcher.matchesRequestUri(uri),216 ArgumentMatchers.any())).thenReturn(response1);217 Mockito.when(chain.proceed(218 HttpRequestMatcher.matchesRequestUri(uri1),219 ArgumentMatchers.any())).thenReturn(response2, response4);220 Mockito.when(chain.proceed(221 HttpRequestMatcher.matchesRequestUri(uri2),222 ArgumentMatchers.any())).thenReturn(response3);223 Mockito.when(httpRoutePlanner.determineRoute(224 ArgumentMatchers.eq(new HttpHost("localhost")),225 ArgumentMatchers.<HttpClientContext>any())).thenReturn(route);226 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);227 redirectExec.execute(request, scope, chain);228 final RedirectLocations uris = context.getRedirectLocations();229 Assert.assertNotNull(uris);230 Assert.assertEquals(Arrays.asList(uri1, uri2, uri1), uris.getAll());231 }232 @Test233 public void testGetLocationUriDisallowCircularRedirects() throws Exception {234 final HttpRoute route = new HttpRoute(target);235 final HttpClientContext context = HttpClientContext.create();236 context.setRequestConfig(RequestConfig.custom()237 .setCircularRedirectsAllowed(false)238 .build());239 final URI uri = URI.create("http://localhost/");240 final HttpGet request = new HttpGet(uri);241 final URI uri1 = URI.create("http://localhost/stuff1");242 final URI uri2 = URI.create("http://localhost/stuff2");243 final ClassicHttpResponse response1 = new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY);244 response1.addHeader("Location", uri1.toASCIIString());245 final ClassicHttpResponse response2 = new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY);246 response2.addHeader("Location", uri2.toASCIIString());247 final ClassicHttpResponse response3 = new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY);248 response3.addHeader("Location", uri1.toASCIIString());249 Mockito.when(httpRoutePlanner.determineRoute(250 ArgumentMatchers.eq(new HttpHost("localhost")),251 ArgumentMatchers.<HttpClientContext>any())).thenReturn(route);252 Mockito.when(chain.proceed(253 HttpRequestMatcher.matchesRequestUri(uri),254 ArgumentMatchers.any())).thenReturn(response1);255 Mockito.when(chain.proceed(256 HttpRequestMatcher.matchesRequestUri(uri1),257 ArgumentMatchers.any())).thenReturn(response2);258 Mockito.when(chain.proceed(259 HttpRequestMatcher.matchesRequestUri(uri2),260 ArgumentMatchers.any())).thenReturn(response3);261 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);262 Assert.assertThrows(CircularRedirectException.class, () ->263 redirectExec.execute(request, scope, chain));264 }265 @Test266 public void testRedirectRuntimeException() throws Exception {267 final HttpRoute route = new HttpRoute(target);268 final HttpGet request = new HttpGet("/test");269 final HttpClientContext context = HttpClientContext.create();270 final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));271 final URI redirect = new URI("http://localhost:80/redirect");272 response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());273 Mockito.when(chain.proceed(274 ArgumentMatchers.same(request),275 ArgumentMatchers.any())).thenReturn(response1);276 Mockito.doThrow(new RuntimeException("Oppsie")).when(redirectStrategy).getLocationURI(277 ArgumentMatchers.<ClassicHttpRequest>any(),278 ArgumentMatchers.<ClassicHttpResponse>any(),279 ArgumentMatchers.<HttpClientContext>any());280 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);281 Assert.assertThrows(RuntimeException.class, () ->282 redirectExec.execute(request, scope, chain));283 Mockito.verify(response1).close();284 }285 @Test286 public void testRedirectProtocolException() throws Exception {287 final HttpRoute route = new HttpRoute(target);288 final HttpGet request = new HttpGet("/test");289 final HttpClientContext context = HttpClientContext.create();290 final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));291 final URI redirect = new URI("http://localhost:80/redirect");292 response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());293 final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));294 final HttpEntity entity1 = EntityBuilder.create()295 .setStream(inStream1)296 .build();297 response1.setEntity(entity1);298 Mockito.when(chain.proceed(299 ArgumentMatchers.same(request),300 ArgumentMatchers.any())).thenReturn(response1);301 Mockito.doThrow(new ProtocolException("Oppsie")).when(redirectStrategy).getLocationURI(302 ArgumentMatchers.<ClassicHttpRequest>any(),303 ArgumentMatchers.<ClassicHttpResponse>any(),304 ArgumentMatchers.<HttpClientContext>any());305 final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);306 Assert.assertThrows(ProtocolException.class, () ->307 redirectExec.execute(request, scope, chain));308 Mockito.verify(inStream1, Mockito.times(2)).close();309 Mockito.verify(response1).close();310 }311 private static class HttpRequestMatcher implements ArgumentMatcher<ClassicHttpRequest> {312 private final URI expectedRequestUri;313 HttpRequestMatcher(final URI requestUri) {...

Full Screen

Full Screen

Source:MatchersMixin.java Github

copy

Full Screen

...315 default <T> T refEq(T value, String... excludeFields) {316 return ArgumentMatchers.refEq(value, excludeFields);317 }318 /**319 * Delegate call to public static <T> T org.mockito.ArgumentMatchers.same(T)320 * {@link org.mockito.ArgumentMatchers#same(java.lang.Object)}321 */322 default <T> T same(T value) {323 return ArgumentMatchers.same(value);324 }325 /**326 * Delegate call to public static short org.mockito.ArgumentMatchers.shortThat(org.mockito.ArgumentMatcher<java.lang.Short>)327 * {@link org.mockito.ArgumentMatchers#shortThat(org.mockito.ArgumentMatcher)}328 */329 default short shortThat(ArgumentMatcher<Short> matcher) {330 return ArgumentMatchers.shortThat(matcher);331 }332 /**333 * Delegate call to public static java.lang.String org.mockito.ArgumentMatchers.startsWith(java.lang.String)334 * {@link org.mockito.ArgumentMatchers#startsWith(java.lang.String)}335 */336 default String startsWith(String prefix) {337 return ArgumentMatchers.startsWith(prefix);...

Full Screen

Full Screen

Source:Slf4JLogBridgeImplTest.java Github

copy

Full Screen

...69 ArgumentCaptor<Marker> markerCapture = ArgumentCaptor.forClass(Marker.class);70 Mockito.verify(mockScrubber, Mockito.times(1)).cleanMessage(testName.getMethodName());71 Mockito.verify(mockHandler, Mockito.times(1)).isEnabled(mockSlf4JLogger);72 Mockito.verify(mockHandler, Mockito.times(0)).log(ArgumentMatchers.any(org.slf4j.Logger.class), ArgumentMatchers.any(Marker.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(Throwable.class));73 Mockito.verify(mockHandler, Mockito.times(1)).log(ArgumentMatchers.same(mockSlf4JLogger), markerCapture.capture(), ArgumentMatchers.matches(message));74 Assert.assertEquals(Logger.EVENT_UNSPECIFIED.toString(), markerCapture.getValue().getName());75 }76 @Test77 public void testLogErrorMessageWithException() {78 String message = testName.getMethodName() + " Cleaned";79 Mockito.when(mockHandler.isEnabled(mockSlf4JLogger)).thenReturn(true);80 Mockito.when(mockScrubber.cleanMessage(testName.getMethodName())).thenReturn(message);81 bridge.log(mockSlf4JLogger, Logger.ALL, Logger.EVENT_UNSPECIFIED, testName.getMethodName(), testEx);82 ArgumentCaptor<Marker> markerCapture = ArgumentCaptor.forClass(Marker.class);83 Mockito.verify(mockScrubber, Mockito.times(1)).cleanMessage(testName.getMethodName());84 Mockito.verify(mockHandler, Mockito.times(1)).isEnabled(mockSlf4JLogger);85 Mockito.verify(mockHandler, Mockito.times(0)).log(ArgumentMatchers.any(org.slf4j.Logger.class), ArgumentMatchers.any(Marker.class), ArgumentMatchers.any(String.class));86 Mockito.verify(mockHandler, Mockito.times(1)).log(ArgumentMatchers.same(mockSlf4JLogger), markerCapture.capture(), ArgumentMatchers.matches(message), ArgumentMatchers.same(testEx));87 Assert.assertEquals(Logger.EVENT_UNSPECIFIED.toString(), markerCapture.getValue().getName()); 88 }89 @Test90 public void testDisabledLogMessage() {91 Mockito.when(mockHandler.isEnabled(mockSlf4JLogger)).thenReturn(false);92 bridge.log(mockSlf4JLogger, Logger.ALL, Logger.EVENT_UNSPECIFIED, testName.getMethodName());93 Mockito.verify(mockHandler, Mockito.times(1)).isEnabled(mockSlf4JLogger);94 Mockito.verify(mockScrubber, Mockito.times(0)).cleanMessage(ArgumentMatchers.anyString());95 Mockito.verify(mockHandler, Mockito.times(0)).log(ArgumentMatchers.any(org.slf4j.Logger.class), ArgumentMatchers.any(Marker.class), ArgumentMatchers.any(String.class));96 Mockito.verify(mockHandler, Mockito.times(0)).log(ArgumentMatchers.any(org.slf4j.Logger.class), ArgumentMatchers.any(Marker.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(Throwable.class));97 }98 @Test99 public void testDisabledErrorLogWithException() {100 Mockito.when(mockHandler.isEnabled(mockSlf4JLogger)).thenReturn(false);...

Full Screen

Full Screen

Source:AdminServiceTest.java Github

copy

Full Screen

...40 @Test41 public void setUserRoleTest() {42 String login = "login";43 Mockito.when(userRepository.findByLogin(login)).thenReturn(user);44 Mockito.when(userRepository.save(ArgumentMatchers.same(user))).thenReturn(user);45 Assertions.assertSame(user, adminService.setUserRole(login, role));46 Mockito.verify(userRepository, Mockito.times(1)).save(ArgumentMatchers.same(user));47 }48 @Test49 public void setUserTest() {50 Mockito.when(userRepository.save(ArgumentMatchers.same(user))).thenReturn(user);51 Mockito.when(user.getPassword()).thenReturn("");52 Mockito.when(passwordEncoder.encode(ArgumentMatchers.anyString())).thenReturn(null);53 Mockito.doNothing().when(user).setPassword(Mockito.any(String.class));54 Mockito.doNothing().when(user).setRole(ArgumentMatchers.any(Role.class));55 Assertions.assertSame(user, adminService.setUser(user));56 Mockito.verify(userRepository, Mockito.times(1)).save(ArgumentMatchers.same(user));57 Mockito.verify(passwordEncoder, Mockito.times(1)).encode(ArgumentMatchers.anyString());58 }59 @Test60 public void removeUserTest() {61 Mockito.when(userRepository.getById(ArgumentMatchers.anyLong())).thenReturn(user);62 Assertions.assertSame(user, adminService.removeUser(0L));63 Mockito.verify(userRepository, Mockito.times(1)).delete(user);64 }65 @Test66 public void getUserByLoginAndPasswordTest() {67 String login = "login";68 String password = "password";69 Mockito.when(userRepository.findByLogin(login)).thenReturn(user);70 Mockito.when(user.getPassword()).thenReturn(password);...

Full Screen

Full Screen

Source:S60MdmConnectionHelperTest.java Github

copy

Full Screen

...13package org.talend.metadata.managment.mdm;14import static org.mockito.ArgumentMatchers.any;15import static org.mockito.ArgumentMatchers.anyString;16import static org.mockito.ArgumentMatchers.eq;17import static org.mockito.ArgumentMatchers.same;18import static org.mockito.Mockito.times;19import java.net.URL;20import java.util.HashMap;21import java.util.Map;22import javax.xml.ws.BindingProvider;23import org.apache.log4j.Logger;24import org.junit.Test;25import org.junit.runner.RunWith;26import org.mockito.Mockito;27import org.powermock.api.mockito.PowerMockito;28import org.powermock.core.classloader.annotations.PowerMockIgnore;29import org.powermock.core.classloader.annotations.PrepareForTest;30import org.powermock.modules.junit4.PowerMockRunner;31import org.talend.core.GlobalServiceRegister;32import org.talend.core.service.IMDMWebServiceHook;33import org.talend.core.utils.ReflectionUtils;34@RunWith(PowerMockRunner.class)35@PrepareForTest({ ReflectionUtils.class, Logger.class, GlobalServiceRegister.class })36@PowerMockIgnore({ "javax.crypto.*", "org.eclipse.osgi.*" })37public class S60MdmConnectionHelperTest {38 @Test39 public void testCheckConnection() throws Exception {40 final String username = "username";41 final String password = "password";42 final String serverUrl = "http://localhost:8180/talendmdm/services?wsdl";43 // mock BindingProvider44 Map<String, Object> requestContext = new HashMap<>();45 BindingProvider mockStub = Mockito.mock(BindingProvider.class);46 Mockito.when(mockStub.getRequestContext()).thenReturn(requestContext);47 PowerMockito.mockStatic(ReflectionUtils.class);48 Object mockServiceService = PowerMockito.mock(Object.class);49 PowerMockito50 .when(ReflectionUtils.newInstance("org.talend.mdm.webservice.TMDMService_Service",51 getClass().getClassLoader(), new Object[] { new URL(serverUrl) }))52 .thenReturn(mockServiceService);53 PowerMockito.when(ReflectionUtils.class, "invokeMethod", same(mockServiceService), eq("getTMDMPort"), any(Object[].class),54 any(Class[].class))55 .thenReturn(mockStub);56 57 // mock IMDMWebServiceHook58 IMDMWebServiceHook mockWebServiceHook = Mockito.mock(IMDMWebServiceHook.class);59 PowerMockito.mockStatic(GlobalServiceRegister.class);60 GlobalServiceRegister mockGlobalServiceRegister = PowerMockito.mock(GlobalServiceRegister.class);61 PowerMockito.when(GlobalServiceRegister.getDefault()).thenReturn(mockGlobalServiceRegister);62 PowerMockito.when(GlobalServiceRegister.getDefault().isServiceRegistered(IMDMWebServiceHook.class)).thenReturn(true);63 PowerMockito.when(GlobalServiceRegister.getDefault().getService(IMDMWebServiceHook.class)).thenReturn(mockWebServiceHook);64 // call & verify65 S60MdmConnectionHelper helper = new S60MdmConnectionHelper();66 helper.checkConnection(serverUrl, null, username, password);67 Mockito.verify(mockWebServiceHook, times(1)).preRequestSendingHook(any(Map.class), anyString());...

Full Screen

Full Screen

Source:VerificationUsingMatchersTest.java Github

copy

Full Screen

...7import static org.junit.Assert.assertNotSame;8import static org.junit.Assert.fail;9import static org.mockito.Mockito.times;10import static org.mockito.Mockito.verify;11import static org.mockito.ArgumentMatchers.same;12import static org.mockito.ArgumentMatchers.anyInt;13import static org.mockito.ArgumentMatchers.isA;14import static org.mockito.ArgumentMatchers.contains;15import static org.mockito.AdditionalMatchers.geq;16import static org.mockito.AdditionalMatchers.leq;17import static org.mockito.AdditionalMatchers.and;18import org.junit.Before;19import org.junit.Test;20import org.mockito.Mockito;21import org.mockito.exceptions.verification.WantedButNotInvoked;22import org.mockito.exceptions.verification.opentest4j.ArgumentsAreDifferent;23import org.mockitousage.IMethods;24import org.mockitoutil.TestBase;25public class VerificationUsingMatchersTest extends TestBase {26 private IMethods mock;27 @Before28 public void setUp() {29 mock = Mockito.mock(IMethods.class);30 }31 @Test32 public void shouldVerifyExactNumberOfInvocationsUsingMatcher() {33 mock.simpleMethod(1);34 mock.simpleMethod(2);35 mock.simpleMethod(3);36 verify(mock, times(3)).simpleMethod(anyInt());37 }38 @Test39 public void shouldVerifyUsingSameMatcher() {40 Object one = new String("1243");41 Object two = new String("1243");42 Object three = new String("1243");43 assertNotSame(one, two);44 assertEquals(one, two);45 assertEquals(two, three);46 mock.oneArg(one);47 mock.oneArg(two);48 verify(mock).oneArg(same(one));49 verify(mock, times(2)).oneArg(two);50 try {51 verify(mock).oneArg(same(three));52 fail();53 } catch (WantedButNotInvoked e) {54 }55 }56 @Test57 public void shouldVerifyUsingMixedMatchers() {58 mock.threeArgumentMethod(11, "", "01234");59 try {60 verify(mock)61 .threeArgumentMethod(and(geq(7), leq(10)), isA(String.class), contains("123"));62 fail();63 } catch (ArgumentsAreDifferent e) {64 }65 mock.threeArgumentMethod(8, new Object(), "01234");...

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.any;2import static org.mockito.ArgumentMatchers.anyInt;3import static org.mockito.ArgumentMatchers.anyList;4import static org.mockito.ArgumentMatchers.anySet;5import static org.mockito.ArgumentMatchers.anyString;6import static org.mockito.ArgumentMatchers.argThat;7import static org.mockito.ArgumentMatchers.eq;8import static org.mockito.ArgumentMatchers.isA;9import static org.mockito.ArgumentMatchers.isNull;10import static org.mockito.ArgumentMatchers.notNull;11import static org.mockito.ArgumentMatchers.refEq;12import static org.mockito.ArgumentMatchers.same;13import static org.mockito.ArgumentMatchers.startsWith;14import java.util.ArrayList;15import java.util.HashSet;16import java.util.List;17import java.util.Set;18import org.junit.Test;19import org.mockito.ArgumentMatcher;20public class MockitoArgumentMatchersTest {21 public void test() {22 List<String> list = new ArrayList<>();23 list.add("abc");24 list.add("xyz");25 list.add("123");26 list.add("456");27 list.add("789");28 list.add("abc");29 list.add("xyz");30 list.add("123");31 list.add("456");32 list.add("789");33 list.add("abc");34 list.add("xyz");35 list.add("123");36 list.add("456");37 list.add("789");38 list.add("abc");39 list.add("xyz");40 list.add("123");41 list.add("456");42 list.add("789");43 list.add("abc");44 list.add("xyz");45 list.add("123");46 list.add("456");47 list.add("789");48 list.add("abc");49 list.add("xyz");50 list.add("123");51 list.add("456");52 list.add("789");53 list.add("abc");54 list.add("xyz");55 list.add("123");56 list.add("456");57 list.add("789");58 list.add("abc");59 list.add("xyz");60 list.add("123");61 list.add("456");62 list.add("789");63 list.add("abc");64 list.add("xyz");65 list.add("123");66 list.add("456");67 list.add("789");68 list.add("abc");69 list.add("xyz");70 list.add("123");71 list.add("456");72 list.add("789");73 Set<String> set = new HashSet<>();74 set.add("abc");75 set.add("xyz");76 set.add("123");

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import static org.mockito.ArgumentMatchers.any;3import static org.mockito.ArgumentMatchers.anyInt;4import static org.mockito.ArgumentMatchers.anyString;5import static org.mockito.ArgumentMatchers.argThat;6import static org.mockito.ArgumentMatchers.eq;7import static org.mockito.ArgumentMatchers.isNull;8import static org.mockito.ArgumentMatchers.notNull;9import static org.mockito.ArgumentMatchers.same;10import static org.mockito.ArgumentMatchers.startsWith;11import org.mockito.Mockito;12import static org.mockito.Mockito.*;13import static org.mockito.Mockito.doNothing;14import static org.mockito.Mockito.doReturn;15import static org.mockito.Mockito.doThrow;16import static org.mockito.Mockito.mock;17import static org.mockito.Mockito.spy;18import static org.mockito.Mockito.times;19import static org.mockito.Mockito.verify;20import static org.mockito.Mockito.when;21import org.mockito.Matchers;22import static org.mockito.Matchers.*;23import static org.mockito.Matchers.any;24import static org.mockito.Matchers.anyInt;25import static org.mockito.Matchers.anyString;26import static org.mockito.Matchers.argThat;27import static org.mockito.Matchers.eq;28import static org.mockito.Matchers.isNull;29import static org.mockito.Matchers.notNull;30import static org.mockito.Matchers.same;31import static org.mockito.Matchers.startsWith;32import org.mockito.Matchers;33import static org.mockito.Matchers.*;34import static org.mockito.Matchers.any;35import static org.mockito.Matchers.anyInt;36import static org.mockito.Matchers.anyString;37import static org.mockito.Matchers.argThat;38import static org.mockito.Matchers.eq;39import static org.mockito.Matchers.isNull;40import static org.mockito.Matchers.notNull;41import static org.mockito.Matchers.same;42import static org.mockito.Matchers.startsWith;43import org.mockito.Matchers;44import static org.mockito.Matchers.*;45import static org.mockito.Matchers.any;46import static org.mockito.Matchers.anyInt;47import static org.mockito.Matchers.anyString;48import static org.mockito.Matchers.argThat;49import static org.mockito.Matchers.eq;50import static org.mockito.Matchers.isNull;51import static org.mockito.Matchers.notNull;52import static org.mockito.Matchers.same;53import static org.mockito.Matchers.startsWith;54import org.mockito.Matchers;55import static org.mockito.Matchers.*;56import static org.mockito.Matchers.any;57import static org.mockito.Matchers.anyInt;58import static org.mockito.Matchers.anyString;59import static org.mockito.Matchers.argThat;60import static org.mockito.Matchers.eq;61import static org.mockito.Matchers.isNull;

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import org.mockito.stubbing.Answer;4import org.mockito.stubbing.OngoingStubbing;5import org.mockito.stubbing.Stubber;6import org.mockito.invocation.InvocationOnMock;7import org.mockito.stubbing.Answer;8import java.util.Arrays;9import java.util.Collection;10import java.util.List;11import java.util.function.Predicate;12import java.util.stream.Collectors;13import java.util.stream.Stream;14import java.util.stream.StreamSupport;15import java.util.stream.Stream;16import jav

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.any;2import java.util.List;3import org.mockito.ArgumentMatchers;4public class MockitoArgumentMatchersTest {5 public static void main(String[] args) {6 List<String> mock = mock(List.class);7 when(mock.add(any(String.class))).thenReturn(true);8 when(mock.add(ArgumentMatchers.any(String.class))).thenReturn(true);9 when(mock.add(org.mockito.ArgumentMatchers.any(String.class))).thenReturn(true);10 }11}

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import org.mockito.internal.matchers.Any;4import org.mockito.internal.matchers.AnyVararg;5import org.mockito.internal.matchers.CapturingMatcher;6import org.mockito.internal.matchers.Equals;7import org.mockito.internal.matchers.InstanceOf;8import org.mockito.internal.matchers.Not;9import org.mockito.internal.matchers.Same;10import org.mockito.internal.matchers.VarargMatcher;11import org.mockito.internal.matchers.apachecommons.ReflectionEquals;12import org.mockito.internal.matchers.text.ValuePrinter;13import org.mockito.internal.util.Primitives;14import org.mockito.internal.util.StringUtil;15import org.mockito.internal.util.collections.ListUtil;16import org.mockito.internal.util.collections.Sets;17import org.mockito.internal.util.reflection.Fields;18import org.mockito.internal.util.reflection.LenientCopyTool;19import org.mockito.internal.util.reflection.LenientSetter;20import org.mockito.internal.util.reflection.LenientUnmockedChecker;21import org.mockito.internal.util.reflection.LenientWrapper;22import org.mockito.internal.util.reflection.ParameterizedTypeImpl;23import org.mockito.internal.util.reflection.SerializableMode;24import org.mockito.internal.util.reflection.WhiteboxImpl;25import org.mockito.internal.util.reflection.WildcardTypeImpl;26import org.mockito.invocation.InvocationOnMock;27import org.mockito.listeners.InvocationListener;28import org.mockito.listeners.MethodInvocationReport;29import org.mockito.listeners.StubbingLookupEvent;30import org.mockito.listeners.StubbingLookupListener;31import org.mockito.listeners.VerificationStartedEvent;32import org.mockito.listeners.VerificationStartedListener;33import org.mockito.matchers.AnyVarargMatcher;34import org.mockito.matchers.VarargMatcherAdapter;35import org.mockito.quality.Strictness;36import org.mockito.stubbing.Answer;37import org.mockito.stubbing.OngoingStubbing;38import org.mockito.stubbing.Stubber;39import org.mockito.verification.VerificationMode;40import org.mockito.verification.VerificationWithTimeout;41import org.mockito.verification.VerificationWithTimeoutMode;42import org.mockito.verification.VerificationWithTimeoutModeProvider;43import org.mockito.verification.VerificationWithTimeoutProvider;44import org.mockito.verification.VerificationWithTimeoutProviderImpl;45import org.mockito.verification.Verifier;46import org.mockito.verification.VerifierProvider;47import org.mockito.verification.VerifierProviderImpl;48import org.mockito.verification.VerifierWithTimeout;49import org.mockito.verification.VerifierWithTimeoutProvider;50import org.mockito.verification.VerifierWithTimeoutProviderImpl;

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import org.mockito.internal.matchers.Any;4import org.mockito.internal.matchers.AnyVararg;5import org.mockito.internal.matchers.CapturingMatcher;6import org.mockito.internal.matchers.Equals;7import org.mockito.internal.matchers.InstanceOf;8import org.mockito.internal.matchers.Not;9import org.mockito.internal.matchers.Same;10import org.mockito.internal.matchers.VarargMatcher;11import org.mockito.internal.matchers.apachecommons.ReflectionEquals;12import org.mockito.internal.matchers.text.ValuePrinter;13import org.mockito.internal.util.Primitives;14import org.mockito.internal.util.StringUtil;15import org.mockito.internal.util.collections.ListUtil;16import org.mockito.internal.util.collections.Sets;17import org.mockito.internal.util.reflection.Fields;18import org.mockito.internal.util.reflection.LenientCopyTool;19import org.mockito.internal.util.reflection.LenientSetter;20import org.mockito.internal.util.reflection.LenientUnmockedChecker;21import org.mockito.internal.util.reflection.LenientWrapper;22import org.mockito.internal.util.reflection.ParameterizedTypeImpl;23import org.mockito.internal.util.reflection.SerializableMode;24import org.mockito.internal.util.reflection.WhiteboxImpl;25import org.mockito.internal.util.reflection.WildcardTypeImpl;26import org.mockito.invocation.InvocationOnMock;27import org.mockito.listeners.InvocationListener;28import org.mockito.listeners.MethodInvocationReport;29import org.mockito.listeners.StubbingLookupEvent;30import org.mockito.listeners.StubbingLookupListener;31import org.mockito.listeners.VerificationStartedEvent;32import org.mockito.listeners.VerificationStartedListener;33import org.mockito.matchers.AnyVarargMatcher;34import org.mockito.matchers.VarargMatcherAdapter;35import org.mockito.quality.Strictness;36import org.mockito.stubbing.Answer;37import org.mockito.stubbing.OngoingStubbing;38import org.mockito.stubbing.Stubber;39import org.mockito.verification.VerificationMode;40import org.mockito.verification.VerificationWithTimeout;41import org.mockito.verification.VerificationWithTimeoutMode;42import org.mockito.verification.VerificationWithTimeoutModeProvider;43import org.mockito.verification.VerificationWithTimeoutProvider;44import org.mockito.verification.VerificationWithTimeoutProviderImpl;45import org.mockito.verification.Verifier;46import org.mockito.verification.VerifierProvider;47import org.mockito.verification.VerifierProviderImpl;48import org.mockito.verification.VerifierWithTimeout;49import org.mockito.verification.VerifierWithTimeoutProvider;50import org.mockito.verification.VerifierWithTimeoutProviderImpl;

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.any;2import java.util.List;3import org.mockito.ArgumentMatchers;4public class MockitoArgumentMatchersTest {5 public static void main(String[] args) {6 List<String> mock = mock(List.class);7 when(mock.add(any(String.class))).thenReturn(true);8 when(mock.add(ArgumentMatchers.any(String.class))).thenReturn(true);9 when(mock.add(org.mockito.ArgumentMatchers.any(String.class))).thenReturn(true);10 }11}

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import java.util.List;4import java.util.ArrayList;5public class 1 {6 public static void main(String[] args) {7 List mockList = Mockito.mock(List.class);8 Mockito.when(mockList.get(Mockito.anyInt())).thenReturn("foo");9 System.out.println(mockList.get(1));10 System.out.println(mockList.get(2));11 System.out.println(mockList.get(3));12 Mockito.when(mockList.get(Mockito.anyInt())).thenReturn("bar");13 System.out.println(mockList.get(4));14 System.out.println(mockList.get(5));15 System.out.println(mockList.get(6));16 }17}18import java.util.List;19import java.util.ArrayList;20import org.mockito.ArgumentMatchers;21import org.mockito.Mockito;22public class 2 {23 public static void main(String[] args) {24 List mockList = Mockito.mock(List.class);25 Mockito.when(mockList.get(Mockito.anyInt())).thenReturn("foo");26 System.out.println(mockList.get(1));27 System.out.println(mockList.get(2));28 System.out.println(mockList.get(3));29 Mockito.when(mockList.get(Mockito.anyInt())).thenReturn("bar");30 System.out.println(mockList.get(4));31 System.out.println(mockList.get(5));32 System.out.println(mockList.get(6));33 Mockito.when(mockList.get(Mockito.anyInt())).thenReturn("baz");34 System.out.println(mockList.get(7));

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.mockito;2import static org.mockito.Mockito.*;3import org.junit.Test;4import org.mockito.ArgumentMatchers;5public class MockitoArgumentMatchersTest {6 public void testArgumentMatchers() {7 Foo foo = mock(Foo.class);8 when(foo.doSomething(ArgumentMatchers.anyInt())).thenReturn("Hello");9 foo.doSomething(1);10 verify(foo).doSomething(ArgumentMatchers.anyInt());11 }12}13package com.automationrhapsody.mockito;14public class Foo {15 public String doSomething(int i) {16 throw new UnsupportedOperationException();17 }18}19Argument(s) are different! Wanted:20foo.doSomething(21 anyInt()22);23-> at com.automationrhapsody.mockito.MockitoArgumentMatchersTest.testArgumentMatchers(MockitoArgumentMatchersTest.java:20)24foo.doSomething(25);26-> at com.automationrhapsody.mockito.Foo.doSomething(Foo.java:9)27package com.automationrhapsody.mockito;28import static org.mockito.Mockito.*;29import org.junit.Test;30import org.mockito.ArgumentMatchers;31public class MockitoArgumentMatchersTest {32 public void testArgumentMatchers() {33 Foo foo = mock(Foo.class);34 when(foo.doSomething(ArgumentMatchers.anyInt())).thenReturn("Hello");35 foo.doSomething(1);36 verify(foo).doSomething(ArgumentMatchers.anyInt());37 }38}39package com.automationrhapsody.mockito;40public class Foo {41 public String doSomething(int i) {42 throw new UnsupportedOperationException();43 }44}45Argument(s) are different! Wanted:46foo.doSomething(47 anyInt()48);49-> at com.automationrhapsody.mockito.MockitoArgumentMatchersTest.testArgumentMatchers(MockitoArgumentMatchersTest.java:20)50foo.doSomething(51 System.out.println(mockList.get(8));52 System.out.println(mockList.get(9));53 }54}55We are using the when() method of the org.mockito.Mockito class to return the “bar”

Full Screen

Full Screen

same

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.mockito;2import static org.mockito.Mockito.*;3import org.junit.Test;4import org.mockito.ArgumentMatchers;5public class MockitoArgumentMatchersTest {6 public void testArgumentMatchers() {7 Foo foo = mock(Foo.class);8 when(foo.doSomething(ArgumentMatchers.anyInt())).thenReturn("Hello");9 foo.doSomething(1);10 verify(foo).doSomething(ArgumentMatchers.anyInt());11 }12}13package com.automationrhapsody.mockito;14public class Foo {15 public String doSomething(int i) {16 throw new UnsupportedOperationException();17 }18}19Argument(s) are different! Wanted:20foo.doSomething(21 anyInt()22);23-> at com.automationrhapsody.mockito.MockitoArgumentMatchersTest.testArgumentMatchers(MockitoArgumentMatchersTest.java:20)24foo.doSomething(25);26-> at com.automationrhapsody.mockito.Foo.doSomething(Foo.java:9)27package com.automationrhapsody.mockito;28import static org.mockito.Mockito.*;29import org.junit.Test;30import org.mockito.ArgumentMatchers;31public class MockitoArgumentMatchersTest {32 public void testArgumentMatchers() {33 Foo foo = mock(Foo.class);34 when(foo.doSomething(ArgumentMatchers.anyInt())).thenReturn("Hello");35 foo.doSomething(1);36 verify(foo).doSomething(ArgumentMatchers.anyInt());37 }38}39package com.automationrhapsody.mockito;40public class Foo {41 public String doSomething(int i) {42 throw new UnsupportedOperationException();43 }44}45Argument(s) are different! Wanted:46foo.doSomething(47 anyInt()48);49-> at com.automationrhapsody.mockito.MockitoArgumentMatchersTest.testArgumentMatchers(MockitoArgumentMatchersTest.java:20)50foo.doSomething(

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful