From 52445a23cd8c93b0c8ab1eab786a29deefcd6114 Mon Sep 17 00:00:00 2001 From: Ravi Nadahar Date: Sun, 12 Oct 2025 16:46:56 +0200 Subject: [PATCH] Fix discovery tests to accommodate https://github.com/openhab/openhab-core/pull/5032 Signed-off-by: Ravi Nadahar --- .../discovery/HomeAssistantDiscoveryTests.java | 14 +++++++++----- .../TPLinkSmartHomeDiscoveryServiceTest.java | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscoveryTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscoveryTests.java index 97afda45b2e62..166c0b3e5f585 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscoveryTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscoveryTests.java @@ -14,6 +14,7 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Instant; import java.util.ArrayList; @@ -72,7 +73,7 @@ public void testOneThingDiscovery() throws Exception { getResourceAsByteArray("component/configTS0601AutoLock.json")); // Then one thing found - assert latch.await(3, TimeUnit.SECONDS); + assertTrue(latch.await(3, TimeUnit.SECONDS)); var discoveryResults = discoveryListener.getDiscoveryResults(); assertThat(discoveryResults.size(), is(1)); var result = discoveryResults.get(0); @@ -99,7 +100,7 @@ public void testComponentAddedToExistingThing() throws Exception { getResourceAsByteArray("component/configTS0601ClimateThermostat.json")); // Then one thing found - assert latch.await(3, TimeUnit.SECONDS); + assertTrue(latch.await(3, TimeUnit.SECONDS)); var discoveryResults = discoveryListener.getDiscoveryResults(); assertThat(discoveryResults.size(), is(1)); var result = discoveryResults.get(0); @@ -119,7 +120,7 @@ public void testComponentAddedToExistingThing() throws Exception { "homeassistant/switch/0x847127fffe11dd6a_auto_lock_zigbee2mqtt/config", getResourceAsByteArray("component/configTS0601AutoLock.json")); - assert latch.await(3, TimeUnit.SECONDS); + assertTrue(latch.await(3, TimeUnit.SECONDS)); discoveryResults = discoveryListener.getDiscoveryResults(); assertThat(discoveryResults.size(), is(1)); result = discoveryResults.get(0); @@ -149,7 +150,7 @@ public void testComponentRemovedFromExistingThing() throws Exception { getResourceAsByteArray("component/configTS0601AutoLock.json")); // Then one thing found - assert latch.await(4, TimeUnit.SECONDS); + assertTrue(latch.await(4, TimeUnit.SECONDS)); var discoveryResults = discoveryListener.getDiscoveryResults(); assertThat(discoveryResults.size(), is(1)); var result = discoveryResults.get(0); @@ -168,7 +169,7 @@ public void testComponentRemovedFromExistingThing() throws Exception { discovery.topicVanished(HA_UID, bridgeConnection, "homeassistant/switch/0x847127fffe11dd6a_auto_lock_zigbee2mqtt/config"); - assert latch.await(3, TimeUnit.SECONDS); + assertTrue(latch.await(3, TimeUnit.SECONDS)); discoveryResults = discoveryListener.getDiscoveryResults(); assertThat(discoveryResults.size(), is(1)); result = discoveryResults.get(0); @@ -204,6 +205,9 @@ public void thingDiscovered(DiscoveryService source, DiscoveryResult result) { @Override public void thingRemoved(DiscoveryService source, ThingUID thingUID) { + if (latch != null) { + latch.countDown(); + } } @Override diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/test/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeDiscoveryServiceTest.java b/bundles/org.openhab.binding.tplinksmarthome/src/test/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeDiscoveryServiceTest.java index 1c6b254fddb1c..a6e802357da18 100644 --- a/bundles/org.openhab.binding.tplinksmarthome/src/test/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeDiscoveryServiceTest.java +++ b/bundles/org.openhab.binding.tplinksmarthome/src/test/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeDiscoveryServiceTest.java @@ -91,7 +91,7 @@ public void testScan(String filename, int propertiesSize) throws IOException { setUp(filename); discoveryService.startScan(); ArgumentCaptor discoveryResultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class); - verify(discoveryListener).thingDiscovered(any(), discoveryResultCaptor.capture()); + verify(discoveryListener, timeout(1000L)).thingDiscovered(any(), discoveryResultCaptor.capture()); DiscoveryResult discoveryResult = discoveryResultCaptor.getValue(); assertEquals(TPLinkSmartHomeBindingConstants.BINDING_ID, discoveryResult.getBindingId(), "Check if correct binding id found");