Simplify code using Stream.toList (#3831)

Stream.toList was introduced in Java 16 and creates an unmodifiable List so it can be used to simplify code whenever the List is not expected to be modified.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2023-10-09 09:20:08 +02:00
committed by GitHub
parent 2794c973d3
commit 09b3160a55
93 changed files with 294 additions and 471 deletions
@@ -919,7 +919,7 @@ public class AutomationIntegrationTest extends JavaOSGiTest {
ModuleBuilder.createCondition().withId("ItemStateCondition" + (random + 1))
.withTypeUID("core.GenericCompareCondition").withConfiguration(condition2Config)
.withInputs(Map.of("input", triggerId + ".event")).build())
.collect(toList());
.toList();
List<Action> actions = List.of(ModuleBuilder.createAction().withId("ItemPostCommandAction" + random)
.withTypeUID("core.ItemCommandAction").withConfiguration(actionConfig).build());
@@ -31,7 +31,6 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -147,7 +146,7 @@ public class RuleSimulationTest extends JavaOSGiTest {
final ZonedDateTime from = ZonedDateTime.of(2021, 1, 4, 0, 0, 0, 0, ZoneId.systemDefault());
final ZonedDateTime until = ZonedDateTime.of(2021, 1, 17, 23, 59, 59, 0, ZoneId.systemDefault());
List<RuleExecution> executions = ruleEngine.simulateRuleExecutions(from, until).collect(Collectors.toList());
List<RuleExecution> executions = ruleEngine.simulateRuleExecutions(from, until).toList();
// Every rule fires twice a week. We simulate for two weeks so we expect 12 executions
// TODO: must be 12, but Ephemeris Condition is not yet evaluated in test, because dayset is not configured.
@@ -25,7 +25,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -199,7 +198,7 @@ public class RuleEventTest extends JavaOSGiTest {
assertThat(ruleEvents.stream().filter(e -> "openhab/rules/myRule21/state".equals(e.getTopic())).findFirst()
.isPresent(), is(true));
List<Event> stateEvents = ruleEvents.stream().filter(e -> "openhab/rules/myRule21/state".equals(e.getTopic()))
.collect(Collectors.toList());
.toList();
assertThat(stateEvents, is(notNullValue()));
Optional<Event> runningEvent = stateEvents.stream()
.filter(e -> ((RuleStatusInfoEvent) e).getStatusInfo().getStatus() == RuleStatus.RUNNING).findFirst();
@@ -19,7 +19,6 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.BeforeEach;
@@ -82,13 +81,12 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking that results from stream() have the same size as getAll() above
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(1, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().toList().size(), "RuleImpl list size");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking predicates
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking rule with 1 tag
@@ -112,7 +110,7 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking that results from stream() have the same size as getAll() above
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(2, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().toList().size(), "RuleImpl list size");
Collection<Rule> rulesWithTag1 = ruleRegistry.getByTags(tag1);
assertEquals(1, rulesWithTag1.size(), "RuleImpl list size");
@@ -120,18 +118,13 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking predicates
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tags)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1)).toList().size(), "RuleImpl list size");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking rule with 2 tags
@@ -156,7 +149,7 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking that results from stream() have the same size as getAll() above
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(3, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().toList().size(), "RuleImpl list size");
rulesWithTag1 = ruleRegistry.getByTags(tag1);
assertEquals(2, rulesWithTag1.size(), "RuleImpl list size");
@@ -170,35 +163,26 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking predicates
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(),
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tags)).toList().size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).toList().size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))).toList().size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag2)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2)))
.collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(),
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1).and(hasAllTags(tag2))).toList().size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1).and(hasAllTags(tag2)))
.collect(Collectors.toList()).size(), "RuleImpl list size");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking rule with 3 tags
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -223,7 +207,7 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking that results from stream() have the same size as getAll() above
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(4, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(4, ruleRegistry.stream().toList().size(), "RuleImpl list size");
rulesWithTag1 = ruleRegistry.getByTags(tag1);
assertEquals(3, rulesWithTag1.size(), "RuleImpl list size");
@@ -246,46 +230,34 @@ public class RuleRegistryTest extends JavaOSGiTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checking predicates
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(),
assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tags)).toList().size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).toList().size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).toList().size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2, tag3)).toList().size(),
"RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(3,
ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2, tag3)).collect(Collectors.toList()).size(),
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).toList().size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2, tag3)).toList().size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))).toList().size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size(),
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag3))).toList().size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2, tag3)).collect(Collectors.toList()).size(),
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2).and(hasAnyOfTags(tag3))).toList().size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2)))
.collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag3)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag3)))
.collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2).and(hasAnyOfTags(tag3)))
.collect(Collectors.toList()).size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAllTags(tag1)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag3)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag2)).toList().size(), "RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).toList().size(), "RuleImpl list size");
assertEquals(3, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(),
"RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2, tag3)).collect(Collectors.toList()).size(),
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).toList().size(), "RuleImpl list size");
assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2, tag3)).toList().size(),
"RuleImpl list size");
}
}
@@ -808,7 +808,7 @@ public class InboxOSGiTest extends JavaOSGiTest {
.anyMatch(forThingUID(THING1_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW))));
assertFalse(inbox.stream()
.anyMatch(forThingUID(THING2_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW))));
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()),
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(),
hasItems(THING_WITHOUT_BRIDGE, THING_WITH_OTHER_BRIDGE));
waitForAssert(() -> {
assertThat(receivedEvents.size(), is(3));
@@ -845,7 +845,7 @@ public class InboxOSGiTest extends JavaOSGiTest {
registry.add(BridgeBuilder.create(BRIDGE_THING_TYPE_UID, BRIDGE_THING_UID).build());
assertFalse(inbox.stream().anyMatch(forThingUID(BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW))));
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()),
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(),
hasItems(THING1_WITH_BRIDGE, THING2_WITH_BRIDGE, THING_WITHOUT_BRIDGE));
waitForAssert(() -> {
assertThat(receivedEvents.size(), is(1));
@@ -879,7 +879,7 @@ public class InboxOSGiTest extends JavaOSGiTest {
inbox.add(THING2_WITH_BRIDGE);
inbox.add(THING_WITHOUT_BRIDGE);
inbox.add(THING_WITH_OTHER_BRIDGE);
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()),
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(),
hasItems(THING1_WITH_BRIDGE, THING2_WITH_BRIDGE, THING_WITHOUT_BRIDGE, THING_WITH_OTHER_BRIDGE));
registry.forceRemove(BRIDGE.getThingUID());
@@ -889,7 +889,7 @@ public class InboxOSGiTest extends JavaOSGiTest {
.anyMatch(forThingUID(THING1_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW))));
assertFalse(inbox.stream()
.anyMatch(forThingUID(THING2_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW))));
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()),
assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(),
hasItems(THING_WITHOUT_BRIDGE, THING_WITH_OTHER_BRIDGE));
});
}
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -113,14 +112,14 @@ public class ProfileTypeResourceTest extends JavaTest {
public void testGetAll() {
Stream<ProfileTypeDTO> result = resource.getProfileTypes(null, null, null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> list = result.toList();
assertThat(list.size(), is(4));
}
@Test
public void testGetProfileTypesForStateChannel1() {
Stream<ProfileTypeDTO> result = resource.getProfileTypes(null, pt1ChannelType1UID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> list = result.toList();
// should be both state profiles because the second state profile supports ALL item types on the channel side
assertThat(list.size(), is(2));
@@ -133,7 +132,7 @@ public class ProfileTypeResourceTest extends JavaTest {
@Test
public void testGetProfileTypesForOtherChannel() {
Stream<ProfileTypeDTO> result = resource.getProfileTypes(null, otherStateChannelTypeUID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> list = result.toList();
// should be only the second state profile because the first one is restricted to another item type on the
// channel side
@@ -148,7 +147,7 @@ public class ProfileTypeResourceTest extends JavaTest {
@Test
public void testGetProfileTypesForTriggerChannel1() {
Stream<ProfileTypeDTO> result = resource.getProfileTypes(null, pt3ChannelType1UID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> list = result.toList();
// should be both trigger profiles because the second trigger profile supports ALL channel types
assertThat(list.size(), is(2));
@@ -161,7 +160,7 @@ public class ProfileTypeResourceTest extends JavaTest {
@Test
public void testGetProfileTypesForTriggerChannel2() {
Stream<ProfileTypeDTO> result = resource.getProfileTypes(null, otherTriggerChannelTypeUID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> list = result.toList();
// should be only the second trigger profile because the first one is restricted to another channel type UID
assertThat(list.size(), is(1));
@@ -12,7 +12,6 @@
*/
package org.openhab.core.model.thing.test.hue;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -97,7 +96,7 @@ public class GenericThingProviderTest3 extends JavaOSGiTest {
.withRequired(false).withDefault("hello world").build(),
ConfigDescriptionParameterBuilder.create("testConf", ConfigDescriptionParameter.Type.TEXT)
.withRequired(false).withDefault("bar").build())
.collect(toList()))
.toList())
.build();
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
@@ -23,7 +23,6 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.measure.Quantity;
import javax.measure.quantity.Dimensionless;
@@ -137,8 +136,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
itemRegistry.update(updatedItem);
waitForAssert(() -> assertThat(events.size(), is(1)));
List<Event> stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance).toList();
assertThat(stateChanges.size(), is(1));
ItemUpdatedEvent change = (ItemUpdatedEvent) stateChanges.get(0);
@@ -442,8 +440,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events.size(), is(2)));
List<Event> updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList();
assertThat(updates.size(), is(1));
GroupStateUpdatedEvent update = (GroupStateUpdatedEvent) updates.get(0);
@@ -453,8 +450,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
.replace("{itemName}", groupItem.getName())));
assertThat(update.getItemState(), is(groupItem.getState()));
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes.size(), is(1));
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0);
@@ -493,7 +489,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events, hasSize(2)));
List<Event> groupItemStateChangedEvents = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
.toList();
assertThat(groupItemStateChangedEvents, hasSize(1));
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) groupItemStateChangedEvents.get(0);
@@ -535,12 +531,11 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events, hasSize(2)));
List<Event> itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance).toList();
assertThat(itemCommandEvents, hasSize(2));
List<Event> groupItemStateChangedEvents = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
.toList();
assertThat(groupItemStateChangedEvents, hasSize(0));
assertThat(groupItem.getState(), is(UnDefType.NULL));
@@ -565,12 +560,10 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events, hasSize(2)));
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes, hasSize(1));
List<Event> updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList();
assertThat(updates, hasSize(1));
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0);
@@ -594,10 +587,10 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
assertThat(events, hasSize(2));
changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList());
changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes, hasSize(0));
updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).collect(Collectors.toList());
updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList();
assertThat(updates, hasSize(2));
assertThat(groupItem.getState(), is(OnOffType.ON));
@@ -622,8 +615,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events, hasSize(2)));
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes, hasSize(1));
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0);
@@ -642,7 +634,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events, hasSize(2)));
changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList());
changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes, hasSize(1));
change = (GroupItemStateChangedEvent) changes.get(0);
@@ -756,8 +748,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events.size(), is(2)));
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0);
assertThat(change.getItemName(), is(groupItem.getName()));
@@ -775,7 +766,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest {
waitForAssert(() -> assertThat(events.size(), is(2)));
changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList());
changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes.size(), is(1));
change = (GroupItemStateChangedEvent) changes.get(0);
@@ -12,7 +12,6 @@
*/
package org.openhab.core.items;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
@@ -132,7 +131,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(Item::getName).collect(toList());
List<String> itemNames = items.stream().map(Item::getName).toList();
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME3));
@@ -144,7 +143,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(Item::getName).collect(toList());
List<String> itemNames = items.stream().map(Item::getName).toList();
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME3));
@@ -156,7 +155,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(Item::getName).collect(toList());
List<String> itemNames = items.stream().map(Item::getName).toList();
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2));
}
@@ -178,7 +177,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(GenericItem::getName).collect(toList());
List<String> itemNames = items.stream().map(GenericItem::getName).toList();
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2));
}
@@ -126,7 +126,7 @@ public class ThingFactoryTest extends JavaOSGiTest {
ChannelDefinition cd1 = new ChannelDefinitionBuilder("channel1", channelType1.getUID()).build();
ChannelDefinition cd2 = new ChannelDefinitionBuilder("channel2", channelType2.getUID()).build();
return Stream.of(cd1, cd2).collect(toList());
return Stream.of(cd1, cd2).toList();
}
@Test
@@ -204,7 +204,7 @@ public class ThingFactoryTest extends JavaOSGiTest {
.withMultiple(true).withLimitToOptions(true).build();
return ConfigDescriptionBuilder.create(uri)
.withParameters(Stream.of(p1, p2, p3, p4, p5, p6).collect(toList())).build();
.withParameters(Stream.of(p1, p2, p3, p4, p5, p6).toList()).build();
}
});
@@ -284,7 +284,7 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest {
private Thing createThing() {
ThingUID thingUID = new ThingUID(THING_TYPE_UID, "thing" + thingCount++);
List<Channel> channels = IntStream.range(0, CHANNEL_COUNT).mapToObj(index -> createChannel(thingUID, index))
.collect(Collectors.toList());
.toList();
return ThingBuilder.create(THING_TYPE_UID, thingUID).withChannels(channels).build();
}
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.*;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.measure.quantity.Temperature;
@@ -196,8 +195,8 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
}).when(profileFactoryMock).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class),
isA(ProfileContext.class));
when(profileFactoryMock.getSupportedProfileTypeUIDs()).thenReturn(Stream
.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList()));
when(profileFactoryMock.getSupportedProfileTypeUIDs())
.thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).toList());
manager.addProfileFactory(profileFactoryMock);
manager.addProfileAdvisor(profileAdvisorMock);
@@ -702,8 +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(FirmwareUpdateProgressInfoEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> list = events.get().stream().filter(FirmwareUpdateProgressInfoEvent.class::isInstance).toList();
assertTrue(list.size() >= SEQUENCE.length);
for (int i = 0; i < SEQUENCE.length; i++) {
FirmwareUpdateProgressInfoEvent event = (FirmwareUpdateProgressInfoEvent) list.get(i);
@@ -903,7 +902,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(FirmwareUpdateResultInfoEvent.class::isInstance).collect(Collectors.toList());
.filter(FirmwareUpdateResultInfoEvent.class::isInstance).toList();
assertEquals(expectedEventCount, allValues.size());
assertFailedFirmwareUpdate(THING1_UID, allValues.get(expectedEventCount - 1), text);
});
@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.AfterEach;
@@ -154,7 +153,7 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest {
int removed = itemChannelLinkRegistry.removeLinksForItem(itemToRemove);
assertThat(removed, is(1));
assertThat(itemChannelLinkRegistry.stream().map(ItemChannelLink::getItemName).collect(Collectors.toList()),
assertThat(itemChannelLinkRegistry.stream().map(ItemChannelLink::getItemName).toList(),
not(hasItem(itemToRemove)));
assertThat(itemChannelLinkRegistry.getAll(),
hasSize(BULK_ITEM_COUNT * BULK_THING_COUNT * BULK_CHANNEL_COUNT - 1));
@@ -169,7 +168,7 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest {
assertThat(removed, is(BULK_CHANNEL_COUNT));
assertThat(itemChannelLinkRegistry.stream().map(ItemChannelLink::getLinkedUID).map(ChannelUID::getThingUID)
.collect(Collectors.toList()), not(hasItem(thingToRemove)));
.toList(), not(hasItem(thingToRemove)));
assertThat(itemChannelLinkRegistry.getAll(),
hasSize((BULK_ITEM_COUNT * BULK_THING_COUNT - 1) * BULK_CHANNEL_COUNT));
}
@@ -16,7 +16,6 @@ import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.BeforeEach;
@@ -68,7 +67,7 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest {
public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions() throws Exception {
try (final AutoCloseable unused = loadedTestBundle()) {
List<ThingType> thingTypes = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> "wireless-router".equals(it.getUID().getId())).collect(Collectors.toList());
.filter(it -> "wireless-router".equals(it.getUID().getId())).toList();
assertThat(thingTypes.size(), is(1));
List<ChannelGroupType> channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes();
@@ -82,17 +81,13 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest {
List<ChannelDefinition> myChannel = channelDefs.stream().filter(
it -> "test".equals(it.getId()) && "system:my-channel".equals(it.getChannelTypeUID().getAsString()))
.collect(Collectors.toList());
.toList();
List<ChannelDefinition> sigStr = channelDefs.stream()
.filter(it -> "sigstr".equals(it.getId())
&& "system:signal-strength".equals(it.getChannelTypeUID().getAsString()))
.collect(Collectors.toList());
List<ChannelDefinition> sigStr = channelDefs.stream().filter(it -> "sigstr".equals(it.getId())
&& "system:signal-strength".equals(it.getChannelTypeUID().getAsString())).toList();
List<ChannelDefinition> lowBat = channelDefs.stream()
.filter(it -> "lowbat".equals(it.getId())
&& "system:low-battery".equals(it.getChannelTypeUID().getAsString()))
.collect(Collectors.toList());
List<ChannelDefinition> lowBat = channelDefs.stream().filter(it -> "lowbat".equals(it.getId())
&& "system:low-battery".equals(it.getChannelTypeUID().getAsString())).toList();
assertThat(myChannel.size(), is(1));
assertThat(sigStr.size(), is(1));