Add and fix more null annotations (#1407)

* Add and fix more null annotations
* Add more @NonNullByDefault and @Nullable annotations
* Remove unnecessary @NonNull annotations
* Fix a few other trivial SAT issues
* Add constructor injection for MDNSDiscoveryService

Signed-off-by: Wouter Born <github@maindrain.net>
pull/1411/head
Wouter Born 2020-04-06 10:45:39 +02:00 committed by GitHub
parent 1981e548aa
commit 945afcdb1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 189 additions and 168 deletions

View File

@ -27,6 +27,8 @@ import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.auth.Authentication;
import org.openhab.core.auth.AuthenticationException;
import org.openhab.core.auth.AuthenticationProvider;
@ -48,11 +50,12 @@ import org.osgi.service.component.annotations.Modified;
* @author Kai Kreuzer - Removed ManagedService and used DS configuration instead
* @author Yannick Schaus - provides a configuration with the ManagedUserLoginModule as a sufficient login module
*/
@NonNullByDefault
@Component(configurationPid = "org.openhab.jaas")
public class JaasAuthenticationProvider implements AuthenticationProvider {
private final String DEFAULT_REALM = "openhab";
private static final String DEFAULT_REALM = "openhab";
private String realmName;
private @Nullable String realmName;
@Override
public Authentication authenticate(final Credentials credentials) throws AuthenticationException {
@ -70,14 +73,14 @@ public class JaasAuthenticationProvider implements AuthenticationProvider {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Principal userPrincipal = new GenericUser(name);
Subject subject = new Subject(true, Set.of(userPrincipal), Collections.emptySet(), Set.of(userCredentials));
Thread.currentThread().setContextClassLoader(ManagedUserLoginModule.class.getClassLoader());
LoginContext loginContext = new LoginContext(realmName, subject, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
public void handle(@NonNullByDefault({}) Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password);

View File

@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.auth.client.oauth2.AccessTokenResponse;
@ -124,7 +123,7 @@ public class OAuthStoreHandlerImpl implements OAuthStoreHandler {
}
@Override
public void saveAccessTokenResponse(@NonNull String handle, @Nullable AccessTokenResponse pAccessTokenResponse) {
public void saveAccessTokenResponse(String handle, @Nullable AccessTokenResponse pAccessTokenResponse) {
AccessTokenResponse accessTokenResponse = pAccessTokenResponse;
if (accessTokenResponse == null) {
accessTokenResponse = new AccessTokenResponse(); // put empty

View File

@ -12,13 +12,15 @@
*/
package org.openhab.core.auth.oauth2client.internal;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Enum of types being used in the store
*
* @author Gary Tse - Initial contribution
*/
@NonNullByDefault
public enum StorageRecordType {
LAST_USED(".LastUsed"),
@ -31,7 +33,7 @@ public enum StorageRecordType {
this.suffix = suffix;
}
public @NonNull String getKey(String handle) {
public String getKey(@Nullable String handle) {
return (handle == null) ? this.suffix : (handle + this.suffix);
}

View File

@ -21,7 +21,6 @@ import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.module.script.ScriptEngineContainer;
@ -112,7 +111,7 @@ public class ScriptEngineManagerImpl implements ScriptEngineManager {
}
@Override
public @Nullable ScriptEngineContainer createScriptEngine(String scriptType, @NonNull String engineIdentifier) {
public @Nullable ScriptEngineContainer createScriptEngine(String scriptType, String engineIdentifier) {
ScriptEngineContainer result = null;
ScriptEngineFactory engineFactory = findEngineFactory(scriptType);
if (engineFactory == null) {

View File

@ -12,7 +12,7 @@
*/
package org.openhab.core.config.core.status;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link ConfigStatusSource} represents a source which would like to propagate its new configuration status. It is
@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.NonNull;
*
* @author Thomas Höfer - Initial contribution
*/
@NonNullByDefault
public abstract class ConfigStatusSource {
/** The id of the entity whose new configuration status is to be propagated. */
@ -30,7 +31,7 @@ public abstract class ConfigStatusSource {
*
* @param entityId the id of the entity whose new configuration status is to be propagated
*/
public ConfigStatusSource(@NonNull String entityId) {
public ConfigStatusSource(String entityId) {
super();
this.entityId = entityId;
}

View File

@ -23,7 +23,7 @@ import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceInfo;
import javax.jmdns.ServiceListener;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
@ -32,7 +32,9 @@ import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
import org.openhab.core.io.transport.mdns.MDNSClient;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
@ -48,6 +50,7 @@ import org.slf4j.LoggerFactory;
* @author Kai Kreuzer - Improved startup behavior and background discovery
* @author Andre Fuechsel - make {@link #startScan()} asynchronous
*/
@NonNullByDefault
@Component(immediate = true, service = DiscoveryService.class, configurationPid = "discovery.mdns")
public class MDNSDiscoveryService extends AbstractDiscoveryService implements ServiceListener {
@ -59,15 +62,17 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
private final Set<MDNSDiscoveryParticipant> participants = new CopyOnWriteArraySet<>();
private MDNSClient mdnsClient;
private final MDNSClient mdnsClient;
public MDNSDiscoveryService() {
@Activate
public MDNSDiscoveryService(final @Nullable Map<String, @Nullable Object> configProperties,
final @Reference MDNSClient mdnsClient) {
super(5);
}
@Reference
public void setMDNSClient(MDNSClient mdnsClient) {
this.mdnsClient = mdnsClient;
super.activate(configProperties);
if (isBackgroundDiscoveryEnabled()) {
for (MDNSDiscoveryParticipant participant : participants) {
mdnsClient.addServiceListener(participant.getServiceType(), this);
@ -78,19 +83,22 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
}
}
public void unsetMDNSClient(MDNSClient mdnsClient) {
@Deactivate
@Override
protected void deactivate() {
super.deactivate();
for (MDNSDiscoveryParticipant participant : participants) {
mdnsClient.removeServiceListener(participant.getServiceType(), this);
}
for (org.openhab.core.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant : oldParticipants) {
mdnsClient.removeServiceListener(participant.getServiceType(), this);
}
this.mdnsClient = null;
}
@Modified
@Override
protected void modified(@Nullable Map<@NonNull String, @Nullable Object> configProperties) {
protected void modified(@Nullable Map<String, @Nullable Object> configProperties) {
super.modified(configProperties);
}
@ -185,16 +193,14 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void addMDNSDiscoveryParticipant(MDNSDiscoveryParticipant participant) {
this.participants.add(participant);
if (mdnsClient != null && isBackgroundDiscoveryEnabled()) {
if (isBackgroundDiscoveryEnabled()) {
mdnsClient.addServiceListener(participant.getServiceType(), this);
}
}
protected void removeMDNSDiscoveryParticipant(MDNSDiscoveryParticipant participant) {
this.participants.remove(participant);
if (mdnsClient != null) {
mdnsClient.removeServiceListener(participant.getServiceType(), this);
}
mdnsClient.removeServiceListener(participant.getServiceType(), this);
}
@Deprecated
@ -202,7 +208,7 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
protected void addMDNSDiscoveryParticipant_old(
org.openhab.core.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant) {
this.oldParticipants.add(participant);
if (mdnsClient != null && isBackgroundDiscoveryEnabled()) {
if (isBackgroundDiscoveryEnabled()) {
mdnsClient.addServiceListener(participant.getServiceType(), this);
}
}
@ -211,9 +217,7 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
protected void removeMDNSDiscoveryParticipant_old(
org.openhab.core.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant) {
this.oldParticipants.remove(participant);
if (mdnsClient != null) {
mdnsClient.removeServiceListener(participant.getServiceType(), this);
}
mdnsClient.removeServiceListener(participant.getServiceType(), this);
}
@Override
@ -229,12 +233,12 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
}
@Override
public void serviceAdded(ServiceEvent serviceEvent) {
public void serviceAdded(@NonNullByDefault({}) ServiceEvent serviceEvent) {
considerService(serviceEvent);
}
@Override
public void serviceRemoved(ServiceEvent serviceEvent) {
public void serviceRemoved(@NonNullByDefault({}) ServiceEvent serviceEvent) {
for (MDNSDiscoveryParticipant participant : participants) {
if (participant.getServiceType().equals(serviceEvent.getType())) {
try {
@ -262,7 +266,7 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se
}
@Override
public void serviceResolved(ServiceEvent serviceEvent) {
public void serviceResolved(@NonNullByDefault({}) ServiceEvent serviceEvent) {
considerService(serviceEvent);
}

View File

@ -19,7 +19,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
@ -89,7 +88,7 @@ public class UsbSerialDiscoveryService extends AbstractDiscoveryService implemen
@Modified
@Override
protected void modified(@Nullable Map<@NonNull String, @Nullable Object> configProperties) {
protected void modified(@Nullable Map<String, @Nullable Object> configProperties) {
super.modified(configProperties);
}

View File

@ -158,7 +158,6 @@ public class SseResource {
@ApiOperation(value = "Initiates a new item state tracker connection", response = EventOutput.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
public Object getStateEvents() throws IOException, InterruptedException {
final SseStateEventOutput eventOutput = new SseStateEventOutput();
statesBroadcaster.add(eventOutput);
@ -186,7 +185,6 @@ public class SseResource {
@ApiResponse(code = 404, message = "Unknown connectionId") })
public Object updateTrackedItems(@PathParam("connectionId") String connectionId,
@ApiParam("items") Set<String> itemNames) {
try {
statesBroadcaster.updateTrackedItems(connectionId, itemNames);
} catch (IllegalArgumentException e) {

View File

@ -14,7 +14,7 @@ package org.openhab.core.persistence;
import java.util.Date;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.items.Item;
import org.openhab.core.types.State;
@ -28,6 +28,7 @@ import org.openhab.core.types.State;
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public interface HistoricItem {
/**
@ -35,7 +36,6 @@ public interface HistoricItem {
*
* @return the timestamp of the item
*/
@NonNull
Date getTimestamp();
/**
@ -43,7 +43,6 @@ public interface HistoricItem {
*
* @return the current state
*/
@NonNull
State getState();
/**
@ -51,7 +50,6 @@ public interface HistoricItem {
*
* @return the name of the item
*/
@NonNull
String getName();
}

View File

@ -16,7 +16,7 @@ import static org.openhab.core.magic.binding.MagicBindingConstants.*;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.ChannelUID;
@ -30,6 +30,7 @@ import org.openhab.core.types.Command;
*
* @author Henning Treu - Initial contribution
*/
@NonNullByDefault
public class MagicThermostatThingHandler extends BaseThingHandler {
public MagicThermostatThingHandler(Thing thing) {
@ -37,7 +38,7 @@ public class MagicThermostatThingHandler extends BaseThingHandler {
}
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (channelUID.getId().equals(CHANNEL_SET_TEMPERATURE)) {
if (command instanceof DecimalType || command instanceof QuantityType) {
String state = command.toFullString() + (command instanceof DecimalType ? " °C" : "");

View File

@ -27,7 +27,6 @@ import java.util.function.Function;
import javax.measure.Quantity;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.AbstractUID;
@ -650,12 +649,12 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
private static class NoOpProfile implements Profile {
@Override
public @NonNull ProfileTypeUID getProfileTypeUID() {
public ProfileTypeUID getProfileTypeUID() {
return new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "noop");
}
@Override
public void onStateUpdateFromItem(@NonNull State state) {
public void onStateUpdateFromItem(State state) {
// no-op
}
}

View File

@ -17,7 +17,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.items.Item;
@ -74,7 +73,7 @@ public class ItemChannelLinkRegistry extends AbstractLinkRegistry<ItemChannelLin
}
public Set<Item> getLinkedItems(final UID uid) {
return ((Stream<@NonNull Item>) super.getLinkedItemNames(uid).parallelStream()
return ((Stream<Item>) super.getLinkedItemNames(uid).parallelStream()
.map(itemName -> itemRegistry.get(itemName)).filter(Objects::nonNull)).collect(Collectors.toSet());
}
@ -85,7 +84,7 @@ public class ItemChannelLinkRegistry extends AbstractLinkRegistry<ItemChannelLin
* @return an unmodifiable set of bound things for the given item name
*/
public Set<Thing> getBoundThings(final String itemName) {
return ((Stream<@NonNull Thing>) getBoundChannels(itemName).parallelStream()
return ((Stream<Thing>) getBoundChannels(itemName).parallelStream()
.map(channelUID -> thingRegistry.get(channelUID.getThingUID())).filter(Objects::nonNull))
.collect(Collectors.toSet());
}

View File

@ -24,7 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Before;
import org.junit.Test;
import org.openhab.core.thing.ThingTypeUID;
@ -34,6 +34,7 @@ import org.openhab.core.thing.ThingTypeUID;
*
* @author Henning Treu - Initial contribution
*/
@NonNullByDefault
public class ThingTypeBuilderTest {
private static final String CONF_URI = "conf:uri";
@ -44,7 +45,7 @@ public class ThingTypeBuilderTest {
private static final String THING_TYPE_ID = "thingTypeId";
private static final String BINDING_ID = "bindingId";
private ThingTypeBuilder builder;
private @NonNullByDefault({}) ThingTypeBuilder builder;
@Before
public void setup() {
@ -212,15 +213,15 @@ public class ThingTypeBuilderTest {
assertThat(bridgeType.getLabel(), is(LABEL));
}
private Map<@NonNull String, String> mockProperties() {
Map<@NonNull String, String> result = new HashMap<>();
private Map<String, String> mockProperties() {
Map<String, String> result = new HashMap<>();
result.put("key1", "value1");
result.put("key2", "value2");
return result;
}
private <T> @NonNull List<T> mockList(Class<T> entityClass, int size) {
private <T> List<T> mockList(Class<T> entityClass, int size) {
List<T> result = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
result.add(mock(entityClass));

View File

@ -17,7 +17,6 @@ import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.registry.AbstractProvider;
@ -62,7 +61,7 @@ public class UIComponentProvider extends AbstractProvider<RootUIComponent>
}
@Override
public void add(@NonNull RootUIComponent element) {
public void add(RootUIComponent element) {
if (StringUtils.isEmpty(element.getUID())) {
throw new IllegalArgumentException("Invalid UID");
}
@ -76,7 +75,7 @@ public class UIComponentProvider extends AbstractProvider<RootUIComponent>
}
@Override
public @Nullable RootUIComponent remove(@NonNull String key) {
public @Nullable RootUIComponent remove(String key) {
RootUIComponent element = storage.remove(key);
if (element != null) {
notifyListenersAboutRemovedElement(element);
@ -87,7 +86,7 @@ public class UIComponentProvider extends AbstractProvider<RootUIComponent>
}
@Override
public @Nullable RootUIComponent update(@NonNull RootUIComponent element) {
public @Nullable RootUIComponent update(RootUIComponent element) {
if (storage.get(element.getUID()) != null) {
RootUIComponent oldElement = storage.put(element.getUID(), element);
if (oldElement != null) {

View File

@ -13,13 +13,14 @@
package org.openhab.core.ui.internal.components;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.registry.RegistryChangeListener;
import org.openhab.core.config.core.ConfigUtil;
@ -67,6 +68,7 @@ import org.slf4j.LoggerFactory;
*
* @author Yannick Schaus - Initial contribution
*/
@NonNullByDefault
@Component(service = SitemapProvider.class)
public class UIComponentSitemapProvider implements SitemapProvider, RegistryChangeListener<RootUIComponent> {
private final Logger logger = LoggerFactory.getLogger(UIComponentSitemapProvider.class);
@ -77,21 +79,26 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
private static final String SITEMAP_SUFFIX = ".sitemap";
private Map<String, Sitemap> sitemaps = new HashMap<>();
private UIComponentRegistryFactory componentRegistryFactory;
private UIComponentRegistry sitemapComponentRegistry;
private @Nullable UIComponentRegistryFactory componentRegistryFactory;
private @Nullable UIComponentRegistry sitemapComponentRegistry;
private final Set<ModelRepositoryChangeListener> modelChangeListeners = new CopyOnWriteArraySet<>();
@Override
public @Nullable Sitemap getSitemap(@NonNull String sitemapName) {
public @Nullable Sitemap getSitemap(String sitemapName) {
buildSitemap(sitemapName.replaceFirst(SITEMAP_PREFIX, ""));
return sitemaps.get(sitemapName);
}
@Override
public @NonNull Set<@NonNull String> getSitemapNames() {
public Set<String> getSitemapNames() {
UIComponentRegistry registry = sitemapComponentRegistry;
if (registry == null) {
return Collections.emptySet();
}
sitemaps.clear();
Collection<RootUIComponent> rootComponents = sitemapComponentRegistry.getAll();
Collection<RootUIComponent> rootComponents = registry.getAll();
// try building all sitemaps to leave the invalid ones out
for (RootUIComponent rootComponent : rootComponents) {
try {
@ -105,8 +112,13 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
return sitemaps.keySet();
}
protected Sitemap buildSitemap(String sitemapName) {
RootUIComponent rootComponent = sitemapComponentRegistry.get(sitemapName);
protected @Nullable Sitemap buildSitemap(String sitemapName) {
UIComponentRegistry registry = sitemapComponentRegistry;
if (registry == null) {
return null;
}
RootUIComponent rootComponent = registry.get(sitemapName);
if (rootComponent != null) {
try {
Sitemap sitemap = buildSitemap(rootComponent);
@ -141,7 +153,7 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
return sitemap;
}
protected Widget buildWidget(UIComponent component) {
protected @Nullable Widget buildWidget(UIComponent component) {
Widget widget = null;
switch (component.getType()) {
@ -261,8 +273,8 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
return widget;
}
private void setWidgetPropertyFromComponentConfig(Widget widget, UIComponent component, String configParamName,
int feature) {
private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UIComponent component,
String configParamName, int feature) {
if (component == null || component.getConfig() == null) {
return;
}
@ -292,12 +304,12 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
}
@Override
public void addModelChangeListener(@NonNull ModelRepositoryChangeListener listener) {
public void addModelChangeListener(ModelRepositoryChangeListener listener) {
modelChangeListeners.add(listener);
}
@Override
public void removeModelChangeListener(@NonNull ModelRepositoryChangeListener listener) {
public void removeModelChangeListener(ModelRepositoryChangeListener listener) {
modelChangeListeners.remove(listener);
}
@ -330,8 +342,12 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
}
protected void unsetComponentRegistryFactory(UIComponentRegistryFactory componentRegistryFactory) {
UIComponentRegistry registry = this.sitemapComponentRegistry;
if (registry != null) {
registry.removeRegistryChangeListener(this);
}
this.componentRegistryFactory = null;
this.sitemapComponentRegistry.removeRegistryChangeListener(this);
this.sitemapComponentRegistry = null;
}
}

View File

@ -42,15 +42,15 @@ import org.slf4j.LoggerFactory;
@Component(immediate = true, name = "org.openhab.core.ui.tiles")
public class TileService implements TileProvider {
private static final Logger logger = LoggerFactory.getLogger(TileService.class);
private final Logger logger = LoggerFactory.getLogger(TileService.class);
protected ConfigurationAdmin configurationAdmin;
protected Set<Tile> tiles = new CopyOnWriteArraySet<>();
private final static String LINK_NAME = "link-name";
private final static String LINK_URL = "link-url";
private final static String LINK_IMAGEURL = "link-imageurl";
private static final String LINK_NAME = "link-name";
private static final String LINK_URL = "link-url";
private static final String LINK_IMAGEURL = "link-imageurl";
@Activate
protected void activate(ComponentContext componentContext, Map<String, Object> properties) {

View File

@ -53,11 +53,11 @@ public class ExternalServiceTile implements Tile {
@Override
public String toString() {
final int MAXLEN = 100;
final int maxlen = 100;
String limitedImageUrl = imageUrl;
if (limitedImageUrl != null && limitedImageUrl.length() > MAXLEN) {
limitedImageUrl = imageUrl.substring(0, MAXLEN) + "...";
if (limitedImageUrl != null && limitedImageUrl.length() > maxlen) {
limitedImageUrl = imageUrl.substring(0, maxlen) + "...";
}
return "[name=" + name + ", url=" + url + ", overlay=" + overlay + ", imageUrl=" + limitedImageUrl + "]";

View File

@ -15,7 +15,6 @@ package org.openhab.core.auth;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
@ -56,7 +55,7 @@ public class GenericUser implements User {
}
@Override
public @NonNull String getUID() {
public String getUID() {
return name;
}

View File

@ -35,7 +35,6 @@ public interface UserRegistry extends Registry<User, String>, AuthenticationProv
* @param username the username of the new user
* @param password the user password
* @param roles the roles attributed to the new user
*
* @return the new registered {@link User} instance
*/
public User register(String username, String password, Set<String> roles);

View File

@ -16,7 +16,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.internal.types.CommandDescriptionImpl;
@ -55,7 +54,7 @@ public class MetadataCommandDescriptionProvider implements CommandDescriptionPro
}
@Override
public @Nullable CommandDescription getCommandDescription(@NonNull String itemName, @Nullable Locale locale) {
public @Nullable CommandDescription getCommandDescription(String itemName, @Nullable Locale locale) {
Metadata metadata = metadataRegistry.get(new MetadataKey(COMMANDDESCRIPTION_METADATA_NAMESPACE, itemName));
if (metadata != null) {

View File

@ -20,7 +20,6 @@ import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.items.Metadata;
@ -69,8 +68,7 @@ public class MetadataStateDescriptionFragmentProvider implements StateDescriptio
}
@Override
public @Nullable StateDescriptionFragment getStateDescriptionFragment(@NonNull String itemName,
@Nullable Locale locale) {
public @Nullable StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale) {
Metadata metadata = metadataRegistry.get(new MetadataKey(STATEDESCRIPTION_METADATA_NAMESPACE, itemName));
if (metadata != null) {
@ -145,7 +143,7 @@ public class MetadataStateDescriptionFragmentProvider implements StateDescriptio
}
@Override
public @NonNull Integer getRank() {
public Integer getRank() {
return rank;
}
}

View File

@ -33,7 +33,7 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class StringListType implements Command, State {
final protected List<String> typeDetails;
protected final List<String> typeDetails;
// constants
public static final String DELIMITER = ",";

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.openhab.core.events.EventPublisher;
@ -45,6 +45,7 @@ import org.openhab.core.types.StateOption;
* @author Christoph Knauf - Initial contribution, event tests
* @author Simon Kaufmann - migrated from Groovy to Java
*/
@NonNullByDefault
@SuppressWarnings("null")
public class GenericItemTest {
@ -150,7 +151,7 @@ public class GenericItemTest {
when(commandDescriptionService.getCommandDescription("test", null)).thenReturn(new CommandDescription() {
@Override
public @NonNull List<@NonNull CommandOption> getCommandOptions() {
public List<CommandOption> getCommandOptions() {
return Arrays.asList(new CommandOption("ALERT", "Alert"), new CommandOption("REBOOT", "Reboot"));
}
});
@ -168,7 +169,7 @@ public class GenericItemTest {
.thenReturn(new CommandDescription() {
@Override
public @NonNull List<@NonNull CommandOption> getCommandOptions() {
public List<CommandOption> getCommandOptions() {
return Arrays.asList(new CommandOption("C1", "Command 1"), new CommandOption("C2", "Command 2"),
new CommandOption("C3", "Command 3"));
}
@ -183,7 +184,7 @@ public class GenericItemTest {
TestItem item = new TestItem("test");
StateDescriptionService stateDescriptionService = mock(StateDescriptionService.class);
List<@NonNull StateOption> stateOptions = Arrays.asList(new StateOption("STATE1", "State 1"),
List<StateOption> stateOptions = Arrays.asList(new StateOption("STATE1", "State 1"),
new StateOption("STATE2", "State 2"));
when(stateDescriptionService.getStateDescription("test", null)).thenReturn(
StateDescriptionFragmentBuilder.create().withOptions(stateOptions).build().toStateDescription());

View File

@ -27,7 +27,8 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.openhab.core.automation.Action;
@ -57,7 +58,6 @@ import org.openhab.core.items.events.ItemEventFactory;
import org.openhab.core.library.items.SwitchItem;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -67,13 +67,13 @@ import org.slf4j.LoggerFactory;
* @author Benedikt Niehues - Initial contribution
* @author Kai Kreuzer - ported test to Java
*/
@NonNullByDefault
public class RuleEventTest extends JavaOSGiTest {
final Logger logger = LoggerFactory.getLogger(RuleEventTest.class);
VolatileStorageService volatileStorageService = new VolatileStorageService();
private final Logger logger = LoggerFactory.getLogger(RuleEventTest.class);
Event itemEvent = null;
Event ruleRemovedEvent = null;
private @Nullable Event itemEvent = null;
private @Nullable Event ruleRemovedEvent = null;
public RuleEventTest() {
}
@ -87,7 +87,7 @@ public class RuleEventTest extends JavaOSGiTest {
}
@Override
public @NonNull Collection<@NonNull Item> getAll() {
public Collection<Item> getAll() {
return Arrays.asList(new Item[] { new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"),
new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"),
new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2") });
@ -118,7 +118,7 @@ public class RuleEventTest extends JavaOSGiTest {
}
@Override
public EventFilter getEventFilter() {
public @Nullable EventFilter getEventFilter() {
return null;
}
@ -186,7 +186,7 @@ public class RuleEventTest extends JavaOSGiTest {
}
@Override
public EventFilter getEventFilter() {
public @Nullable EventFilter getEventFilter() {
return null;
}
};
@ -215,7 +215,7 @@ public class RuleEventTest extends JavaOSGiTest {
}
@Override
public EventFilter getEventFilter() {
public @Nullable EventFilter getEventFilter() {
return null;
}

View File

@ -18,7 +18,7 @@ import static org.mockito.Mockito.*;
import java.util.Collections;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
@ -57,6 +57,7 @@ import org.openhab.core.thing.type.ThingTypeBuilder;
* @author Andre Fuechsel - Added tests for device id
* @author Simon Kaufmann - ported to Java
*/
@NonNullByDefault
public class DynamicThingUpdateOSGiTest extends JavaOSGiTest {
private static final int DEFAULT_TTL = 60;
@ -73,11 +74,11 @@ public class DynamicThingUpdateOSGiTest extends JavaOSGiTest {
private static final ThingType THING_TYPE = ThingTypeBuilder.instance(THING_TYPE_UID, "label")
.withRepresentationProperty(DEVICE_ID_KEY).isListed(true).build();
private Inbox inbox;
private ManagedThingProvider managedThingProvider;
private ThingHandler thingHandler;
private @NonNullByDefault({}) Inbox inbox;
private @NonNullByDefault({}) ManagedThingProvider managedThingProvider;
private @NonNullByDefault({}) ThingHandler thingHandler;
private volatile ThingHandlerCallback callback;
private volatile @NonNullByDefault({}) ThingHandlerCallback callback;
@Before
public void setUp() {
@ -110,12 +111,12 @@ public class DynamicThingUpdateOSGiTest extends JavaOSGiTest {
ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {
@Override
public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return THING_TYPE_UID.equals(thingTypeUID);
}
@Override
protected @Nullable ThingHandler createHandler(@NonNull Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
thingHandler = createThingHandler(thing);
return thingHandler;
}

View File

@ -295,7 +295,6 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest {
delay = ephemerisManager.getDaysUntil(today, next);
assertEquals(4, delay);
}
}
@Test

View File

@ -18,7 +18,7 @@ import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
@ -41,10 +41,11 @@ import org.openhab.core.test.java.JavaOSGiTest;
* @author Andre Fuechsel - extended with tag tests
* @author Kai Kreuzer - added tests for all items changed cases
*/
@NonNullByDefault
public class ItemUpdaterOSGiTest extends JavaOSGiTest {
private EventPublisher eventPublisher;
private ItemRegistry itemRegistry;
private @NonNullByDefault({}) EventPublisher eventPublisher;
private @NonNullByDefault({}) ItemRegistry itemRegistry;
private final ConcurrentLinkedQueue<Event> receivedEvents = new ConcurrentLinkedQueue<>();
@Before
@ -60,12 +61,12 @@ public class ItemUpdaterOSGiTest extends JavaOSGiTest {
EventSubscriber eventSubscriber = new EventSubscriber() {
@Override
public void receive(@NonNull Event event) {
public void receive(Event event) {
receivedEvents.add(event);
}
@Override
public @NonNull Set<@NonNull String> getSubscribedEventTypes() {
public Set<String> getSubscribedEventTypes() {
return Collections.singleton(ItemStateChangedEvent.TYPE);
}

View File

@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
@ -84,19 +85,20 @@ import org.osgi.service.component.ComponentContext;
* @author Thomas Höfer - Thing type constructor modified because of thing properties introduction
* @author Markus Rathgeb - Migrated from Groovy to plain Java
*/
@NonNullByDefault
public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "thingStatusInfoI18nTest.bundle";
private static final ChannelTypeUID CHANNEL_TYPE_7_UID = new ChannelTypeUID("hue:num-dynamic");
private ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService;
private ItemRegistry itemRegistry;
private ItemChannelLinkRegistry linkRegistry;
private @NonNullByDefault({}) ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService;
private @NonNullByDefault({}) ItemRegistry itemRegistry;
private @NonNullByDefault({}) ItemChannelLinkRegistry linkRegistry;
@Mock
private ComponentContext componentContext;
private @NonNullByDefault({}) ComponentContext componentContext;
private Bundle testBundle;
private @NonNullByDefault({}) Bundle testBundle;
@Before
public void setup() throws Exception {
@ -145,12 +147,12 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest {
registerService(new ChannelTypeProvider() {
@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return channelTypes;
}
@Override
public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
for (final ChannelType channelType : channelTypes) {
if (channelType.getUID().equals(channelTypeUID)) {
return channelType;
@ -405,9 +407,9 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest {
* Helper
*/
class TestDynamicStateDescriptionProvider extends BaseDynamicStateDescriptionProvider {
final StateDescription newState = StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.valueOf(10))
.withMaximum(BigDecimal.valueOf(100)).withStep(BigDecimal.valueOf(5)).withPattern("VALUE %d")
.withReadOnly(false)
final @Nullable StateDescription newState = StateDescriptionFragmentBuilder.create()
.withMinimum(BigDecimal.valueOf(10)).withMaximum(BigDecimal.valueOf(100))
.withStep(BigDecimal.valueOf(5)).withPattern("VALUE %d").withReadOnly(false)
.withOptions(Arrays.asList(new StateOption("value0", "label0"), new StateOption("value1", "label1")))
.build().toStateDescription();
@ -454,7 +456,7 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest {
}
@Override
protected ThingHandler createHandler(Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
return new AbstractThingHandler(thing) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
@ -502,7 +504,7 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest {
*/
private class BundleResolverImpl implements BundleResolver {
@Override
public Bundle resolveBundle(Class<?> clazz) {
public Bundle resolveBundle(@Nullable Class<?> clazz) {
if (clazz != null && clazz.equals(AbstractThingHandler.class)) {
return testBundle;
} else {

View File

@ -26,7 +26,7 @@ import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
@ -93,20 +93,14 @@ import org.osgi.service.component.ComponentContext;
* @author Simon Kaufmann - Initial contribution
* @author Christoph Weitkamp - Added preconfigured ChannelGroupBuilder
*/
@NonNullByDefault
public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
private ManagedThingProvider managedThingProvider;
private ItemRegistry itemRegistry;
private ThingRegistry thingRegistry;
private ReadyService readyService;
private ItemChannelLinkRegistry itemChannelLinkRegistry;
private ThingManager thingManager;
private static final String CONFIG_PARAM_NAME = "test";
private static final String BINDING_ID = "binding";
private static final String CHANNEL_ID = "channel";
private static final ChannelTypeUID CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, CHANNEL_ID);
private static final String CHANNEL_GROUP_ID = "channel-group";
@ -123,16 +117,22 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
private static final ChannelGroupUID CHANNEL_GROUP_UID = new ChannelGroupUID(THING_UID, CHANNEL_GROUP_ID);
private Thing thing;
private URI configDescriptionThing;
private URI configDescriptionChannel;
private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry;
private @NonNullByDefault({}) ItemRegistry itemRegistry;
private @NonNullByDefault({}) ManagedThingProvider managedThingProvider;
private @NonNullByDefault({}) ThingRegistry thingRegistry;
private @NonNullByDefault({}) ReadyService readyService;
private @NonNullByDefault({}) Storage<Boolean> storage;
private @NonNullByDefault({}) ThingManager thingManager;
private Storage<Boolean> storage;
private @NonNullByDefault({}) URI configDescriptionChannel;
private @NonNullByDefault({}) URI configDescriptionThing;
private @NonNullByDefault({}) Thing thing;
@Before
public void setUp() throws Exception {
configDescriptionThing = new URI("test:test");
configDescriptionChannel = new URI("test:channel");
configDescriptionThing = new URI("test:test");
thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(Collections.singletonList( //
ChannelBuilder.create(CHANNEL_UID, "Switch").withLabel("Test Label").withDescription("Test Description")
.withType(CHANNEL_TYPE_UID).withDefaultTags(Collections.singleton("Test Tag")).build() //
@ -320,7 +320,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
registerChannelTypeProvider();
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
});
@ -354,7 +354,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
@ -373,7 +373,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
});
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
@ -430,7 +430,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
@ -449,7 +449,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
});
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
@ -506,7 +506,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
@ -525,7 +525,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
});
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
@ -1062,12 +1062,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
}
@Override
public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return this.thingTypeUID.equals(thingTypeUID);
}
@Override
protected @Nullable ThingHandler createHandler(@NonNull Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
return thingHandlerProducer.apply(thing);
}
};
@ -1079,12 +1079,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest {
AtomicReference<ThingHandlerCallback> thc = new AtomicReference<>();
ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {
@Override
public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return true;
}
@Override
protected @Nullable ThingHandler createHandler(@NonNull Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingHandler mockHandler = mock(ThingHandler.class);
doAnswer(a -> {
thc.set((ThingHandlerCallback) a.getArguments()[0]);

View File

@ -23,7 +23,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
@ -58,10 +58,11 @@ import org.osgi.framework.ServiceRegistration;
* @author Stefan Bußweiler - Initial contribution
* @author Kai Kreuzer - Moved createThing test from managed provider
*/
@NonNullByDefault
public class ThingRegistryOSGiTest extends JavaOSGiTest {
ManagedThingProvider managedThingProvider;
ServiceRegistration<?> thingHandlerFactoryServiceReg;
private @NonNullByDefault({}) ManagedThingProvider managedThingProvider;
private @NonNullByDefault({}) ServiceRegistration<?> thingHandlerFactoryServiceReg;
private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID("binding:type");
private static final ThingUID THING_UID = new ThingUID(THING_TYPE_UID, "id");
@ -69,8 +70,8 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest {
private static final String THING1_ID = "testThing1";
private static final String THING2_ID = "testThing2";
Map<@NonNull String, @NonNull Object> changedParameters = null;
Event receivedEvent = null;
private @Nullable Map<String, Object> changedParameters = null;
private @Nullable Event receivedEvent = null;
@Before
public void setUp() {
@ -99,7 +100,7 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest {
}
@Override
public EventFilter getEventFilter() {
public @Nullable EventFilter getEventFilter() {
return null;
}
@ -143,12 +144,11 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest {
ThingHandler thingHandler = new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
public void handleConfigurationUpdate(
@NonNull Map<@NonNull String, @NonNull Object> configurationParameters) {
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
changedParameters = configurationParameters;
}
};
@ -158,16 +158,16 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest {
ThingProvider thingProvider = new ThingProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) {
public void addProviderChangeListener(ProviderChangeListener<Thing> listener) {
}
@Override
public Collection<@NonNull Thing> getAll() {
public Collection<Thing> getAll() {
return Collections.singleton(thing);
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) {
public void removeProviderChangeListener(ProviderChangeListener<Thing> listener) {
}
};
@ -208,17 +208,17 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest {
ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {
@Override
public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return true;
}
@Override
protected @Nullable ThingHandler createHandler(@NonNull Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
return null;
}
@Override
public @Nullable Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration,
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
@Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
assertThat(thingTypeUID, is(expectedThingTypeUID));
assertThat(configuration, is(expectedConfiguration));
@ -237,7 +237,11 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest {
waitForAssert(() -> {
assertTrue(thingResultWrapper.get() != null);
});
assertThat(thing, is(thingResultWrapper.get()));
assertThat(thing, is(notNullValue()));
if (thing != null) {
assertThat(thing, is(thingResultWrapper.get()));
}
}
private void registerThingHandlerFactory(ThingHandlerFactory thingHandlerFactory) {