]> git.basschouten.com Git - openhab-addons.git/commitdiff
Java 17 features (itests) (#15583)
authorHolger Friedrich <holgerfriedrich@users.noreply.github.com>
Wed, 13 Sep 2023 06:06:37 +0000 (08:06 +0200)
committerGitHub <noreply@github.com>
Wed, 13 Sep 2023 06:06:37 +0000 (08:06 +0200)
- replace Collections by List.of and Set.of
- instanceof
- SAT warnings

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
15 files changed:
itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/handler/test/AstroCommandTest.java
itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/handler/test/AstroValidConfigurationTest.java
itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/test/AstroStateTest.java
itests/org.openhab.binding.astro.tests/src/main/java/org/openhab/binding/astro/test/cases/AstroBindingTestsData.java
itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/config/ConfigFlowTest.java
itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/handler/AbstractMieleThingHandlerTest.java
itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/handler/MieleHandlerFactoryTest.java
itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/util/OpenHabOsgiTest.java
itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/AbstractModbusOSGiTest.java
itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/DiscoverComponentsTest.java
itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/HomeAssistantMQTTImplementationTest.java
itests/org.openhab.binding.mqtt.ruuvigateway.tests/src/main/java/org/openhab/binding/mqtt/ruuvigateway/RuuviGatewayTest.java
itests/org.openhab.binding.mqtt.ruuvigateway.tests/src/main/java/org/openhab/binding/mqtt/ruuvigateway/ThingStatusInfoChangedSubscriber.java
itests/org.openhab.binding.ntp.tests/src/main/java/org/openhab/binding/ntp/test/NtpOSGiTest.java
itests/org.openhab.binding.wemo.tests/src/main/java/org/openhab/binding/wemo/internal/discovery/test/WemoDiscoveryParticipantTest.java

index 60f25e700569287a20f6209d6a4743abf4c5a652..a7fdec32285c0867eec42543f74523fe4954f22b 100644 (file)
@@ -40,7 +40,7 @@ import org.openhab.core.types.State;
  * <p>
  * This class tests the commands for the astro thing.
  *
- * @author Petar Valchev - Initial implementation
+ * @author Petar Valchev - Initial contribution
  * @author Svilen Valkanov - Reworked to plain unit tests
  * @author Christoph Weitkamp - Migrated tests to pure Java
  */
index 0229f07fcbde34effd60418cad20dae5472e2e17..29d4ad7a902afdf56320f60de68c5bbc76cec478 100644 (file)
@@ -37,7 +37,7 @@ import org.openhab.core.thing.binding.ThingHandlerCallback;
  * <p>
  * This class tests the required configuration for the astro thing.
  *
- * @author Petar Valchev - Initial implementation
+ * @author Petar Valchev - Initial contribution
  * @author Svilen Valkanov - Reworked to plain unit tests, removed irrelevant tests
  * @author Christoph Weitkamp - Migrated tests to pure Java
  */
index e31b8a5d9c3d1ee9bec49f2571b3ab635628f094..e63119126dcd8d304978c3e08cd4ed9ff20f4bd1 100644 (file)
@@ -40,7 +40,7 @@ import org.openhab.core.types.State;
  * Tests for the Astro Channels state
  *
  * @See {@link AstroParametrizedTestCases}
- * @author Petar Valchev - Initial implementation
+ * @author Petar Valchev - Initial contribution
  * @author Svilen Valkanov - Reworked to plain unit tests
  * @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
  * @author Christoph Weitkamp - Migrated tests to pure Java
index 4ac648d5ada6aeaf3844d242c7417f9c512d87b8..d8acbeea4428bf3d4bab39485e9c04ed1e6de5bf 100644 (file)
@@ -17,7 +17,7 @@ import java.math.BigDecimal;
 /**
  * Contains some test data used across different tests
  *
- * @author Svilen Valkanov - Initial implementation
+ * @author Svilen Valkanov - Initial contribution
  * @author Christoph Weitkamp - Migrated tests to pure Java
  */
 public final class AstroBindingTestsData {
index 2a6c3e0baacfe903fbec17ac579c269387687fa1..417b723f5bc1d25bb7f399b27a25371908ad3bc2 100644 (file)
@@ -61,8 +61,8 @@ public class ConfigFlowTest extends AbstractConfigFlowTest {
             Thing bridge = getThingRegistry().get(MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID);
             assertNotNull(bridge);
             ThingHandler handler = bridge.getHandler();
-            if (handler instanceof MieleBridgeHandler) {
-                ((MieleBridgeHandler) handler).onConnectionAlive();
+            if (handler instanceof MieleBridgeHandler mieleBridgeHandler) {
+                mieleBridgeHandler.onConnectionAlive();
             }
             return null;
         }).when(webservice).addConnectionStatusListener(any());
index c29a9f15c3c5adbe8782fe5742b42434e6ea3b7d..0ae26d7e33ba15dd6f30b0050e5727b1efd6b143 100644 (file)
@@ -20,8 +20,8 @@ import static org.openhab.binding.mielecloud.internal.util.MieleCloudBindingInte
 import static org.openhab.binding.mielecloud.internal.util.ReflectionUtil.setPrivate;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 
@@ -181,9 +181,8 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
                 .create(MieleCloudBindingConstants.THING_TYPE_BRIDGE,
                         MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID)
                 .withLabel("Miele@home Account")
-                .withConfiguration(
-                        new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
-                                MieleCloudBindingIntegrationTestConstants.EMAIL)))
+                .withConfiguration(new Configuration(Map.of(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
+                        MieleCloudBindingIntegrationTestConstants.EMAIL)))
                 .build();
         assertNotNull(bridge);
 
