From 54ca61263007687db5bbbe8c9b9e1be5997c8833 Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Tue, 22 Dec 2020 20:31:04 +0100 Subject: [PATCH] [danfossairunit] Try to make tests more stable (#9473) Signed-off-by: Fabian Wolter --- .../internal/ValueCacheTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.danfossairunit/src/test/java/org/openhab/binding/danfossairunit/internal/ValueCacheTest.java b/bundles/org.openhab.binding.danfossairunit/src/test/java/org/openhab/binding/danfossairunit/internal/ValueCacheTest.java index eb8d5962539..5192a9cd5c5 100644 --- a/bundles/org.openhab.binding.danfossairunit/src/test/java/org/openhab/binding/danfossairunit/internal/ValueCacheTest.java +++ b/bundles/org.openhab.binding.danfossairunit/src/test/java/org/openhab/binding/danfossairunit/internal/ValueCacheTest.java @@ -17,12 +17,13 @@ import static org.junit.jupiter.api.Assertions.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; import org.openhab.core.library.types.OnOffType; +import org.openhab.core.test.java.JavaTest; /** * @author Robert Bach - Initial contribution */ @NonNullByDefault -public class ValueCacheTest { +public class ValueCacheTest extends JavaTest { @Test public void updateValueNotInCache() { @@ -45,20 +46,17 @@ public class ValueCacheTest { } @Test - public void updateValueInCacheUnchangedButCacheDurationExpired() throws InterruptedException { + public void updateValueInCacheUnchangedButCacheDurationExpired() { ValueCache valueCache = new ValueCache(1); assertTrue(valueCache.updateValue("channel", OnOffType.ON)); - Thread.sleep(2); - assertTrue(valueCache.updateValue("channel", OnOffType.ON)); + waitForAssert(() -> assertTrue(valueCache.updateValue("channel", OnOffType.ON))); } @Test - public void updateValueMultipleCacheUpdatesButNotReportedAsToUpdate() throws InterruptedException { - ValueCache valueCache = new ValueCache(60); - assertTrue(valueCache.updateValue("channel", OnOffType.ON)); - Thread.sleep(30); - assertFalse(valueCache.updateValue("channel", OnOffType.ON)); - Thread.sleep(35); + public void updateValueMultipleCacheUpdatesButNotReportedAsToUpdate() { + ValueCache valueCache = new ValueCache(100); assertTrue(valueCache.updateValue("channel", OnOffType.ON)); + waitForAssert(() -> assertFalse(valueCache.updateValue("channel", OnOffType.ON))); + waitForAssert(() -> assertTrue(valueCache.updateValue("channel", OnOffType.ON))); } }