From 675bddafa550552f43294c195ffc55126c0a4e47 Mon Sep 17 00:00:00 2001 From: cpmeister Date: Sat, 18 Apr 2020 01:27:28 -0700 Subject: [PATCH] [bluetooth] Removed usage of deprecated method in tests (#7405) Signed-off-by: Connor Petty --- .../BluetoothDiscoveryServiceTest.java | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java index 0525da81db2d8..62b392dbebb2f 100644 --- a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java +++ b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java @@ -300,9 +300,17 @@ public void removeDefaultDeviceTest() { discoveryService.deviceDiscovered(device); discoveryService.deviceRemoved(device); + ArgumentCaptor resultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class); Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)) - .thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers - .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON))); + .thingDiscovered(ArgumentMatchers.same(discoveryService), resultCaptor.capture()); + + DiscoveryResult result = resultCaptor.getValue(); + + Assert.assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID()); + + Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingRemoved( + ArgumentMatchers.same(discoveryService), + ArgumentMatchers.argThat(arg -> arg.equals(result.getThingUID()))); } @Test @@ -314,10 +322,19 @@ public void removeUpdatedDefaultDeviceTest() { device.setName("somename"); discoveryService.deviceDiscovered(device); + ArgumentCaptor resultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class); + Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)) + .thingDiscovered(ArgumentMatchers.same(discoveryService), resultCaptor.capture()); + + DiscoveryResult result = resultCaptor.getValue(); + + Assert.assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID()); + discoveryService.deviceRemoved(device); - Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)) - .thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers - .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON))); + + Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingRemoved( + ArgumentMatchers.same(discoveryService), + ArgumentMatchers.argThat(arg -> arg.equals(result.getThingUID()))); } @Test @@ -357,18 +374,22 @@ public void replaceOlderDiscoveryTest() { // lets start with producing a default result discoveryService.deviceDiscovered(device); + ArgumentCaptor resultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class); Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)) - .thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers - .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON))); + .thingDiscovered(ArgumentMatchers.same(discoveryService), resultCaptor.capture()); + + DiscoveryResult result = resultCaptor.getValue(); + + Assert.assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID()); device.setManufacturerId(10); // lets start with producing a default result discoveryService.deviceDiscovered(device); - Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)) - .thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers - .argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON))); + Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingRemoved( + ArgumentMatchers.same(discoveryService), + ArgumentMatchers.argThat(arg -> arg.equals(result.getThingUID()))); Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered( ArgumentMatchers.same(discoveryService),