From dd04d2eca0601ad9a11d8bf1cd29d92a187e5e12 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Sun, 30 Aug 2020 17:37:55 +0200 Subject: [PATCH] Added unit test for unset thing properties (#1615) Signed-off-by: Christoph Weitkamp --- .../binding/BindingBaseClassesOSGiTest.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java index 1ef8a0c3bb..190f62d8fa 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java @@ -445,14 +445,14 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { updateConfiguration(configuration); } - public void updateProperties() { + public void updateProperties(String value) { Map properties = editProperties(); - properties.put(Thing.PROPERTY_MODEL_ID, "1234"); + properties.put(Thing.PROPERTY_MODEL_ID, value); updateProperties(properties); } - public void updateProperty() { - updateProperty(Thing.PROPERTY_VENDOR, "vendor"); + public void updateProperty(String value) { + updateProperty(Thing.PROPERTY_VENDOR, value); } } @@ -533,13 +533,25 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_MODEL_ID), is(nullValue())); assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_VENDOR), is(nullValue())); - ((YetAnotherThingHandler) listener.getThing().getHandler()).updateProperties(); + // set properties + String modelId = "1234"; + ((YetAnotherThingHandler) listener.getThing().getHandler()).updateProperties(modelId); - assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_MODEL_ID), is("1234")); + assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_MODEL_ID), is(modelId)); - ((YetAnotherThingHandler) listener.getThing().getHandler()).updateProperty(); + String vendor = "vendor"; + ((YetAnotherThingHandler) listener.getThing().getHandler()).updateProperty(vendor); - assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_VENDOR), is("vendor")); + assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_VENDOR), is(vendor)); + + // unset properties + ((YetAnotherThingHandler) listener.getThing().getHandler()).updateProperties((String) null); + + assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_MODEL_ID), is(nullValue())); + + ((YetAnotherThingHandler) listener.getThing().getHandler()).updateProperty(null); + + assertThat(listener.getThing().getProperties().get(Thing.PROPERTY_VENDOR), is(nullValue())); } finally { thingRegistry.removeRegistryChangeListener(listener); }