@@ -216,8 +215,8 @@ public abstract class AbstractMieleThingHandlerTest extends JavaOSGiTest {
         List<Channel> channels = createChannelsForThingHandler(thingTypeUid, thingUid);
 
         Thing thing = ThingBuilder.create(thingTypeUid, thingUid)
-                .withConfiguration(new Configuration(Collections
-                        .singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER, deviceIdentifier)))
+                .withConfiguration(new Configuration(
+                        Map.of(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER, deviceIdentifier)))
                 .withBridge(getBridge().getUID()).withChannels(channels).withLabel("DA-6996")
                 .withProperty("thingTypeVersion", thingTypeVersion).build();
         assertNotNull(thing);
index ac7ed386a7451cab9940a2cd58d3b4e79c6a2a80..fbfe2a801ba8b7f4b419bb6dd766612845fbb991 100644 (file)
@@ -17,7 +17,7 @@ import static org.mockito.Mockito.*;
 import static org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants.*;
 import static org.openhab.binding.mielecloud.internal.util.ReflectionUtil.*;
 
-import java.util.Collections;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 
@@ -117,9 +117,8 @@ public class MieleHandlerFactoryTest extends JavaOSGiTest {
         Bridge bridge = BridgeBuilder
                 .create(MieleCloudBindingConstants.THING_TYPE_BRIDGE,
                         MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID)
-                .withConfiguration(
-                        new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
-                                MieleCloudBindingIntegrationTestConstants.EMAIL)))
+                .withConfiguration(new Configuration(Map.of(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
+                        MieleCloudBindingIntegrationTestConstants.EMAIL)))
                 .withLabel(MIELE_CLOUD_ACCOUNT_LABEL).build();
         assertNotNull(bridge);
 
@@ -141,9 +140,8 @@ public class MieleHandlerFactoryTest extends JavaOSGiTest {
         Bridge bridge = BridgeBuilder
                 .create(MieleCloudBindingConstants.THING_TYPE_BRIDGE,
                         MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID)
-                .withConfiguration(
-                        new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
-                                MieleCloudBindingIntegrationTestConstants.EMAIL)))
+                .withConfiguration(new Configuration(Map.of(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
+                        MieleCloudBindingIntegrationTestConstants.EMAIL)))
                 .withLabel(MIELE_CLOUD_ACCOUNT_LABEL).build();
         assertNotNull(bridge);
 
@@ -194,8 +192,8 @@ public class MieleHandlerFactoryTest extends JavaOSGiTest {
 
         // when:
         Thing device = ThingBuilder.create(thingTypeUid, thingUid)
-                .withConfiguration(new Configuration(Collections
-                        .singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER, DEVICE_IDENTIFIER)))
+                .withConfiguration(new Configuration(
+                        Map.of(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER, DEVICE_IDENTIFIER)))
                 .withLabel(label).withProperty("thingTypeVersion", thingTypeVersion).build();
 
         assertNotNull(device);
