mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Fix SAT and null analysis issues (#3781)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
+3
-1
@@ -74,7 +74,9 @@ public class ScriptProfileFactory implements ProfileFactory, ProfileTypeProvider
|
|||||||
public void bindScriptTransformationService(ScriptTransformationService service, Map<String, Object> properties) {
|
public void bindScriptTransformationService(ScriptTransformationService service, Map<String, Object> properties) {
|
||||||
String serviceId = (String) properties.get(TransformationService.SERVICE_PROPERTY_NAME);
|
String serviceId = (String) properties.get(TransformationService.SERVICE_PROPERTY_NAME);
|
||||||
String serviceLabel = (String) properties.get(TransformationService.SERVICE_PROPERTY_LABEL);
|
String serviceLabel = (String) properties.get(TransformationService.SERVICE_PROPERTY_LABEL);
|
||||||
services.put(serviceId, new ServiceRecord(service, serviceLabel));
|
if (serviceId != null && serviceLabel != null) {
|
||||||
|
services.put(serviceId, new ServiceRecord(service, serviceLabel));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbindScriptTransformationService(ScriptTransformationService service, Map<String, Object> properties) {
|
public void unbindScriptTransformationService(ScriptTransformationService service, Map<String, Object> properties) {
|
||||||
|
|||||||
-1
@@ -169,7 +169,6 @@ public class RuleResource implements RESTResource {
|
|||||||
@QueryParam("prefix") final @Nullable String prefix, @QueryParam("tags") final @Nullable List<String> tags,
|
@QueryParam("prefix") final @Nullable String prefix, @QueryParam("tags") final @Nullable List<String> tags,
|
||||||
@QueryParam("summary") @Parameter(description = "summary fields only") @Nullable Boolean summary,
|
@QueryParam("summary") @Parameter(description = "summary fields only") @Nullable Boolean summary,
|
||||||
@DefaultValue("false") @QueryParam("staticDataOnly") @Parameter(description = "provides a cacheable list of values not expected to change regularly and honors the If-Modified-Since header, all other parameters are ignored") boolean staticDataOnly) {
|
@DefaultValue("false") @QueryParam("staticDataOnly") @Parameter(description = "provides a cacheable list of values not expected to change regularly and honors the If-Modified-Since header, all other parameters are ignored") boolean staticDataOnly) {
|
||||||
|
|
||||||
if ((summary == null || !summary) && !securityContext.isUserInRole(Role.ADMIN)) {
|
if ((summary == null || !summary) && !securityContext.isUserInRole(Role.ADMIN)) {
|
||||||
// users may only access the summary
|
// users may only access the summary
|
||||||
return JSONResponse.createErrorResponse(Status.UNAUTHORIZED, "Authentication required");
|
return JSONResponse.createErrorResponse(Status.UNAUTHORIZED, "Authentication required");
|
||||||
|
|||||||
+4
-1
@@ -53,7 +53,10 @@ import org.openhab.core.config.core.ConfigParser;
|
|||||||
import org.openhab.core.config.core.ConfigurableService;
|
import org.openhab.core.config.core.ConfigurableService;
|
||||||
import org.openhab.core.io.rest.JSONResponse;
|
import org.openhab.core.io.rest.JSONResponse;
|
||||||
import org.openhab.core.io.rest.RESTConstants;
|
import org.openhab.core.io.rest.RESTConstants;
|
||||||
import org.openhab.core.io.rest.auth.internal.*;
|
import org.openhab.core.io.rest.auth.internal.ExpiringUserSecurityContextCache;
|
||||||
|
import org.openhab.core.io.rest.auth.internal.JwtHelper;
|
||||||
|
import org.openhab.core.io.rest.auth.internal.JwtSecurityContext;
|
||||||
|
import org.openhab.core.io.rest.auth.internal.UserSecurityContext;
|
||||||
import org.osgi.framework.Constants;
|
import org.osgi.framework.Constants;
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
|||||||
-20
@@ -470,26 +470,6 @@ public class FeatureInstaller implements ConfigurationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean installFeature(String name) {
|
|
||||||
try {
|
|
||||||
Feature[] features = featuresService.listInstalledFeatures();
|
|
||||||
if (!anyMatchingFeature(features, withName(name))) {
|
|
||||||
featuresService.installFeature(name,
|
|
||||||
EnumSet.of(FeaturesService.Option.Upgrade, FeaturesService.Option.NoAutoRefreshBundles));
|
|
||||||
features = featuresService.listInstalledFeatures();
|
|
||||||
if (anyMatchingFeature(features, withName(name))) {
|
|
||||||
logger.debug("Installed '{}'", name);
|
|
||||||
postInstalledEvent(name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Failed installing '{}': {}", name, e.getMessage(), debugException(e));
|
|
||||||
configMapCache = null; // make sure we retry the installation
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void uninstallFeature(String name) {
|
private void uninstallFeature(String name) {
|
||||||
try {
|
try {
|
||||||
Feature[] features = featuresService.listInstalledFeatures();
|
Feature[] features = featuresService.listInstalledFeatures();
|
||||||
|
|||||||
+4
-4
@@ -62,11 +62,11 @@ import org.openhab.core.types.UnDefType;
|
|||||||
public class CommunicationManagerConversionTest {
|
public class CommunicationManagerConversionTest {
|
||||||
// TODO: remove test - only to show CommunicationManager is too complex
|
// TODO: remove test - only to show CommunicationManager is too complex
|
||||||
|
|
||||||
private static final List<Class<? extends Item>> itemTypes = List.of(CallItem.class, ColorItem.class,
|
private static final List<Class<? extends Item>> ITEM_TYPES = List.of(CallItem.class, ColorItem.class,
|
||||||
ContactItem.class, DateTimeItem.class, DimmerItem.class, ImageItem.class, LocationItem.class,
|
ContactItem.class, DateTimeItem.class, DimmerItem.class, ImageItem.class, LocationItem.class,
|
||||||
PlayerItem.class, RollershutterItem.class, StringItem.class);
|
PlayerItem.class, RollershutterItem.class, StringItem.class);
|
||||||
|
|
||||||
private static final List<Class<? extends Type>> types = List.of(DateTimeType.class, DecimalType.class,
|
private static final List<Class<? extends Type>> TYPES = List.of(DateTimeType.class, DecimalType.class,
|
||||||
HSBType.class, IncreaseDecreaseType.class, NextPreviousType.class, OnOffType.class, OpenClosedType.class,
|
HSBType.class, IncreaseDecreaseType.class, NextPreviousType.class, OnOffType.class, OpenClosedType.class,
|
||||||
PercentType.class, PlayPauseType.class, PointType.class, QuantityType.class, RawType.class,
|
PercentType.class, PlayPauseType.class, PointType.class, QuantityType.class, RawType.class,
|
||||||
RewindFastforwardType.class, StringType.class, UpDownType.class, UnDefType.class);
|
RewindFastforwardType.class, StringType.class, UpDownType.class, UnDefType.class);
|
||||||
@@ -74,9 +74,9 @@ public class CommunicationManagerConversionTest {
|
|||||||
private static Stream<Arguments> arguments()
|
private static Stream<Arguments> arguments()
|
||||||
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||||
List<Arguments> arguments = new ArrayList<>();
|
List<Arguments> arguments = new ArrayList<>();
|
||||||
for (Class<? extends Item> itemType : itemTypes) {
|
for (Class<? extends Item> itemType : ITEM_TYPES) {
|
||||||
Item item = itemType.getDeclaredConstructor(String.class).newInstance("testItem");
|
Item item = itemType.getDeclaredConstructor(String.class).newInstance("testItem");
|
||||||
for (Class<? extends Type> type : types) {
|
for (Class<? extends Type> type : TYPES) {
|
||||||
if (type.isEnum()) {
|
if (type.isEnum()) {
|
||||||
arguments.add(Arguments.of(item, type.getEnumConstants()[0]));
|
arguments.add(Arguments.of(item, type.getEnumConstants()[0]));
|
||||||
} else if (type == RawType.class) {
|
} else if (type == RawType.class) {
|
||||||
|
|||||||
+9
-14
@@ -13,15 +13,12 @@
|
|||||||
package org.openhab.core.thing.binding;
|
package org.openhab.core.thing.binding;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.hasEntry;
|
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -101,9 +98,8 @@ public class AbstractStorageBasedTypeProviderTest {
|
|||||||
List<ChannelDefinition> actualChannelDefinitions = actual.getChannelDefinitions();
|
List<ChannelDefinition> actualChannelDefinitions = actual.getChannelDefinitions();
|
||||||
assertThat(actualChannelDefinitions.size(), is(expectedChannelDefinitions.size()));
|
assertThat(actualChannelDefinitions.size(), is(expectedChannelDefinitions.size()));
|
||||||
for (ChannelDefinition expectedChannelDefinition : expectedChannelDefinitions) {
|
for (ChannelDefinition expectedChannelDefinition : expectedChannelDefinitions) {
|
||||||
ChannelDefinition actualChannelDefinition = actualChannelDefinitions.stream()
|
ChannelDefinition actualChannelDefinition = Objects.requireNonNull(actualChannelDefinitions.stream()
|
||||||
.filter(d -> d.getId().equals(expectedChannelDefinition.getId())).findFirst().orElse(null);
|
.filter(d -> d.getId().equals(expectedChannelDefinition.getId())).findFirst().orElse(null));
|
||||||
assertThat(actualChannelDefinition, is(notNullValue()));
|
|
||||||
assertChannelDefinition(actualChannelDefinition, expectedChannelDefinition);
|
assertChannelDefinition(actualChannelDefinition, expectedChannelDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,18 +141,17 @@ public class AbstractStorageBasedTypeProviderTest {
|
|||||||
List<ChannelDefinition> actualChannelDefinitions = actual.getChannelDefinitions();
|
List<ChannelDefinition> actualChannelDefinitions = actual.getChannelDefinitions();
|
||||||
assertThat(actualChannelDefinitions.size(), is(expectedChannelDefinitions.size()));
|
assertThat(actualChannelDefinitions.size(), is(expectedChannelDefinitions.size()));
|
||||||
for (ChannelDefinition expectedChannelDefinition : expectedChannelDefinitions) {
|
for (ChannelDefinition expectedChannelDefinition : expectedChannelDefinitions) {
|
||||||
ChannelDefinition actualChannelDefinition = actualChannelDefinitions.stream()
|
ChannelDefinition actualChannelDefinition = Objects.requireNonNull(actualChannelDefinitions.stream()
|
||||||
.filter(d -> d.getId().equals(expectedChannelDefinition.getId())).findFirst().orElse(null);
|
.filter(d -> d.getId().equals(expectedChannelDefinition.getId())).findFirst().orElse(null));
|
||||||
assertThat(actualChannelDefinition, is(notNullValue()));
|
|
||||||
assertChannelDefinition(actualChannelDefinition, expectedChannelDefinition);
|
assertChannelDefinition(actualChannelDefinition, expectedChannelDefinition);
|
||||||
}
|
}
|
||||||
List<ChannelGroupDefinition> expectedChannelGroupDefinitions = expected.getChannelGroupDefinitions();
|
List<ChannelGroupDefinition> expectedChannelGroupDefinitions = expected.getChannelGroupDefinitions();
|
||||||
List<ChannelGroupDefinition> actualChannelGroupDefinitions = actual.getChannelGroupDefinitions();
|
List<ChannelGroupDefinition> actualChannelGroupDefinitions = actual.getChannelGroupDefinitions();
|
||||||
assertThat(actualChannelGroupDefinitions.size(), is(expectedChannelGroupDefinitions.size()));
|
assertThat(actualChannelGroupDefinitions.size(), is(expectedChannelGroupDefinitions.size()));
|
||||||
for (ChannelGroupDefinition expectedChannelGroupDefinition : expectedChannelGroupDefinitions) {
|
for (ChannelGroupDefinition expectedChannelGroupDefinition : expectedChannelGroupDefinitions) {
|
||||||
ChannelGroupDefinition actualChannelGroupDefinition = actualChannelGroupDefinitions.stream()
|
ChannelGroupDefinition actualChannelGroupDefinition = Objects.requireNonNull(actualChannelGroupDefinitions
|
||||||
.filter(d -> d.getId().equals(expectedChannelGroupDefinition.getId())).findFirst().orElse(null);
|
.stream().filter(d -> d.getId().equals(expectedChannelGroupDefinition.getId())).findFirst()
|
||||||
assertThat(actualChannelGroupDefinition, is(notNullValue()));
|
.orElse(null));
|
||||||
assertChannelGroupDefinition(actualChannelGroupDefinition, expectedChannelGroupDefinition);
|
assertChannelGroupDefinition(actualChannelGroupDefinition, expectedChannelGroupDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -85,8 +85,8 @@ public class ItemStateConverterImpl implements ItemStateConverter {
|
|||||||
Class<? extends Quantity<?>> dimension = numberItem.getDimension();
|
Class<? extends Quantity<?>> dimension = numberItem.getDimension();
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
// explicit cast to Class<? extends Quantity> as JDK compiler complains
|
// explicit cast to Class<? extends Quantity> as JDK compiler complains
|
||||||
Unit<? extends Quantity<?>> conversionUnit = unitProvider
|
Unit<? extends Quantity<?>> conversionUnit = dimension == null ? null
|
||||||
.getUnit((Class<? extends Quantity>) dimension);
|
: unitProvider.getUnit((Class<? extends Quantity>) dimension);
|
||||||
if (conversionUnit != null
|
if (conversionUnit != null
|
||||||
&& UnitUtils.isDifferentMeasurementSystem(conversionUnit, quantityState.getUnit())) {
|
&& UnitUtils.isDifferentMeasurementSystem(conversionUnit, quantityState.getUnit())) {
|
||||||
return convertOrUndef(quantityState, conversionUnit);
|
return convertOrUndef(quantityState, conversionUnit);
|
||||||
|
|||||||
+8
-13
@@ -73,7 +73,8 @@ public class NumberItem extends GenericItem implements MetadataAwareItem {
|
|||||||
|
|
||||||
String itemTypeExtension = ItemUtil.getItemTypeExtension(getType());
|
String itemTypeExtension = ItemUtil.getItemTypeExtension(getType());
|
||||||
if (itemTypeExtension != null) {
|
if (itemTypeExtension != null) {
|
||||||
dimension = UnitUtils.parseDimension(itemTypeExtension);
|
Class<? extends Quantity<?>> dimension = UnitUtils.parseDimension(itemTypeExtension);
|
||||||
|
this.dimension = dimension;
|
||||||
if (dimension == null) {
|
if (dimension == null) {
|
||||||
throw new IllegalArgumentException("The given dimension " + itemTypeExtension + " is unknown.");
|
throw new IllegalArgumentException("The given dimension " + itemTypeExtension + " is unknown.");
|
||||||
} else if (unitProvider == null) {
|
} else if (unitProvider == null) {
|
||||||
@@ -104,13 +105,11 @@ public class NumberItem extends GenericItem implements MetadataAwareItem {
|
|||||||
if (dimension == null) {
|
if (dimension == null) {
|
||||||
DecimalType strippedCommand = new DecimalType(command.toBigDecimal());
|
DecimalType strippedCommand = new DecimalType(command.toBigDecimal());
|
||||||
internalSend(strippedCommand);
|
internalSend(strippedCommand);
|
||||||
|
} else if (command.getUnit().isCompatible(unit) || command.getUnit().inverse().isCompatible(unit)) {
|
||||||
|
internalSend(command);
|
||||||
} else {
|
} else {
|
||||||
if (command.getUnit().isCompatible(unit) || command.getUnit().inverse().isCompatible(unit)) {
|
logger.warn("Command '{}' to item '{}' was rejected because it is incompatible with the item unit '{}'",
|
||||||
internalSend(command);
|
command, name, unit);
|
||||||
} else {
|
|
||||||
logger.warn("Command '{}' to item '{}' was rejected because it is incompatible with the item unit '{}'",
|
|
||||||
command, name, unit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,12 +198,7 @@ public class NumberItem extends GenericItem implements MetadataAwareItem {
|
|||||||
public void addedMetadata(Metadata metadata) {
|
public void addedMetadata(Metadata metadata) {
|
||||||
if (dimension != null && UNIT_METADATA_NAMESPACE.equals(metadata.getUID().getNamespace())) {
|
if (dimension != null && UNIT_METADATA_NAMESPACE.equals(metadata.getUID().getNamespace())) {
|
||||||
Unit<?> unit = UnitUtils.parseUnit(metadata.getValue());
|
Unit<?> unit = UnitUtils.parseUnit(metadata.getValue());
|
||||||
if (unit == null) {
|
if ((unit == null) || (!unit.isCompatible(this.unit) && !unit.inverse().isCompatible(this.unit))) {
|
||||||
logger.warn("Unit '{}' could not be parsed to a known unit. Keeping old unit '{}' for item '{}'.",
|
|
||||||
metadata.getValue(), this.unit, name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!unit.isCompatible(this.unit) && !unit.inverse().isCompatible(this.unit)) {
|
|
||||||
logger.warn("Unit '{}' could not be parsed to a known unit. Keeping old unit '{}' for item '{}'.",
|
logger.warn("Unit '{}' could not be parsed to a known unit. Keeping old unit '{}' for item '{}'.",
|
||||||
metadata.getValue(), this.unit, name);
|
metadata.getValue(), this.unit, name);
|
||||||
return;
|
return;
|
||||||
@@ -222,6 +216,7 @@ public class NumberItem extends GenericItem implements MetadataAwareItem {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void removedMetadata(Metadata metadata) {
|
public void removedMetadata(Metadata metadata) {
|
||||||
|
Class<? extends Quantity<?>> dimension = this.dimension;
|
||||||
if (dimension != null && UNIT_METADATA_NAMESPACE.equals(metadata.getUID().getNamespace())) {
|
if (dimension != null && UNIT_METADATA_NAMESPACE.equals(metadata.getUID().getNamespace())) {
|
||||||
assert unitProvider != null;
|
assert unitProvider != null;
|
||||||
unit = unitProvider.getUnit((Class<? extends Quantity>) dimension);
|
unit = unitProvider.getUnit((Class<? extends Quantity>) dimension);
|
||||||
|
|||||||
+1
-2
@@ -176,8 +176,7 @@ public class I18nProviderImplTest {
|
|||||||
@MethodSource("getAllDimensions")
|
@MethodSource("getAllDimensions")
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Quantity<T>> void assertThatUnitProviderIsComplete(String dimensionName) {
|
public <T extends Quantity<T>> void assertThatUnitProviderIsComplete(String dimensionName) {
|
||||||
Class<? extends Quantity<?>> dimension = UnitUtils.parseDimension(dimensionName);
|
Class<? extends Quantity<?>> dimension = Objects.requireNonNull(UnitUtils.parseDimension(dimensionName));
|
||||||
assertThat(dimension, is(notNullValue()));
|
|
||||||
|
|
||||||
Unit<?> defaultUnit = i18nProviderImpl.getUnit((Class<T>) dimension);
|
Unit<?> defaultUnit = i18nProviderImpl.getUnit((Class<T>) dimension);
|
||||||
assertThat(dimensionName + " has no default unit", defaultUnit, notNullValue());
|
assertThat(dimensionName + " has no default unit", defaultUnit, notNullValue());
|
||||||
|
|||||||
+2
-2
@@ -463,11 +463,11 @@ public class QuantityTypeTest {
|
|||||||
assertEquals(8, bits.byteValue());
|
assertEquals(8, bits.byteValue());
|
||||||
bytes = new QuantityType<>("1 MB");
|
bytes = new QuantityType<>("1 MB");
|
||||||
assertEquals("1 MB", bytes.toString());
|
assertEquals("1 MB", bytes.toString());
|
||||||
bytes = new QuantityType<DataAmount>(1, MetricPrefix.MEGA(Units.BYTE));
|
bytes = new QuantityType<>(1, MetricPrefix.MEGA(Units.BYTE));
|
||||||
assertEquals("1 MB", bytes.toString());
|
assertEquals("1 MB", bytes.toString());
|
||||||
bytes = new QuantityType<>("1 GiB");
|
bytes = new QuantityType<>("1 GiB");
|
||||||
assertEquals("1 GiB", bytes.toString());
|
assertEquals("1 GiB", bytes.toString());
|
||||||
bytes = new QuantityType<DataAmount>(1, BinaryPrefix.GIBI(Units.BYTE));
|
bytes = new QuantityType<>(1, BinaryPrefix.GIBI(Units.BYTE));
|
||||||
assertEquals("1 GiB", bytes.toString());
|
assertEquals("1 GiB", bytes.toString());
|
||||||
QuantityType<DataAmount> bigAmount = new QuantityType<>("1 kio");
|
QuantityType<DataAmount> bigAmount = new QuantityType<>("1 kio");
|
||||||
QuantityType<DataAmount> octets = bigAmount.toUnit(Units.OCTET);
|
QuantityType<DataAmount> octets = bigAmount.toUnit(Units.OCTET);
|
||||||
|
|||||||
+4
-5
@@ -14,8 +14,7 @@ package org.openhab.core.automation.internal.module;
|
|||||||
|
|
||||||
import static java.util.Map.entry;
|
import static java.util.Map.entry;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -77,8 +76,8 @@ public class RunRuleModuleTest extends JavaOSGiTest {
|
|||||||
startLevelService = mock(StartLevelService.class);
|
startLevelService = mock(StartLevelService.class);
|
||||||
when(startLevelService.getStartLevel()).thenReturn(100);
|
when(startLevelService.getStartLevel()).thenReturn(100);
|
||||||
registerService(startLevelService, StartLevelService.class.getName());
|
registerService(startLevelService, StartLevelService.class.getName());
|
||||||
EventPublisher eventPublisher = getService(EventPublisher.class);
|
EventPublisher eventPublisher = Objects.requireNonNull(getService(EventPublisher.class));
|
||||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
ItemRegistry itemRegistry = Objects.requireNonNull(getService(ItemRegistry.class));
|
||||||
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
||||||
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
||||||
mock(CoreModuleHandlerFactory.class);
|
mock(CoreModuleHandlerFactory.class);
|
||||||
@@ -206,6 +205,6 @@ public class RunRuleModuleTest extends JavaOSGiTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ServiceReference<?> subscriberReference = registerService(eventSubscriber).getReference();
|
ServiceReference<?> subscriberReference = registerService(eventSubscriber).getReference();
|
||||||
assertNotNull(getServices(EventSubscriber.class, (reference) -> reference.equals(subscriberReference)));
|
assertNotNull(getServices(EventSubscriber.class, reference -> reference.equals(subscriberReference)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -14,8 +14,7 @@ package org.openhab.core.automation.internal.module;
|
|||||||
|
|
||||||
import static java.util.Map.entry;
|
import static java.util.Map.entry;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -87,8 +86,8 @@ public class RuntimeRuleTest extends JavaOSGiTest {
|
|||||||
startLevelService = mock(StartLevelService.class);
|
startLevelService = mock(StartLevelService.class);
|
||||||
when(startLevelService.getStartLevel()).thenReturn(100);
|
when(startLevelService.getStartLevel()).thenReturn(100);
|
||||||
registerService(startLevelService, StartLevelService.class.getName());
|
registerService(startLevelService, StartLevelService.class.getName());
|
||||||
EventPublisher eventPublisher = getService(EventPublisher.class);
|
EventPublisher eventPublisher = Objects.requireNonNull(getService(EventPublisher.class));
|
||||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
ItemRegistry itemRegistry = Objects.requireNonNull(getService(ItemRegistry.class));
|
||||||
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
||||||
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
||||||
mock(CoreModuleHandlerFactory.class);
|
mock(CoreModuleHandlerFactory.class);
|
||||||
@@ -136,7 +135,7 @@ public class RuntimeRuleTest extends JavaOSGiTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ServiceReference<?> subscriberReference = registerService(eventSubscriber).getReference();
|
ServiceReference<?> subscriberReference = registerService(eventSubscriber).getReference();
|
||||||
assertNotNull(getServices(EventSubscriber.class, (reference) -> reference.equals(subscriberReference)));
|
assertNotNull(getServices(EventSubscriber.class, reference -> reference.equals(subscriberReference)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+3
-4
@@ -15,8 +15,7 @@ package org.openhab.core.automation.module.timer.internal;
|
|||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -91,8 +90,8 @@ public abstract class BasicConditionHandlerTest extends JavaOSGiTest {
|
|||||||
startLevelService = mock(StartLevelService.class);
|
startLevelService = mock(StartLevelService.class);
|
||||||
when(startLevelService.getStartLevel()).thenReturn(100);
|
when(startLevelService.getStartLevel()).thenReturn(100);
|
||||||
registerService(startLevelService, StartLevelService.class.getName());
|
registerService(startLevelService, StartLevelService.class.getName());
|
||||||
EventPublisher eventPublisher = getService(EventPublisher.class);
|
EventPublisher eventPublisher = Objects.requireNonNull(getService(EventPublisher.class));
|
||||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
ItemRegistry itemRegistry = Objects.requireNonNull(getService(ItemRegistry.class));
|
||||||
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
||||||
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
||||||
mock(CoreModuleHandlerFactory.class);
|
mock(CoreModuleHandlerFactory.class);
|
||||||
|
|||||||
+3
-2
@@ -23,6 +23,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@@ -59,8 +60,8 @@ public class DayOfWeekConditionHandlerTest extends BasicConditionHandlerTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
EventPublisher eventPublisher = getService(EventPublisher.class);
|
EventPublisher eventPublisher = Objects.requireNonNull(getService(EventPublisher.class));
|
||||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
ItemRegistry itemRegistry = Objects.requireNonNull(getService(ItemRegistry.class));
|
||||||
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
||||||
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
||||||
mock(CoreModuleHandlerFactory.class);
|
mock(CoreModuleHandlerFactory.class);
|
||||||
|
|||||||
+4
-5
@@ -15,8 +15,7 @@ package org.openhab.core.automation.module.timer.internal;
|
|||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -83,8 +82,8 @@ public class RuntimeRuleTest extends JavaOSGiTest {
|
|||||||
startLevelService = mock(StartLevelService.class);
|
startLevelService = mock(StartLevelService.class);
|
||||||
when(startLevelService.getStartLevel()).thenReturn(100);
|
when(startLevelService.getStartLevel()).thenReturn(100);
|
||||||
registerService(startLevelService, StartLevelService.class.getName());
|
registerService(startLevelService, StartLevelService.class.getName());
|
||||||
EventPublisher eventPublisher = getService(EventPublisher.class);
|
EventPublisher eventPublisher = Objects.requireNonNull(getService(EventPublisher.class));
|
||||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
ItemRegistry itemRegistry = Objects.requireNonNull(getService(ItemRegistry.class));
|
||||||
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
||||||
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
||||||
mock(CoreModuleHandlerFactory.class);
|
mock(CoreModuleHandlerFactory.class);
|
||||||
@@ -174,7 +173,7 @@ public class RuntimeRuleTest extends JavaOSGiTest {
|
|||||||
if (event.getTopic().contains(testItemName)) {
|
if (event.getTopic().contains(testItemName)) {
|
||||||
itemEvents.add(event);
|
itemEvents.add(event);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public java.util.Set<String> getSubscribedEventTypes() {
|
public java.util.Set<String> getSubscribedEventTypes() {
|
||||||
|
|||||||
+3
-4
@@ -16,8 +16,7 @@ import static java.util.Map.entry;
|
|||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -89,8 +88,8 @@ public class RuleEventTest extends JavaOSGiTest {
|
|||||||
startLevelService = mock(StartLevelService.class);
|
startLevelService = mock(StartLevelService.class);
|
||||||
when(startLevelService.getStartLevel()).thenReturn(100);
|
when(startLevelService.getStartLevel()).thenReturn(100);
|
||||||
registerService(startLevelService, StartLevelService.class.getName());
|
registerService(startLevelService, StartLevelService.class.getName());
|
||||||
EventPublisher eventPublisher = getService(EventPublisher.class);
|
EventPublisher eventPublisher = Objects.requireNonNull(getService(EventPublisher.class));
|
||||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
ItemRegistry itemRegistry = Objects.requireNonNull(getService(ItemRegistry.class));
|
||||||
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
CoreModuleHandlerFactory coreModuleHandlerFactory = new CoreModuleHandlerFactory(getBundleContext(),
|
||||||
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
eventPublisher, itemRegistry, mock(TimeZoneProvider.class), mock(StartLevelService.class));
|
||||||
mock(CoreModuleHandlerFactory.class);
|
mock(CoreModuleHandlerFactory.class);
|
||||||
|
|||||||
+4
-8
@@ -13,12 +13,9 @@
|
|||||||
package org.openhab.core.thing.binding;
|
package org.openhab.core.thing.binding;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
import java.util.Objects;
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@@ -58,8 +55,7 @@ public class AbstractStorageBasedTypeProviderOSGiTest extends JavaOSGiTest {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
registerVolatileStorageService();
|
registerVolatileStorageService();
|
||||||
|
|
||||||
StorageService storageService = getService(StorageService.class);
|
StorageService storageService = Objects.requireNonNull(getService(StorageService.class));
|
||||||
assertThat(storageService, is(notNullValue()));
|
|
||||||
|
|
||||||
typeProvider = new AbstractStorageBasedTypeProvider(storageService) {
|
typeProvider = new AbstractStorageBasedTypeProvider(storageService) {
|
||||||
};
|
};
|
||||||
|
|||||||
+8
-8
@@ -104,7 +104,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final UnitProvider unitProviderMock = mock(UnitProvider.class);
|
private static final UnitProvider UNIT_PROVIDER_MOCK = mock(UnitProvider.class);
|
||||||
|
|
||||||
private static final String EVENT = "event";
|
private static final String EVENT = "event";
|
||||||
private static final String ITEM_NAME_1 = "testItem1";
|
private static final String ITEM_NAME_1 = "testItem1";
|
||||||
@@ -116,7 +116,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
private static final SwitchItem ITEM_2 = new SwitchItem(ITEM_NAME_2);
|
private static final SwitchItem ITEM_2 = new SwitchItem(ITEM_NAME_2);
|
||||||
private static final NumberItem ITEM_3 = new NumberItem(ITEM_NAME_3);
|
private static final NumberItem ITEM_3 = new NumberItem(ITEM_NAME_3);
|
||||||
private static final NumberItem ITEM_4 = new NumberItem(ITEM_NAME_4);
|
private static final NumberItem ITEM_4 = new NumberItem(ITEM_NAME_4);
|
||||||
private static NumberItem ITEM_5 = new NumberItem(ITEM_NAME_5); // will be replaced later by dimension item
|
private NumberItem item5 = new NumberItem(ITEM_NAME_5); // will be replaced later by dimension item
|
||||||
|
|
||||||
private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID("test", "type");
|
private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID("test", "type");
|
||||||
private static final ThingUID THING_UID = new ThingUID("test", "thing");
|
private static final ThingUID THING_UID = new ThingUID("test", "thing");
|
||||||
@@ -167,8 +167,8 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void beforeEach() {
|
public void beforeEach() {
|
||||||
when(unitProviderMock.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
|
when(UNIT_PROVIDER_MOCK.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
|
||||||
ITEM_5 = new NumberItem("Number:Temperature", ITEM_NAME_5, unitProviderMock);
|
item5 = new NumberItem("Number:Temperature", ITEM_NAME_5, UNIT_PROVIDER_MOCK);
|
||||||
|
|
||||||
safeCaller = getService(SafeCaller.class);
|
safeCaller = getService(SafeCaller.class);
|
||||||
assertNotNull(safeCaller);
|
assertNotNull(safeCaller);
|
||||||
@@ -179,7 +179,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
|
|
||||||
manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry,
|
manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry,
|
||||||
itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock,
|
itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock,
|
||||||
unitProviderMock);
|
UNIT_PROVIDER_MOCK);
|
||||||
|
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
switch (((Channel) invocation.getArguments()[0]).getKind()) {
|
switch (((Channel) invocation.getArguments()[0]).getKind()) {
|
||||||
@@ -227,7 +227,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
when(itemRegistryMock.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
|
when(itemRegistryMock.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
|
||||||
when(itemRegistryMock.get(eq(ITEM_NAME_3))).thenReturn(ITEM_3);
|
when(itemRegistryMock.get(eq(ITEM_NAME_3))).thenReturn(ITEM_3);
|
||||||
when(itemRegistryMock.get(eq(ITEM_NAME_4))).thenReturn(ITEM_4);
|
when(itemRegistryMock.get(eq(ITEM_NAME_4))).thenReturn(ITEM_4);
|
||||||
when(itemRegistryMock.get(eq(ITEM_NAME_5))).thenReturn(ITEM_5);
|
when(itemRegistryMock.get(eq(ITEM_NAME_5))).thenReturn(item5);
|
||||||
|
|
||||||
ChannelType channelType4 = mock(ChannelType.class);
|
ChannelType channelType4 = mock(ChannelType.class);
|
||||||
when(channelType4.getItemType()).thenReturn("Number:Temperature");
|
when(channelType4.getItemType()).thenReturn("Number:Temperature");
|
||||||
@@ -238,7 +238,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
|
|
||||||
when(thingRegistryMock.get(eq(THING_UID))).thenReturn(THING);
|
when(thingRegistryMock.get(eq(THING_UID))).thenReturn(THING);
|
||||||
|
|
||||||
manager.addItemFactory(new CoreItemFactory(unitProviderMock));
|
manager.addItemFactory(new CoreItemFactory(UNIT_PROVIDER_MOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -307,7 +307,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
|||||||
public void testItemCommandEventDecimal2Quantity2() {
|
public void testItemCommandEventDecimal2Quantity2() {
|
||||||
MetadataKey key = new MetadataKey(NumberItem.UNIT_METADATA_NAMESPACE, ITEM_NAME_5);
|
MetadataKey key = new MetadataKey(NumberItem.UNIT_METADATA_NAMESPACE, ITEM_NAME_5);
|
||||||
Metadata metadata = new Metadata(key, ImperialUnits.FAHRENHEIT.toString(), null);
|
Metadata metadata = new Metadata(key, ImperialUnits.FAHRENHEIT.toString(), null);
|
||||||
ITEM_5.addedMetadata(metadata);
|
item5.addedMetadata(metadata);
|
||||||
|
|
||||||
manager.receive(ItemEventFactory.createCommandEvent(ITEM_NAME_5, DecimalType.valueOf("20")));
|
manager.receive(ItemEventFactory.createCommandEvent(ITEM_NAME_5, DecimalType.valueOf("20")));
|
||||||
waitForAssert(() -> {
|
waitForAssert(() -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user