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