From 515658de7f64682084a6d9c0cca85d1ff5f8e16e Mon Sep 17 00:00:00 2001 From: Connor Petty Date: Wed, 30 Sep 2020 22:53:48 -0700 Subject: [PATCH] Fix bluetooth unit tests (#8620) Fixes: #8538 Signed-off-by: Connor Petty --- .../discovery/internal/BluetoothDiscoveryService.java | 4 ++++ .../java/org/openhab/binding/bluetooth/TestUtils.java | 2 +- .../discovery/internal/BluetoothDiscoveryServiceTest.java | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java index 91acacc91d..da64eb3c47 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java @@ -267,6 +267,10 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen future = future.thenApply(result -> { publishDiscoveryResult(adapter, result); return result; + }).whenComplete((r, t) -> { + if (t != null) { + logger.warn("Error occured during discovery of {}", device.getAddress(), t); + } }); // now save this snapshot for later diff --git a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/TestUtils.java b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/TestUtils.java index fcb926d9ff..8308f59bf9 100644 --- a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/TestUtils.java +++ b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/TestUtils.java @@ -35,6 +35,6 @@ public class TestUtils { } public static ThingUID randomThingUID() { - return new ThingUID("mock", RandomStringUtils.randomAlphabetic(6)); + return new ThingUID(BluetoothBindingConstants.BINDING_ID, RandomStringUtils.randomAlphabetic(6)); } } 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 07b8516820..9d51898a44 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 @@ -28,7 +28,6 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; @@ -66,7 +65,6 @@ import org.slf4j.LoggerFactory; @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) @NonNullByDefault -@Disabled("Needs to be updated for OH3") public class BluetoothDiscoveryServiceTest { private static final int TIMEOUT = 2000; @@ -541,7 +539,8 @@ public class BluetoothDiscoveryServiceTest { private ThingTypeUID typeUID; public MockDiscoveryParticipant() { - this.typeUID = new ThingTypeUID("mock", RandomStringUtils.randomAlphabetic(6)); + this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, + RandomStringUtils.randomAlphabetic(6)); } @Override @@ -551,8 +550,9 @@ public class BluetoothDiscoveryServiceTest { @Override public @Nullable DiscoveryResult createResult(BluetoothDiscoveryDevice device) { + String repProp = RandomStringUtils.randomAlphabetic(6); return DiscoveryResultBuilder.create(getThingUID(device)).withLabel(RandomStringUtils.randomAlphabetic(6)) - .withRepresentationProperty(RandomStringUtils.randomAlphabetic(6)) + .withProperty(repProp, RandomStringUtils.randomAlphabetic(6)).withRepresentationProperty(repProp) .withBridge(device.getAdapter().getUID()).build(); } -- 2.47.3