Code cleanup: Use Java 17 features (#3580)

* Code cleanup: Use Java 17 features

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2023-04-30 18:37:48 +02:00 committed by GitHub
parent ac0f512178
commit 33233982b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 99 additions and 112 deletions

View File

@ -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\"]"));
});

View File

@ -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

View File

@ -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

View File

@ -105,8 +105,6 @@ public class RuntimeRuleTest extends JavaOSGiTest {
*/
logger.info("Create rule");
String testExpression = "* * * * * ?";
;
Configuration triggerConfig = new Configuration(Map.of("cronExpression", testExpression));
List<Trigger> 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;

View File

@ -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<String, Object> timeMap = new HashMap<>();
timeMap.put("startTime", startTime);
timeMap.put("endTime", endTime);
Configuration timeConfig = new Configuration(timeMap);
return timeConfig;
return new Configuration(timeMap);
}
@Override

View File

@ -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<Input> 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<Output> 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<String> tags) {

View File

@ -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()));

View File

@ -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");

View File

@ -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());
}

View File

@ -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<Boolean> 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));
}

View File

@ -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
}
}

View File

@ -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<String> valueCollection = (Collection<String>) thingDefault.getConfiguration().get("config");

View File

@ -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

View File

@ -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) {
}

View File

@ -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<Event> receivedEvents = new ConcurrentLinkedQueue<>();
private final Queue<Event> receivedEvents = new ConcurrentLinkedQueue<>();
@BeforeEach
public void setUp() {

View File

@ -84,7 +84,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
private final List<Event> 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<Event> stateChanges = events.stream().filter(it -> it instanceof ItemUpdatedEvent)
List<Event> 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<Item> members = rootGroupItem.getMembers(i -> i instanceof GroupItem);
Set<Item> 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<Event> updates = events.stream().filter(it -> it instanceof GroupStateUpdatedEvent)
List<Event> 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<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent)
List<Event> 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<Event> groupItemStateChangedEvents = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent)
List<Event> 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<Event> itemCommandEvents = events.stream().filter(it -> it instanceof ItemCommandEvent)
List<Event> itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance)
.collect(Collectors.toList());
assertThat(itemCommandEvents, hasSize(2));
List<Event> groupItemStateChangedEvents = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent)
List<Event> 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<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent)
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
assertThat(changes, hasSize(1));
List<Event> updates = events.stream().filter(it -> it instanceof GroupStateUpdatedEvent)
List<Event> 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<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent)
List<Event> 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<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent)
List<Event> 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);

View File

@ -132,7 +132,7 @@ public class ItemRegistryImplTest extends JavaTest {
List<Item> items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG));
assertThat(items, hasSize(4));
List<String> itemNames = items.stream().map(i -> i.getName()).collect(toList());
List<String> 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<Item> items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG_UPPERCASE));
assertThat(items, hasSize(4));
List<String> itemNames = items.stream().map(i -> i.getName()).collect(toList());
List<String> 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<Item> items = new ArrayList<>(itemRegistry.getItemsByTagAndType("Switch", CAMERA_TAG));
assertThat(items, hasSize(2));
List<String> itemNames = items.stream().map(i -> i.getName()).collect(toList());
List<String> 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<SwitchItem> items = new ArrayList<>(itemRegistry.getItemsByTag(SwitchItem.class, CAMERA_TAG));
assertThat(items, hasSize(2));
List<String> itemNames = items.stream().map(i -> i.getName()).collect(toList());
List<String> itemNames = items.stream().map(GenericItem::getName).collect(toList());
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2));
}

View File

@ -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;

View File

@ -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

View File

@ -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<ChannelUID> 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) {

View File

@ -164,7 +164,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest {
|| THING_TYPE_UID3.equals(thing.getThingTypeUID())) {
return Collections.emptySet();
} else {
Supplier<TreeSet<Firmware>> supplier = () -> new TreeSet<>();
Supplier<TreeSet<Firmware>> 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<TreeSet<Firmware>> supplier = () -> new TreeSet<>();
Supplier<TreeSet<Firmware>> 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<TreeSet<Firmware>> supplier = () -> new TreeSet<>();
Supplier<TreeSet<Firmware>> 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<Event> list = events.get().stream().filter(event -> event instanceof FirmwareUpdateProgressInfoEvent)
List<Event> 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<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, atLeast(expectedEventCount)).post(eventCaptor.capture());
List<Event> 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);
});

View File

@ -73,7 +73,7 @@ public class TTSServiceStub implements TTSService {
try {
Collection<ServiceReference<Voice>> 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) {

View File

@ -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());