diff --git a/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java b/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java index 0778f76f3..1531c2ab4 100644 --- a/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java +++ b/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java @@ -29,6 +29,8 @@ import org.openhab.core.addon.AddonInfoRegistry; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionRegistry; +import org.openhab.core.config.core.FilterCriteria; +import org.openhab.core.config.core.ParameterOption; import org.openhab.core.test.java.JavaOSGiTest; /** @@ -82,14 +84,16 @@ public class AddonInfoTest extends JavaOSGiTest { ConfigDescriptionParameter listParameter = parameters.stream().filter(p -> "list".equals(p.getName())) .findFirst().get(); assertThat(listParameter, is(notNullValue())); - assertThat(listParameter.getOptions().stream().map(p -> p.toString()).collect(Collectors.joining(", ")), is( - "ParameterOption [value=\"key1\", label=\"label1\"], ParameterOption [value=\"key2\", label=\"label2\"]")); + assertThat( + listParameter.getOptions().stream().map(ParameterOption::toString) + .collect(Collectors.joining(", ")), + is("ParameterOption [value=\"key1\", label=\"label1\"], ParameterOption [value=\"key2\", label=\"label2\"]")); ConfigDescriptionParameter lightParameter = parameters.stream() .filter(p -> "color-alarming-light".equals(p.getName())).findFirst().get(); assertThat(lightParameter, is(notNullValue())); assertThat( - lightParameter.getFilterCriteria().stream().map(p -> p.toString()) + lightParameter.getFilterCriteria().stream().map(FilterCriteria::toString) .collect(Collectors.joining(", ")), is("FilterCriteria [name=\"tags\", value=\"alarm, light\"], FilterCriteria [name=\"type\", value=\"color\"], FilterCriteria [name=\"binding-id\", value=\"hue\"]")); }); diff --git a/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/AbstractTestAgent.java b/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/AbstractTestAgent.java index 54d1be91f..c8a586673 100644 --- a/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/AbstractTestAgent.java +++ b/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/AbstractTestAgent.java @@ -65,11 +65,10 @@ public abstract class AbstractTestAgent implements TestAgent { if (obj == null) { return ""; } - if (obj instanceof String) { - return (String) obj; + if (obj instanceof String string) { + return string; } - if (obj instanceof String[]) { - String[] strArr = (String[]) obj; + if (obj instanceof String[] strArr) { if (strArr.length >= 1) { return strArr[0]; } else { @@ -141,22 +140,19 @@ public abstract class AbstractTestAgent implements TestAgent { @Override public AccessTokenResponse testGetCachedAccessToken() throws OAuthException, IOException, OAuthResponseException { logger.debug("test getCachedAccessToken"); - AccessTokenResponse oldRefreshedToken = oauthClientService.getAccessTokenResponse(); - return oldRefreshedToken; + return oauthClientService.getAccessTokenResponse(); } @Override public AccessTokenResponse testRefreshToken() throws OAuthException, IOException, OAuthResponseException { logger.debug("test RefreshToken"); - AccessTokenResponse newRefreshedToken = oauthClientService.refreshToken(); - return newRefreshedToken; + return oauthClientService.refreshToken(); } @Override public String testGetAuthorizationUrl(String state) throws OAuthException { logger.debug("test getAuthorizationUrl {}", state); - String authorizationURL = oauthClientService.getAuthorizationUrl(redirectUri, scope, state); - return authorizationURL; + return oauthClientService.getAuthorizationUrl(redirectUri, scope, state); } @Override diff --git a/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java b/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java index 3ba71f090..e3c68f6d6 100644 --- a/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java +++ b/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java @@ -99,7 +99,7 @@ public class RunRuleModuleTest extends JavaOSGiTest { final Configuration sceneRuleAction3Config = new Configuration( Map.ofEntries(entry("itemName", "switch3"), entry("command", "ON"))); - final Rule sceneRule = RuleBuilder.create("exampleSceneRule").withActions( + return RuleBuilder.create("exampleSceneRule").withActions( ModuleBuilder.createAction().withId("sceneItemPostCommandAction1").withTypeUID("core.ItemCommandAction") .withConfiguration(sceneRuleAction1Config).build(), ModuleBuilder.createAction().withId("sceneItemPostCommandAction2").withTypeUID("core.ItemCommandAction") @@ -107,8 +107,6 @@ public class RunRuleModuleTest extends JavaOSGiTest { ModuleBuilder.createAction().withId("sceneItemPostCommandAction3").withTypeUID("core.ItemCommandAction") .withConfiguration(sceneRuleAction3Config).build()) .withName("Example Scene").build(); - - return sceneRule; } private Rule createOuterRule() { @@ -120,14 +118,12 @@ public class RunRuleModuleTest extends JavaOSGiTest { final Configuration outerRuleActionConfig = new Configuration(Map.of("ruleUIDs", ruleUIDs)); - final Rule outerRule = RuleBuilder.create("sceneActivationRule") + return RuleBuilder.create("sceneActivationRule") .withTriggers(ModuleBuilder.createTrigger().withId("ItemStateChangeTrigger2") .withTypeUID("core.GenericEventTrigger").withConfiguration(outerRuleTriggerConfig).build()) .withActions(ModuleBuilder.createAction().withId("RunRuleAction1").withTypeUID("core.RunRuleAction") .withConfiguration(outerRuleActionConfig).build()) .withName("scene activator").build(); - - return outerRule; } @Test diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java index 1df494a5c..1077c801b 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java @@ -105,8 +105,6 @@ public class RuntimeRuleTest extends JavaOSGiTest { */ logger.info("Create rule"); String testExpression = "* * * * * ?"; - - ; Configuration triggerConfig = new Configuration(Map.of("cronExpression", testExpression)); List triggers = List.of(ModuleBuilder.createTrigger().withId("MyTimerTrigger") .withTypeUID(GenericCronTriggerHandler.MODULE_TYPE_ID).withConfiguration(triggerConfig).build()); @@ -136,8 +134,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { final RuleStatusInfo ruleStatus = ruleEngine.getStatusInfo(rule.getUID()); logger.info("Rule status (should be IDLE or RUNNING): {}", ruleStatus); boolean allFine; - if (RuleStatus.IDLE.equals(ruleStatus.getStatus()) - || RuleStatus.RUNNING.equals(ruleStatus.getStatus())) { + if (RuleStatus.IDLE == ruleStatus.getStatus() || RuleStatus.RUNNING == ruleStatus.getStatus()) { allFine = true; } else { allFine = false; diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java index 2b670aab4..3bbdea8a1 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java @@ -74,23 +74,20 @@ public class TimeOfDayConditionHandlerTest extends BasicConditionHandlerTest { } private TimeOfDayConditionHandler getTimeOfDayConditionHandler(String startTime, String endTime) { - TimeOfDayConditionHandler handler = new TimeOfDayConditionHandler(getTimeCondition(startTime, endTime)); - return handler; + return new TimeOfDayConditionHandler(getTimeCondition(startTime, endTime)); } private Condition getTimeCondition(String startTime, String endTime) { Configuration timeConfig = getTimeConfiguration(startTime, endTime); - Condition condition = ModuleBuilder.createCondition().withId("testTimeOfDayCondition") + return ModuleBuilder.createCondition().withId("testTimeOfDayCondition") .withTypeUID(TimeOfDayConditionHandler.MODULE_TYPE_ID).withConfiguration(timeConfig).build(); - return condition; } private Configuration getTimeConfiguration(String startTime, String endTime) { Map timeMap = new HashMap<>(); timeMap.put("startTime", startTime); timeMap.put("endTime", endTime); - Configuration timeConfig = new Configuration(timeMap); - return timeConfig; + return new Configuration(timeMap); } @Override diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/TestModuleTypeProvider.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/TestModuleTypeProvider.java index 37011e6c4..5ba47dcf1 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/TestModuleTypeProvider.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/TestModuleTypeProvider.java @@ -55,17 +55,16 @@ public class TestModuleTypeProvider implements ModuleTypeProvider { outputs.add(createOutput("out1", Set.of("tagA"))); outputs.add(createOutput("out2", Set.of("tagB", "tagC"))); outputs.add(createOutput("out3", Set.of("tagA", "tagB", "tagC"))); - TriggerType t = new TriggerType(TRIGGER_TYPE, null, outputs); - return t; + return new TriggerType(TRIGGER_TYPE, null, outputs); } private ConditionType createConditionType() { List inputs = new ArrayList<>(3); inputs.add(createInput("in0", Set.of("tagE"))); // no connection, missing condition tag inputs.add(createInput("in1", Set.of("tagA"))); // conflict in2 -> out1 or in2 -> out3 - inputs.add(createInput("in2", Set.of("tagA", "tagB"))); // in2 -> out3 - ConditionType t = new ConditionType(CONDITION_TYPE, null, inputs); - return t; + inputs.add(createInput("in2", Set.of("tagA", "tagB"))); + // in2 -> out3 + return new ConditionType(CONDITION_TYPE, null, inputs); } private ActionType createActionType() { @@ -78,8 +77,7 @@ public class TestModuleTypeProvider implements ModuleTypeProvider { List outputs = new ArrayList<>(3); outputs.add(createOutput("out4", Set.of("tagD"))); outputs.add(createOutput("out5", Set.of("tagD", "tagE"))); - ActionType t = new ActionType(ACTION_TYPE, null, inputs, outputs); - return t; + return new ActionType(ACTION_TYPE, null, inputs, outputs); } private Output createOutput(String name, Set tags) { diff --git a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionI18nTest.java b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionI18nTest.java index caf3d4d99..dd973d1c4 100644 --- a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionI18nTest.java +++ b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionI18nTest.java @@ -30,6 +30,7 @@ import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameterGroup; import org.openhab.core.config.core.ConfigDescriptionProvider; +import org.openhab.core.config.core.ParameterOption; import org.openhab.core.test.BundleCloseable; import org.openhab.core.test.SyntheticBundleInstaller; import org.openhab.core.test.java.JavaOSGiTest; @@ -101,7 +102,7 @@ public class ConfigDescriptionI18nTest extends JavaOSGiTest { sb.append(String.format("refresh.description = %s\n", refresh.getDescription())); sb.append(String.format("question.pattern = %s\n", question.getPattern())); sb.append(String.format("question.options = %s\n", - question.getOptions().stream().map(o -> o.getLabel()).collect(Collectors.joining(", ")))); + question.getOptions().stream().map(ParameterOption::getLabel).collect(Collectors.joining(", ")))); sb.append(String.format("group.label = %s\n", group.getLabel())); sb.append(String.format("group.description = %s", group.getDescription())); diff --git a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionsTest.java b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionsTest.java index a1193063e..63d9f5951 100644 --- a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionsTest.java +++ b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/xml/ConfigDescriptionsTest.java @@ -33,6 +33,8 @@ import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; import org.openhab.core.config.core.ConfigDescriptionParameterGroup; import org.openhab.core.config.core.ConfigDescriptionRegistry; +import org.openhab.core.config.core.FilterCriteria; +import org.openhab.core.config.core.ParameterOption; import org.openhab.core.test.BundleCloseable; import org.openhab.core.test.SyntheticBundleInstaller; import org.openhab.core.test.java.JavaOSGiTest; @@ -119,7 +121,7 @@ public class ConfigDescriptionsTest extends JavaOSGiTest { assertThat(colorItemParameter.getContext(), is("item")); assertThat(colorItemParameter.getFilterCriteria(), is(notNullValue())); assertThat( - colorItemParameter.getFilterCriteria().stream().map(c -> c.toString()) + colorItemParameter.getFilterCriteria().stream().map(FilterCriteria::toString) .collect(Collectors.joining(", ")), is("FilterCriteria [name=\"tags\", value=\"alarm, light\"], FilterCriteria [name=\"type\", value=\"color\"], FilterCriteria [name=\"binding-id\", value=\"hue\"]")); @@ -136,7 +138,7 @@ public class ConfigDescriptionsTest extends JavaOSGiTest { assertThat(listParameter1.isVerifyable(), is(false)); assertThat(listParameter1.getLimitToOptions(), is(true)); assertThat(listParameter1.getMultipleLimit(), is(nullValue())); - assertThat(listParameter1.getOptions().stream().map(o -> o.toString()).collect(joining(", ")), is( + assertThat(listParameter1.getOptions().stream().map(ParameterOption::toString).collect(joining(", ")), is( "ParameterOption [value=\"key1\", label=\"label1\"], ParameterOption [value=\"key2\", label=\"label2\"]")); ConfigDescriptionParameter listParameter2 = findParameter(englishDescription, "list2"); diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java index 3aeb235d8..011da7699 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java @@ -359,7 +359,7 @@ public class DiscoveryServiceRegistryOSGiTest extends JavaOSGiTest { discoveryServiceRegistry.addDiscoveryListener(discoveryListenerMock); discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener1); - waitForAssert(() -> mockScanListener1.onFinished()); + waitForAssert(mockScanListener1::onFinished); verify(discoveryListenerMock, times(2)).thingDiscovered(any(), any()); } diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java index 983c8d0a4..5646ab426 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java @@ -219,8 +219,8 @@ public class InboxOSGiTest extends JavaOSGiTest { EventSubscriber inboxEventSubscriber = new EventSubscriber() { @Override public void receive(Event event) { - if (event instanceof InboxRemovedEvent) { - removedInboxThingUIDs.add(((InboxRemovedEvent) event).getDiscoveryResult().thingUID); + if (event instanceof InboxRemovedEvent removedEvent) { + removedInboxThingUIDs.add(removedEvent.getDiscoveryResult().thingUID); } } @@ -235,7 +235,7 @@ public class InboxOSGiTest extends JavaOSGiTest { registry.remove(BRIDGE_THING_UID); managedThingProvider.getAll().forEach(thing -> managedThingProvider.remove(thing.getUID())); - inboxListeners.forEach(listener -> inbox.removeInboxListener(listener)); + inboxListeners.forEach(inbox::removeInboxListener); inbox.getAll().stream().forEach(discoveryResult -> inbox.remove(discoveryResult.getThingUID())); discoveryResults.clear(); @@ -1053,7 +1053,7 @@ public class InboxOSGiTest extends JavaOSGiTest { CompletableFuture future = inbox.add(discoveryResult); - waitForAssert(() -> future.isDone(), 30, 5); + waitForAssert(future::isDone, 30, 5); assertThat(future.get(), is(false)); } @@ -1071,7 +1071,7 @@ public class InboxOSGiTest extends JavaOSGiTest { dummyThingTypeProvider.add(thingTypeUID, ThingTypeBuilder.instance(thingTypeUID, "label").build()); - waitForAssert(() -> future.isDone(), 30, 5); + waitForAssert(future::isDone, 30, 5); assertThat(future.get(), is(true)); } diff --git a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java index 8b73f3762..92ec4d60e 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java +++ b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java @@ -88,7 +88,7 @@ public class SysFsUsbSerialScannerTest { @Test public void testIOExceptionIfSysfsTtyDoesNotExist() throws IOException { delete(sysfsTtyPath); - assertThrows(IOException.class, () -> scanner.scan()); + assertThrows(IOException.class, scanner::scan); } @Test @@ -246,6 +246,6 @@ public class SysFsUsbSerialScannerTest { NO_VENDOR_ID, NO_PRODUCT_ID, NO_INTERFACE_NUMBER, - NON_USB_DEVICE; + NON_USB_DEVICE } } diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java index a84cda47e..b57c38991 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java @@ -271,7 +271,7 @@ public class GenericThingProviderTest extends JavaOSGiTest { assertThat(actualThings.size(), is(2)); Thing thing = actualThings.stream().filter(t -> !(t instanceof Bridge)).findFirst().get(); - Bridge bridge = (Bridge) actualThings.stream().filter(t -> t instanceof Bridge).findFirst().get(); + Bridge bridge = (Bridge) actualThings.stream().filter(Bridge.class::isInstance).findFirst().get(); assertThat(thing.getBridgeUID().toString(), is("hue:bridge:bridge1")); assertThat(bridge.getThings().contains(thing), is(true)); @@ -302,22 +302,22 @@ public class GenericThingProviderTest extends JavaOSGiTest { assertThat(actualThings.size(), is(4)); - actualThings.stream().filter(t -> "bulb_default".equals(t.getUID().getId().toString())).findFirst().get(); + actualThings.stream().filter(t -> "bulb_default".equals(t.getUID().getId())).findFirst().get(); - Thing thingDefault = actualThings.stream().filter(t -> "bulb_default".equals(t.getUID().getId().toString())) - .findFirst().get(); + Thing thingDefault = actualThings.stream().filter(t -> "bulb_default".equals(t.getUID().getId())).findFirst() + .get(); assertThat(thingDefault.getChannels().size(), is(2)); - Thing thingCustom = actualThings.stream().filter(t -> "bulb_custom".equals(t.getUID().getId().toString())) - .findFirst().get(); + Thing thingCustom = actualThings.stream().filter(t -> "bulb_custom".equals(t.getUID().getId())).findFirst() + .get(); assertThat(thingCustom.getChannels().size(), is(4)); assertThat(thingCustom.getChannel("manual").getChannelTypeUID(), is(equalTo(new ChannelTypeUID("hue", "color")))); assertThat(thingCustom.getChannel("manual").getLabel(), is("colorLabel")); // default from thing type assertThat(thingCustom.getChannel("manualWithLabel").getLabel(), is("With Label")); // manual overrides default - Thing thingBroken = actualThings.stream().filter(t -> "bulb_broken".equals(t.getUID().getId().toString())) - .findFirst().get(); + Thing thingBroken = actualThings.stream().filter(t -> "bulb_broken".equals(t.getUID().getId())).findFirst() + .get(); assertThat(thingBroken.getChannels().size(), is(4)); assertThat(thingBroken.getChannel("manual").getChannelTypeUID(), is(equalTo(new ChannelTypeUID("hue", "broken")))); @@ -343,8 +343,8 @@ public class GenericThingProviderTest extends JavaOSGiTest { assertThat(actualThings.size(), is(1)); - Thing thingDefault = actualThings.stream().filter(t -> "sensor_custom".equals(t.getUID().getId().toString())) - .findFirst().get(); + Thing thingDefault = actualThings.stream().filter(t -> "sensor_custom".equals(t.getUID().getId())).findFirst() + .get(); assertThat(thingDefault.getChannels().size(), is(2)); assertThat(thingDefault.getChannel("sensor1").getAcceptedItemType(), is("Number:Temperature")); @@ -363,8 +363,8 @@ public class GenericThingProviderTest extends JavaOSGiTest { assertThat(actualThings.size(), is(1)); - Thing thingDefault = actualThings.stream().filter(t -> "sensor_custom".equals(t.getUID().getId().toString())) - .findFirst().get(); + Thing thingDefault = actualThings.stream().filter(t -> "sensor_custom".equals(t.getUID().getId())).findFirst() + .get(); @SuppressWarnings("unchecked") Collection valueCollection = (Collection) thingDefault.getConfiguration().get("config"); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java index 2c41f7732..55229369c 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java @@ -120,8 +120,8 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { hueThingHandlerFactory = new TestHueThingHandlerFactoryX(componentContextMock) { @Override protected @Nullable ThingHandler createHandler(final Thing thing) { - if (thing instanceof Bridge) { - return new TestBridgeHandler((Bridge) thing); + if (thing instanceof Bridge bridge) { + return new TestBridgeHandler(bridge); } else { return new BaseThingHandler(thing) { @Override diff --git a/itests/org.openhab.core.model.thing.testsupport/src/main/java/org/openhab/core/model/thing/testsupport/hue/TestHueThingHandlerFactory.java b/itests/org.openhab.core.model.thing.testsupport/src/main/java/org/openhab/core/model/thing/testsupport/hue/TestHueThingHandlerFactory.java index c9f4e324c..fce64d943 100644 --- a/itests/org.openhab.core.model.thing.testsupport/src/main/java/org/openhab/core/model/thing/testsupport/hue/TestHueThingHandlerFactory.java +++ b/itests/org.openhab.core.model.thing.testsupport/src/main/java/org/openhab/core/model/thing/testsupport/hue/TestHueThingHandlerFactory.java @@ -110,8 +110,8 @@ public class TestHueThingHandlerFactory extends BaseThingHandlerFactory { @Override protected @Nullable ThingHandler createHandler(Thing thing) { - if (thing instanceof Bridge) { - return new BaseBridgeHandler((Bridge) thing) { + if (thing instanceof Bridge bridge) { + return new BaseBridgeHandler(bridge) { @Override public void handleCommand(ChannelUID channelUID, Command command) { } diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java index 56169bf46..e6e06fb30 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java @@ -14,6 +14,7 @@ package org.openhab.core.internal.items; import static org.junit.jupiter.api.Assertions.*; +import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; @@ -43,7 +44,7 @@ public class ItemUpdaterOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) EventPublisher eventPublisher; private @NonNullByDefault({}) ItemRegistry itemRegistry; - private final ConcurrentLinkedQueue receivedEvents = new ConcurrentLinkedQueue<>(); + private final Queue receivedEvents = new ConcurrentLinkedQueue<>(); @BeforeEach public void setUp() { diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java index e1d8afe2c..b9c1567dc 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java @@ -84,7 +84,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { private final List events = new LinkedList<>(); private final GroupFunctionHelper groupFunctionHelper = new GroupFunctionHelper(); - private final EventPublisher publisher = event -> events.add(event); + private final EventPublisher publisher = events::add; private @NonNullByDefault({}) ItemRegistry itemRegistry; private @NonNullByDefault({}) ItemStateConverter itemStateConverter; @@ -135,7 +135,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { itemRegistry.update(updatedItem); waitForAssert(() -> assertThat(events.size(), is(1))); - List stateChanges = events.stream().filter(it -> it instanceof ItemUpdatedEvent) + List stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(stateChanges.size(), is(1)); @@ -281,7 +281,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { subGroup.addMember(member1); rootGroupItem.addMember(subGroup); - Set members = rootGroupItem.getMembers(i -> i instanceof GroupItem); + Set members = rootGroupItem.getMembers(GroupItem.class::isInstance); assertThat(members.size(), is(1)); members = rootGroupItem.getMembers(i -> "mem1".equals(i.getLabel())); @@ -440,7 +440,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events.size(), is(2))); - List updates = events.stream().filter(it -> it instanceof GroupStateUpdatedEvent) + List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(updates.size(), is(1)); @@ -451,7 +451,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { .replace("{itemName}", groupItem.getName()))); assertThat(update.getItemState(), is(groupItem.getState())); - List changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(changes.size(), is(1)); @@ -490,7 +490,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List groupItemStateChangedEvents = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) + List groupItemStateChangedEvents = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(groupItemStateChangedEvents, hasSize(1)); @@ -533,11 +533,11 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List itemCommandEvents = events.stream().filter(it -> it instanceof ItemCommandEvent) + List itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance) .collect(Collectors.toList()); assertThat(itemCommandEvents, hasSize(2)); - List groupItemStateChangedEvents = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) + List groupItemStateChangedEvents = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(groupItemStateChangedEvents, hasSize(0)); @@ -563,11 +563,11 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(changes, hasSize(1)); - List updates = events.stream().filter(it -> it instanceof GroupStateUpdatedEvent) + List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(updates, hasSize(1)); @@ -592,10 +592,10 @@ public class GroupItemOSGiTest extends JavaOSGiTest { assertThat(events, hasSize(2)); - changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList()); + changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList()); assertThat(changes, hasSize(0)); - updates = events.stream().filter(it -> it instanceof GroupStateUpdatedEvent).collect(Collectors.toList()); + updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).collect(Collectors.toList()); assertThat(updates, hasSize(2)); assertThat(groupItem.getState(), is(OnOffType.ON)); @@ -620,7 +620,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) .collect(Collectors.toList()); assertThat(changes, hasSize(1)); @@ -640,7 +640,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList()); + changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList()); assertThat(changes, hasSize(1)); change = (GroupItemStateChangedEvent) changes.get(0); @@ -754,7 +754,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events.size(), is(2))); - List changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) .collect(Collectors.toList()); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); assertThat(change.getItemName(), is(groupItem.getName())); @@ -773,7 +773,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events.size(), is(2))); - changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList()); + changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList()); assertThat(changes.size(), is(1)); change = (GroupItemStateChangedEvent) changes.get(0); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java index 03dfe1c8c..c7d989551 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java @@ -132,7 +132,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG)); assertThat(items, hasSize(4)); - List itemNames = items.stream().map(i -> i.getName()).collect(toList()); + List itemNames = items.stream().map(Item::getName).collect(toList()); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME3)); @@ -144,7 +144,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG_UPPERCASE)); assertThat(items, hasSize(4)); - List itemNames = items.stream().map(i -> i.getName()).collect(toList()); + List itemNames = items.stream().map(Item::getName).collect(toList()); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME3)); @@ -156,7 +156,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTagAndType("Switch", CAMERA_TAG)); assertThat(items, hasSize(2)); - List itemNames = items.stream().map(i -> i.getName()).collect(toList()); + List itemNames = items.stream().map(Item::getName).collect(toList()); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); } @@ -178,7 +178,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTag(SwitchItem.class, CAMERA_TAG)); assertThat(items, hasSize(2)); - List itemNames = items.stream().map(i -> i.getName()).collect(toList()); + List itemNames = items.stream().map(GenericItem::getName).collect(toList()); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); } 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 6a81832a9..c9fb1b914 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 @@ -146,7 +146,7 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { @Override protected @Nullable ThingHandler createHandler(Thing thing) { - ThingHandler handler = (thing instanceof Bridge) ? new SimpleBridgeHandler((Bridge) thing) + ThingHandler handler = (thing instanceof Bridge b) ? new SimpleBridgeHandler(b) : new SimpleThingHandler(thing); handlers.add(handler); return handler; diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java index 42997f7b5..50aec670b 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java @@ -287,7 +287,7 @@ public class FirmwareTest extends JavaOSGiTest { Firmware firmware = FirmwareBuilder.create(THING_TYPE_UID, "1") .withInputStream(bundleContext.getBundle().getResource(FILE_NAME).openStream()) .withMd5Hash("78805a221a988e79ef3f42d7c5bfd419").build(); - assertThrows(IllegalStateException.class, () -> firmware.getBytes()); + assertThrows(IllegalStateException.class, firmware::getBytes); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java index 42d01aa87..f6e741584 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java @@ -218,14 +218,14 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest { @Override public void receive(Event event) { logger.debug("Received event: {}", event); - if (event instanceof AbstractItemChannelLinkRegistryEvent) { - ItemChannelLinkDTO link = ((AbstractItemChannelLinkRegistryEvent) event).getLink(); + if (event instanceof AbstractItemChannelLinkRegistryEvent registryEvent) { + ItemChannelLinkDTO link = registryEvent.getLink(); removedItemChannelLinkUIDs .add(AbstractLink.getIDFor(link.itemName, new ChannelUID(link.channelUID))); - } else if (event instanceof AbstractItemRegistryEvent) { - removedItemNames.add(((AbstractItemRegistryEvent) event).getItem().name); - } else if (event instanceof AbstractThingRegistryEvent) { - removedThingUIDs.add(((AbstractThingRegistryEvent) event).getThing().UID); + } else if (event instanceof AbstractItemRegistryEvent registryEvent) { + removedItemNames.add(registryEvent.getItem().name); + } else if (event instanceof AbstractThingRegistryEvent registryEvent) { + removedThingUIDs.add(registryEvent.getThing().UID); } } @@ -295,7 +295,7 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest { } private void forEachThingChannelUID(Thing thing, Consumer consumer) { - thing.getChannels().stream().map(Channel::getUID).forEach(channelUID -> consumer.accept(channelUID)); + thing.getChannels().stream().map(Channel::getUID).forEach(consumer::accept); } private void addItemsAndLinks(Thing thing, String itemSuffix) { diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java index 9a1e46d85..b76c45ed8 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java @@ -164,7 +164,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { || THING_TYPE_UID3.equals(thing.getThingTypeUID())) { return Collections.emptySet(); } else { - Supplier> supplier = () -> new TreeSet<>(); + Supplier> supplier = TreeSet::new; return Stream.of(FW009_EN, FW111_EN, FW112_EN).collect(Collectors.toCollection(supplier)); } }; @@ -318,7 +318,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { firmwareUpdateService.updateFirmware(THING1_UID, V112, null); waitForAssert(() -> { - assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112.toString())); + assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112)); }); assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(upToDateInfo)); @@ -461,7 +461,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { firmwareUpdateService.updateFirmware(THING2_UID, V111, null); waitForAssert(() -> { - assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111.toString())); + assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111)); }); assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(updateExecutableInfoFw112)); @@ -547,7 +547,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { || THING_TYPE_UID2.equals(thing.getThingTypeUID())) { return Collections.emptySet(); } else { - Supplier> supplier = () -> new TreeSet<>(); + Supplier> supplier = TreeSet::new; return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toCollection(supplier)); } }); @@ -583,7 +583,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { || THING_TYPE_UID2.equals(thing.getThingTypeUID())) { return Collections.emptySet(); } else { - Supplier> supplier = () -> new TreeSet<>(); + Supplier> supplier = TreeSet::new; return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toCollection(supplier)); } }; @@ -702,7 +702,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { verify(eventPublisherMock, atLeast(SEQUENCE.length + 1)).post(eventCaptor.capture()); }); events.get().addAll(eventCaptor.getAllValues()); - List list = events.get().stream().filter(event -> event instanceof FirmwareUpdateProgressInfoEvent) + List list = events.get().stream().filter(FirmwareUpdateProgressInfoEvent.class::isInstance) .collect(Collectors.toList()); assertTrue(list.size() >= SEQUENCE.length); for (int i = 0; i < SEQUENCE.length; i++) { @@ -758,7 +758,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { assertResultInfoEvent(THING1_UID, FW112_EN, "unexpected-handler-error", Locale.ENGLISH, "english", 1); assertResultInfoEvent(THING1_UID, FW112_EN, "unexpected-handler-error", Locale.GERMAN, "deutsch", 2); - assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111.toString())); + assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111)); assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112)); } @@ -777,7 +777,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { assertResultInfoEvent(THING1_UID, FW112_EN, "test-error", Locale.ENGLISH, "english", 1); assertResultInfoEvent(THING1_UID, FW112_EN, "test-error", Locale.GERMAN, "deutsch", 2); - assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111.toString())); + assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111)); assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112)); } @@ -821,9 +821,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { FirmwareUpdateBackgroundTransferHandler handler4 = mock(FirmwareUpdateBackgroundTransferHandler.class); when(handler4.getThing()).thenReturn(thing4); - doAnswer(invocation -> { - return updateExecutable.get(); - }).when(handler4).isUpdateExecutable(); + doAnswer(invocation -> updateExecutable.get()).when(handler4).isUpdateExecutable(); doAnswer(invocation -> { Firmware firmware = (Firmware) invocation.getArguments()[0]; thing4.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion()); @@ -905,7 +903,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, atLeast(expectedEventCount)).post(eventCaptor.capture()); List allValues = eventCaptor.getAllValues().stream() - .filter(e -> e instanceof FirmwareUpdateResultInfoEvent).collect(Collectors.toList()); + .filter(FirmwareUpdateResultInfoEvent.class::isInstance).collect(Collectors.toList()); assertEquals(expectedEventCount, allValues.size()); assertFailedFirmwareUpdate(THING1_UID, allValues.get(expectedEventCount - 1), text); }); diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java index 0e7687379..3e90f20e5 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/TTSServiceStub.java @@ -73,7 +73,7 @@ public class TTSServiceStub implements TTSService { try { Collection> refs = bundleContext.getServiceReferences(Voice.class, null); return refs.stream() // - .map(ref -> bundleContext.getService(ref)) // + .map(bundleContext::getService) // .filter(service -> service.getUID().startsWith(getId())) // .collect(Collectors.toSet()); } catch (InvalidSyntaxException e) { diff --git a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java index 6a11b508d..0462066d2 100644 --- a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java +++ b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java @@ -116,20 +116,17 @@ public class BundleInfoReader { return; } for (Object type : types) { - if (type instanceof ThingTypeXmlResult) { - ThingTypeXmlResult result = (ThingTypeXmlResult) type; + if (type instanceof ThingTypeXmlResult result) { bundleInfo.getThingTypesXml().add(result); if (bundleInfo.getAddonId().isBlank()) { bundleInfo.setAddonId(result.getUID().getBindingId()); } - } else if (type instanceof ChannelGroupTypeXmlResult) { - ChannelGroupTypeXmlResult result = (ChannelGroupTypeXmlResult) type; + } else if (type instanceof ChannelGroupTypeXmlResult result) { bundleInfo.getChannelGroupTypesXml().add(result); if (bundleInfo.getAddonId().isBlank()) { bundleInfo.setAddonId(result.getUID().getBindingId()); } - } else if (type instanceof ChannelTypeXmlResult) { - ChannelTypeXmlResult result = (ChannelTypeXmlResult) type; + } else if (type instanceof ChannelTypeXmlResult result) { bundleInfo.getChannelTypesXml().add(result); if (bundleInfo.getAddonId().isBlank()) { bundleInfo.setAddonId(result.toChannelType().getUID().getBindingId());