[hue] Improve HueBridgeHandlerOSGiTest stability (#8621)

The ThingStatus is updated asynchronously so the test is unstable when the status is not updated immediately.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2020-10-01 12:19:51 +02:00 committed by GitHub
parent 515658de7f
commit 1b0876f719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -67,4 +67,5 @@ Fragment-Host: org.openhab.binding.hue
org.openhab.core.test;version='[3.0.0,3.0.1)',\
org.openhab.core.thing;version='[3.0.0,3.0.1)',\
org.openhab.core.thing.xml;version='[3.0.0,3.0.1)',\
org.opentest4j;version='[1.2.0,1.2.1)'
org.opentest4j;version='[1.2.0,1.2.1)',\
org.eclipse.jdt.annotation;version='[2.2.100,2.2.101)'

View File

@ -12,6 +12,7 @@
*/
package org.openhab.binding.hue.internal.handler;
import static org.eclipse.jdt.annotation.Checks.requireNonNull;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@ -50,7 +51,7 @@ import org.openhab.core.thing.ThingUID;
*/
public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
private final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "bridge");
private static final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "bridge");
private static final String TEST_USER_NAME = "eshTestUser";
private static final String DUMMY_HOST = "1.2.3.4";
@ -132,7 +133,7 @@ public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
hueBridgeHandler.onNotAuthenticated();
assertEquals("notAuthenticatedUser", bridge.getConfiguration().get(USER_NAME));
assertEquals(ThingStatus.OFFLINE, bridge.getStatus());
waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, bridge.getStatus()));
assertEquals(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, bridge.getStatusInfo().getStatusDetail());
}
@ -156,7 +157,7 @@ public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
hueBridgeHandler.onNotAuthenticated();
assertNull(bridge.getConfiguration().get(USER_NAME));
assertEquals(ThingStatus.OFFLINE, bridge.getStatus());
waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, bridge.getStatus()));
assertEquals(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, bridge.getStatusInfo().getStatusDetail());
}
@ -180,7 +181,7 @@ public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
hueBridgeHandler.onNotAuthenticated();
assertNull(bridge.getConfiguration().get(USER_NAME));
assertEquals(ThingStatus.OFFLINE, bridge.getStatus());
waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, bridge.getStatus()));
assertEquals(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, bridge.getStatusInfo().getStatusDetail());
}
@ -196,7 +197,7 @@ public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
hueBridgeHandler.onConnectionLost();
assertEquals(ThingStatus.OFFLINE, bridge.getStatus());
waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, bridge.getStatus()));
assertNotEquals(ThingStatusDetail.BRIDGE_OFFLINE, bridge.getStatusInfo().getStatusDetail());
}
@ -236,7 +237,7 @@ public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
Bridge bridge = (Bridge) thingRegistry.createThingOfType(BRIDGE_THING_TYPE_UID,
new ThingUID(BRIDGE_THING_TYPE_UID, "testBridge"), null, "Bridge", configuration);
assertNotNull(bridge);
bridge = requireNonNull(bridge, "Bridge is null");
thingRegistry.add(bridge);
return bridge;
}