Skip to content

Commit 52445a2

Browse files
author
Ravi Nadahar
committed
Fix discovery tests to accommodate openhab/openhab-core#5032
Signed-off-by: Ravi Nadahar <[email protected]>
1 parent 32a7c33 commit 52445a2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscoveryTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.hamcrest.CoreMatchers.*;
1616
import static org.hamcrest.MatcherAssert.assertThat;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
1718

1819
import java.time.Instant;
1920
import java.util.ArrayList;
@@ -72,7 +73,7 @@ public void testOneThingDiscovery() throws Exception {
7273
getResourceAsByteArray("component/configTS0601AutoLock.json"));
7374

7475
// Then one thing found
75-
assert latch.await(3, TimeUnit.SECONDS);
76+
assertTrue(latch.await(3, TimeUnit.SECONDS));
7677
var discoveryResults = discoveryListener.getDiscoveryResults();
7778
assertThat(discoveryResults.size(), is(1));
7879
var result = discoveryResults.get(0);
@@ -99,7 +100,7 @@ public void testComponentAddedToExistingThing() throws Exception {
99100
getResourceAsByteArray("component/configTS0601ClimateThermostat.json"));
100101

101102
// Then one thing found
102-
assert latch.await(3, TimeUnit.SECONDS);
103+
assertTrue(latch.await(3, TimeUnit.SECONDS));
103104
var discoveryResults = discoveryListener.getDiscoveryResults();
104105
assertThat(discoveryResults.size(), is(1));
105106
var result = discoveryResults.get(0);
@@ -119,7 +120,7 @@ public void testComponentAddedToExistingThing() throws Exception {
119120
"homeassistant/switch/0x847127fffe11dd6a_auto_lock_zigbee2mqtt/config",
120121
getResourceAsByteArray("component/configTS0601AutoLock.json"));
121122

122-
assert latch.await(3, TimeUnit.SECONDS);
123+
assertTrue(latch.await(3, TimeUnit.SECONDS));
123124
discoveryResults = discoveryListener.getDiscoveryResults();
124125
assertThat(discoveryResults.size(), is(1));
125126
result = discoveryResults.get(0);
@@ -149,7 +150,7 @@ public void testComponentRemovedFromExistingThing() throws Exception {
149150
getResourceAsByteArray("component/configTS0601AutoLock.json"));
150151

151152
// Then one thing found
152-
assert latch.await(4, TimeUnit.SECONDS);
153+
assertTrue(latch.await(4, TimeUnit.SECONDS));
153154
var discoveryResults = discoveryListener.getDiscoveryResults();
154155
assertThat(discoveryResults.size(), is(1));
155156
var result = discoveryResults.get(0);
@@ -168,7 +169,7 @@ public void testComponentRemovedFromExistingThing() throws Exception {
168169
discovery.topicVanished(HA_UID, bridgeConnection,
169170
"homeassistant/switch/0x847127fffe11dd6a_auto_lock_zigbee2mqtt/config");
170171

171-
assert latch.await(3, TimeUnit.SECONDS);
172+
assertTrue(latch.await(3, TimeUnit.SECONDS));
172173
discoveryResults = discoveryListener.getDiscoveryResults();
173174
assertThat(discoveryResults.size(), is(1));
174175
result = discoveryResults.get(0);
@@ -204,6 +205,9 @@ public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
204205

205206
@Override
206207
public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
208+
if (latch != null) {
209+
latch.countDown();
210+
}
207211
}
208212

209213
@Override

bundles/org.openhab.binding.tplinksmarthome/src/test/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeDiscoveryServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void testScan(String filename, int propertiesSize) throws IOException {
9191
setUp(filename);
9292
discoveryService.startScan();
9393
ArgumentCaptor<DiscoveryResult> discoveryResultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class);
94-
verify(discoveryListener).thingDiscovered(any(), discoveryResultCaptor.capture());
94+
verify(discoveryListener, timeout(1000L)).thingDiscovered(any(), discoveryResultCaptor.capture());
9595
DiscoveryResult discoveryResult = discoveryResultCaptor.getValue();
9696
assertEquals(TPLinkSmartHomeBindingConstants.BINDING_ID, discoveryResult.getBindingId(),
9797
"Check if correct binding id found");

0 commit comments

Comments
 (0)