@@ -208,9 +206,8 @@ public class MieleHandlerFactoryTest extends JavaOSGiTest {
         Bridge bridge = BridgeBuilder
                 .create(MieleCloudBindingConstants.THING_TYPE_BRIDGE,
                         MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID)
-                .withConfiguration(
-                        new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
-                                MieleCloudBindingIntegrationTestConstants.EMAIL)))
+                .withConfiguration(new Configuration(Map.of(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
+                        MieleCloudBindingIntegrationTestConstants.EMAIL)))
                 .withLabel(MIELE_CLOUD_ACCOUNT_LABEL).build();
         assertNotNull(bridge);
 
index 046b70d7e082c0dda9e68500d8169586fb8868e5..9050416cdd21f861b0c2e3ca0c7b98b1408c7adb 100644 (file)
@@ -15,7 +15,7 @@ package org.openhab.binding.mielecloud.internal.util;
 import static org.junit.jupiter.api.Assertions.*;
 import static org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants.MIELE_CLOUD_ACCOUNT_LABEL;
 
-import java.util.Collections;
+import java.util.Map;
 import java.util.Objects;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -78,9 +78,8 @@ public abstract class OpenHabOsgiTest extends JavaOSGiTest {
         Bridge bridge = BridgeBuilder
                 .create(MieleCloudBindingConstants.THING_TYPE_BRIDGE,
                         MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID)
-                .withConfiguration(
-                        new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
-                                MieleCloudBindingIntegrationTestConstants.EMAIL)))
+                .withConfiguration(new Configuration(Map.of(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL,
+                        MieleCloudBindingIntegrationTestConstants.EMAIL)))
                 .withLabel(MIELE_CLOUD_ACCOUNT_LABEL).build();
         assertNotNull(bridge);
 
index 3aaa469ed5eeba3750cd43a8347c18e43d9563b9..f5d35deb03d6912ecbd7ef8df1000c8c97b2498f 100644 (file)
@@ -21,7 +21,6 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.*;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -96,7 +95,7 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
 
         @Override
         public Set<@NonNull String> getSubscribedEventTypes() {
-            return Collections.singleton(ItemStateEvent.TYPE);
+            return Set.of(ItemStateEvent.TYPE);
         }
 
         @Override
index 7959eb21ee424f9a11e45640e574a65b218ae3ca..e07e7cfde008a52b25d9c52e7fb4f5f452de95c3 100644 (file)
@@ -15,8 +15,8 @@ package org.openhab.binding.mqtt.homeassistant;
 import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
