]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hue] Improve HueBridgeHandlerOSGiTest stability (#8621)
authorWouter Born <github@maindrain.net>
Thu, 1 Oct 2020 10:19:51 +0000 (12:19 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Oct 2020 10:19:51 +0000 (12:19 +0200)
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>
itests/org.openhab.binding.hue.tests/itest.bndrun
itests/org.openhab.binding.hue.tests/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandlerOSGiTest.java

index 230f7bcda8c4109f64e44f6cdfe82fa614b9a7bd..f07fb47f10ca0d6278a54a0213fe16f5c1ba7385 100644 (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)'
index 5a76b1deb60f1d6518dab9367227a21f4ebef15e..c0c9c121f77e70270b6e6868ff41b6b805ac93b2 100644 (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;
     }