From 0f2080110060d5bdb1deeb303c3931c49b6c532b Mon Sep 17 00:00:00 2001 From: lolodomo Date: Tue, 9 Jun 2020 22:00:30 +0200 Subject: [PATCH] [astro] Method renamed (relative to TimeZoneProvider) (#7877) * [astro] Method renamed (relative to TimeZoneProvider) * Fix the integration tests broken by a previous PR Signed-off-by: Laurent Garnier Signed-off-by: Daan Meijer --- .../astro/internal/AstroHandlerFactory.java | 5 ++-- .../internal/config/AstroThingConfig.java | 13 +-------- .../astro/internal/util/PropertyUtils.java | 8 ++--- .../test/AstroValidConfigurationTest.java | 29 ++++++++++--------- .../binding/astro/test/AstroStateTest.java | 4 +-- 5 files changed, 22 insertions(+), 37 deletions(-) diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/AstroHandlerFactory.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/AstroHandlerFactory.java index ce6886a1db0f1..130b950136f77 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/AstroHandlerFactory.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/AstroHandlerFactory.java @@ -53,9 +53,10 @@ public class AstroHandlerFactory extends BaseThingHandlerFactory { private final CronScheduler scheduler; @Activate - public AstroHandlerFactory(final @Reference CronScheduler scheduler, final @Reference TimeZoneProvider timeZone) { + public AstroHandlerFactory(final @Reference CronScheduler scheduler, + final @Reference TimeZoneProvider timeZoneProvider) { this.scheduler = scheduler; - PropertyUtils.setTimeZone(timeZone); + PropertyUtils.setTimeZoneProvider(timeZoneProvider); } @Override diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/config/AstroThingConfig.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/config/AstroThingConfig.java index 64974f682e2d7..dbe71a7d533ce 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/config/AstroThingConfig.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/config/AstroThingConfig.java @@ -12,10 +12,6 @@ */ package org.openhab.binding.astro.internal.config; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.TimeZone; - import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; @@ -68,15 +64,8 @@ public void setThingUid(String thingUid) { @Override public String toString() { - TimeZone tz = TimeZone.getDefault(); - StringBuilder tzInfo = new StringBuilder(); - tzInfo.append(tz.getID()); - tzInfo.append(" (").append(tz.getDisplayName(false, TimeZone.SHORT)).append(" ") - .append(new SimpleDateFormat("Z").format(Calendar.getInstance().getTime())); - tzInfo.append(")"); return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("thing", thingUid) .append("geolocation", geolocation).append("altitude", altitude).append("interval", interval) - .append("systemTimezone", tzInfo.toString()) - .append("daylightSavings", Calendar.getInstance().get(Calendar.DST_OFFSET) != 0).toString(); + .toString(); } } diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java index e8e22439d7ee7..d357663d856e0 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java @@ -71,12 +71,8 @@ public static State getState(ChannelUID channelUID, AstroChannelConfig config, O } } - public static void setTimeZone(TimeZoneProvider zone) { - PropertyUtils.timeZoneProvider = zone; - } - - public static void unsetTimeZone() { - PropertyUtils.timeZoneProvider = null; + public static void setTimeZoneProvider(TimeZoneProvider timeZoneProvider) { + PropertyUtils.timeZoneProvider = timeZoneProvider; } /** diff --git a/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/handler/test/AstroValidConfigurationTest.java b/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/handler/test/AstroValidConfigurationTest.java index b34899ab6f8c6..93a6e48431391 100644 --- a/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/handler/test/AstroValidConfigurationTest.java +++ b/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/handler/test/AstroValidConfigurationTest.java @@ -48,7 +48,7 @@ public void testIfGeolocationIsProvidedForASunThing_theThingStatusBecomesONLINE( Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE); - assertThingStatus(thingConfiguration, ThingStatus.ONLINE); + assertThingStatus(thingConfiguration, ThingStatus.ONLINE, ThingStatusDetail.NONE); } @Test @@ -56,49 +56,49 @@ public void testIfGeolocationIsProvidedForAMoonThing_theThingStatusBecomesONLINE Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE); - assertThingStatus(thingConfiguration, ThingStatus.ONLINE); + assertThingStatus(thingConfiguration, ThingStatus.ONLINE, ThingStatusDetail.NONE); } @Test public void testIfGeolocationForASunThingIsNull_theThingStatusBecomesOFFLINE() { Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, null); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test public void testIfGeolocationForAMoonThingIsNull_theThingStatusBecomesOFFLINE() { Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, null); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test public void testIfTheLatitudeForASunThingIsNull_theThingStatusBecomesOFFLINE() { Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LATITUDE); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test public void testIfTheLatitudeForAMoonThingIsNull_theThingStatusBecomesOFFLINE() { Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LATITUDE); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test public void testIfTheLongitudeForASunThingIsNull_theThingStatusBecomesOFFLINE() { Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LONGITUDE); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test public void testIfTheLongitudeForAMoonThingIsNull_theThingStatusBecomesOFFLINE() { Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LONGITUDE); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test @@ -106,7 +106,7 @@ public void testIfTheIntervalForASunThingIsLessThan1_theThingStatusBecomesOFFLIN Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(INTERVAL_PROPERTY, new Integer(0)); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test @@ -114,7 +114,7 @@ public void testIfTheIntervalForAMoonThingIsLessThan1_theThingStatusBecomesOFFLI Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(INTERVAL_PROPERTY, new Integer(0)); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test @@ -122,7 +122,7 @@ public void testIfTheIntervalForASunThingIsGreaterThan86400_theThingStatusBecome Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(INTERVAL_PROPERTY, new Integer(86401)); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } @Test @@ -130,10 +130,11 @@ public void testIfTheIntervalForAMoonThingIsGreaterThan86400_theThingStatusBecom Configuration thingConfiguration = new Configuration(); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(INTERVAL_PROPERTY, new Integer(86401)); - assertThingStatus(thingConfiguration, ThingStatus.OFFLINE); + assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); } - private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus) { + private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus, + ThingStatusDetail expectedStatusDetail) { ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID); Thing thing = mock(Thing.class); @@ -147,7 +148,7 @@ private void assertThingStatus(Configuration configuration, ThingStatus expected sunHandler.initialize(); - ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, ThingStatusDetail.NONE, null); + ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, expectedStatusDetail, null); verify(callback, times(1)).statusUpdated(thing, expectedThingStatus); } } diff --git a/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/test/AstroStateTest.java b/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/test/AstroStateTest.java index 95975832d8404..0a6722d1b055d 100644 --- a/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/test/AstroStateTest.java +++ b/itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/test/AstroStateTest.java @@ -72,10 +72,8 @@ public static List data() { @Test public void testParametrized() { - PropertyUtils.unsetTimeZone(); - // Anonymous implementation of the service to adapt the time zone to the tested longitude and latitude - PropertyUtils.setTimeZone(new TimeZoneProvider() { + PropertyUtils.setTimeZoneProvider(new TimeZoneProvider() { @Override public ZoneId getTimeZone() { return ZONE_ID;