-import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
@@ -86,8 +86,7 @@ public class DiscoverComponentsTest extends JavaOSGiTest {
         DiscoverComponents discover = spy(new DiscoverComponents(ThingChannelConstants.TEST_HOME_ASSISTANT_THING,
                 scheduler, channelStateUpdateListener, availabilityTracker, gson, transformationServiceProvider));
 
-        HandlerConfiguration config = new HandlerConfiguration("homeassistant",
-                Collections.singletonList("switch/object"));
+        HandlerConfiguration config = new HandlerConfiguration("homeassistant", List.of("switch/object"));
 
         Set<HaID> discoveryIds = new HashSet<>();
         discoveryIds.addAll(HaID.fromConfig(config));
index 751dd3fe0bdda2516a0a12cf668fb26e1806744b..4bf6be8374ce37fda99ec9d5b75d644588389f30 100644 (file)
@@ -19,10 +19,10 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.*;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ScheduledExecutorService;
@@ -166,12 +166,11 @@ public class HomeAssistantMQTTImplementationTest extends MqttOSGiTest {
 
         // Start the discovery for 2000ms. Forced timeout after 4000ms.
         HaID haID = new HaID(testObjectTopic + "/config");
-        CompletableFuture<Void> future = discover.startDiscovery(haConnection, 2000, Collections.singleton(haID), cd)
-                .thenRun(() -> {
-                }).exceptionally(e -> {
-                    failure = e;
-                    return null;
-                });
+        CompletableFuture<Void> future = discover.startDiscovery(haConnection, 2000, Set.of(haID), cd).thenRun(() -> {
+        }).exceptionally(e -> {
+            failure = e;
+            return null;
+        });
 
         assertTrue(latch.await(4, TimeUnit.SECONDS));
         future.get(5, TimeUnit.SECONDS);
index 6022125724452b6195d1ac060df7f1010e6e9819..ad5d6fcf14ce12490c76293419aa2e609186b0a1 100644 (file)
@@ -385,9 +385,15 @@ public class RuuviGatewayTest extends MqttOSGiTest {
         } else {
             // test argument is only specifiying the data field in the json payload
             // Fill rest of the fields with some valid values
-            jsonPayload = "{" + "  \"gw_mac\": \"DE:AD:BE:EF:00\"," + "  \"rssi\": -82," + "  \"aoa\": [],"
-                    + "  \"gwts\": \"1659365432\"," + "  \"ts\": \"1659365222\"," + "  \"data\": \"" + val + "\","
-                    + "  \"coords\": \"\" }";
+            jsonPayload = """
+                    {\
+                      "gw_mac": "DE:AD:BE:EF:00",\
+                      "rssi": -82,\
+                      "aoa": [],\
+                      "gwts": "1659365432",\
+                      "ts": "1659365222",\
+                      "data": "\
+                    """ + val + "\"," + "  \"coords\": \"\" }";
         }
 
         Thing ruuviThing = createRuuviThing("mygwid", topic, 100);
@@ -525,7 +531,6 @@ public class RuuviGatewayTest extends MqttOSGiTest {
                         .forEach(channelId -> assertEquals(UnDefType.UNDEF, getItemState.apply(channelId)));
                 statusUpdateIndex.incrementAndGet();
             });
-
         }
 
         // Another mqtt update (("minimum values" test vector from
index 9afa8b62b82b911fc884838d6f613bb1460225f2..a6ad5d51970c057a0c5d9706e01da1d242456d3b 100644 (file)
@@ -14,7 +14,6 @@ package org.openhab.binding.mqtt.ruuvigateway;
 
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -48,7 +47,7 @@ public class ThingStatusInfoChangedSubscriber implements EventSubscriber {
 
     @Override
     public Set<@NonNull String> getSubscribedEventTypes() {
-        return Collections.singleton(ThingStatusInfoChangedEvent.TYPE);
+        return Set.of(ThingStatusInfoChangedEvent.TYPE);
     }
 
     @Override
index 1d675da2ac982f48efc68a2217ef3aeda14449cd..fdfc374dfabd794c8f239f623587e3a6d0598f7d 100644 (file)
@@ -22,8 +22,8 @@ import java.time.ZoneId;
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Collections;
 import java.util.Locale;
+import java.util.Set;
 import java.util.TimeZone;
 
 import org.junit.jupiter.api.AfterAll;
@@ -483,7 +483,7 @@ public class NtpOSGiTest extends JavaOSGiTest {
         initialize(configuration, channelID, acceptedItemType, null, null);
 
         EventSubscriber eventSubscriberMock = mock(EventSubscriber.class);
-        when(eventSubscriberMock.getSubscribedEventTypes()).thenReturn(Collections.singleton(ItemStateEvent.TYPE));
+        when(eventSubscriberMock.getSubscribedEventTypes()).thenReturn(Set.of(ItemStateEvent.TYPE));
         registerService(eventSubscriberMock);
 
         if (updateEventType.equals(UpdateEventType.HANDLE_COMMAND)) {
index 09d92fe881ebbe34e5ea00370e55162bceff7fac..efe52a86e463892c0fd6cec05022347eea5b65bb 100644 (file)
@@ -107,7 +107,7 @@ public class WemoDiscoveryParticipantTest {
         assertThat(result.getThingUID(), is(new ThingUID(thingTypeUid, DEVICE_UDN)));
         assertThat(result.getThingTypeUID(), is(thingTypeUid));
         assertThat(result.getBridgeUID(), is(nullValue()));
-        assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN.toString()));
+        assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN));
         assertThat(result.getRepresentationProperty(), is(WemoBindingConstants.UDN));
     }
 }