From ad936cd83f70d9ac9732f8e1b94acc04939fe9ed Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Mon, 14 Feb 2022 11:33:50 +0100 Subject: [PATCH] Add more null annotations (#2742) * Add more null annotations * Fix mock name Adds null annotations to most of the tests as well as a few other classes. Also fixes a few other SAT findings. Fixes ~300 SAT findings in total. Signed-off-by: Wouter Born --- .../sample/internal/SampleAddonService.java | 37 +- .../AudioConsoleCommandExtension.java | 7 +- .../core/audio/utils/AudioWaveUtils.java | 2 +- .../internal/AbstractAudioServletTest.java | 21 +- .../core/audio/internal/AudioConsoleTest.java | 16 +- .../core/audio/internal/AudioFormatTest.java | 2 + .../internal/AudioManagerServletTest.java | 10 +- .../core/audio/internal/AudioManagerTest.java | 17 +- .../core/audio/internal/AudioServletTest.java | 2 + .../utils/BundledSoundFileHandler.java | 2 + .../rulesupport/loader/ScriptFileWatcher.java | 1 - .../core/automation/AnnotatedActions.java | 3 + .../openhab/core/automation/RuleStatus.java | 3 + .../core/automation/RuleStatusDetail.java | 3 + .../openhab/core/automation/Visibility.java | 2 + .../internal/ConnectionValidatorTest.java | 2 + .../automation/internal/RulePrefixTest.java | 2 + ...nnotationActionModuleTypeProviderTest.java | 22 +- ...atedThingActionModuleTypeProviderTest.java | 35 +- .../util/ReferenceResolverUtilTest.java | 7 +- .../core/ConfigDescriptionBuilderTest.java | 4 +- ...ConfigDescriptionParameterBuilderTest.java | 2 + .../core/config/core/ConfigUtilTest.java | 2 + .../i18n/I18nConfigOptionsProviderTest.java | 2 + ...dataConfigDescriptionProviderImplTest.java | 50 +-- .../normalization/NormalizerTest.java | 2 + .../ConfigValidationExceptionTest.java | 4 +- .../config/discovery/DiscoveryResultFlag.java | 3 + .../console/InboxConsoleCommandExtension.java | 4 +- .../AbstractDiscoveryServiceTest.java | 19 +- .../discovery/DiscoveryResultBuilderTest.java | 6 +- .../discovery/inbox/InboxPredicatesTest.java | 2 + .../inbox/events/InboxEventFactoryTest.java | 2 + .../internal/AutomaticInboxProcessorTest.java | 160 ++++---- .../internal/DiscoveryResultImplTest.java | 2 + .../internal/PersistentInboxTest.java | 66 +-- .../ConfigDispatcherFileWatcherTest.java | 24 +- .../org/openhab/core/id/InstanceUUIDTest.java | 2 + .../core/io/bin2json/Bin2JsonTest.java | 2 + .../console/eclipse/internal/OSGiConsole.java | 2 + .../console/karaf/internal/OSGiConsole.java | 2 + .../rfc147/internal/CommandWrapper.java | 2 + .../internal/ConsoleCommandsContainer.java | 2 + .../rfc147/internal/ConsoleSupportRfc147.java | 30 +- .../console/rfc147/internal/OSGiConsole.java | 2 + .../HelpConsoleCommandExtension.java | 12 +- .../org/openhab/core/io/console/Console.java | 3 + .../core/io/console/ConsoleInterpreter.java | 2 + .../HttpContextFactoryServiceImplTest.java | 28 +- .../core/io/net/exec/ExecUtilTest.java | 2 + .../core/io/net/http/BaseHttpUtilTest.java | 11 +- .../io/net/http/HttpRequestBuilderTest.java | 2 + .../core/io/net/http/HttpUtilTest.java | 2 + .../ExtensibleTrustManagerImplTest.java | 104 ++--- .../internal/WebClientFactoryImplTest.java | 14 +- ...nrichedConfigDescriptionDTOMapperTest.java | 2 + .../channel/ChannelTypeResourceTest.java | 28 +- .../config/ConfigDescriptionResourceTest.java | 14 +- .../item/MetadataSelectorMatcherTest.java | 12 +- .../persistence/PersistenceResourceTest.java | 21 +- .../core/item/EnrichedItemDTOMapperTest.java | 12 +- .../thing/EnrichedThingDTOMapperTest.java | 45 +- .../io/rest/log/internal/LogConstants.java | 3 + .../sitemap/internal/SitemapResourceTest.java | 127 +++--- .../rest/sse/internal/util/SseUtilTest.java | 2 + .../openhab/core/io/rest/RESTConstants.java | 3 + .../core/io/rest/Stream2JSONInputStream.java | 7 +- .../core/io/rest/JSONResponseTest.java | 2 + .../io/rest/Stream2JSONInputStreamTest.java | 16 +- .../rest/internal/filter/CorsFilterTest.java | 40 +- .../rest/internal/filter/ProxyFilterTest.java | 49 +-- .../modbus/ModbusReadFunctionCode.java | 3 + .../modbus/ModbusWriteFunctionCode.java | 6 +- .../endpoint/ModbusSlaveEndpointVisitor.java | 1 - .../modbus/test/AbstractRequestComparer.java | 4 +- .../modbus/test/BasicBitArrayTest.java | 2 + .../test/BitUtilitiesExtractBitTest.java | 2 + .../test/BitUtilitiesExtractFloat32Test.java | 2 + ...UtilitiesExtractIndividualMethodsTest.java | 2 + .../test/BitUtilitiesExtractInt8Test.java | 2 + ...tilitiesExtractStateFromRegistersTest.java | 10 +- .../test/BitUtilitiesExtractStringTest.java | 2 + ...UtilitiesTranslateCommand2BooleanTest.java | 2 + .../io/transport/modbus/test/CoilMatcher.java | 4 +- .../modbus/test/IntegrationTestSupport.java | 24 +- .../test/ModbusSlaveEndpointTestCase.java | 2 + ...usSlaveErrorResponseExceptionImplTest.java | 2 + .../modbus/test/RegisterMatcher.java | 4 +- .../transport/modbus/test/ResultCaptor.java | 10 +- .../io/transport/modbus/test/SmokeTest.java | 24 +- .../modbus/test/ValueBufferTest.java | 2 + .../test/WriteRequestJsonUtilitiesTest.java | 7 +- .../upnp/internal/UpnpIOServiceTest.java | 62 +-- .../internal/MappingUriExtensionsTest.java | 9 +- .../ScriptEngineConsoleCommandExtension.java | 20 +- .../extensions/PersistenceExtensionsTest.java | 20 +- .../core/semantics/SemanticTagsTest.java | 8 +- .../semantics/SemanticsPredicatesTest.java | 8 +- .../internal/SemanticsServiceImplTest.java | 18 +- .../json/internal/JsonStorageTest.java | 6 +- .../modules/MagicMultiActionMarker.java | 2 + .../MagicMultiServiceMultiActions.java | 4 +- .../modules/MagicSingleActionService.java | 6 +- .../modules/MagicThingActionsService.java | 7 +- .../firmware/MagicFirmwareProvider.java | 19 +- .../service/MagicMultiInstanceService.java | 2 + .../MagicMultiInstanceServiceMarker.java | 3 +- .../handler/MagicColorLightHandlerTest.java | 14 +- .../MagicDimmableLightHandlerTest.java | 14 +- .../handler/MagicOnOffLightHandlerTest.java | 14 +- .../internal/MagicServiceImplTest.java | 4 +- .../openhab/core/test/AsyncResultWrapper.java | 8 +- .../openhab/core/test/BundleCloseable.java | 2 + .../org/openhab/core/test/TestPortUtil.java | 3 + .../org/openhab/core/test/TestServer.java | 5 +- .../internal/java/MissingServiceAnalyzer.java | 7 +- .../test/storage/VolatileStorageService.java | 5 +- .../openhab/core/test/java/JavaTestTest.java | 15 +- .../thing/xml/internal/XmlHelperTest.java | 2 + .../org/openhab/core/thing/ThingStatus.java | 3 + .../openhab/core/thing/ThingStatusDetail.java | 3 + ...BaseDynamicCommandDescriptionProvider.java | 1 - .../core/thing/ChannelGroupUIDTest.java | 2 + .../org/openhab/core/thing/ChannelTest.java | 2 + .../openhab/core/thing/ChannelUIDTest.java | 2 + .../org/openhab/core/thing/ThingUIDTest.java | 2 + .../java/org/openhab/core/thing/UIDTest.java | 2 + ...DynamicCommandDescriptionProviderTest.java | 20 +- ...seDynamicStateDescriptionProviderTest.java | 24 +- .../binding/builder/ChannelBuilderTest.java | 6 +- .../binding/builder/ThingBuilderTest.java | 4 +- .../builder/ThingStatusInfoBuilderTest.java | 4 +- .../core/thing/dto/ChannelDTOTest.java | 2 + .../openhab/core/thing/dto/ThingDTOTest.java | 2 + .../firmware/FirmwareEventFactoryTest.java | 4 +- .../thing/internal/AutoUpdateManagerTest.java | 37 +- .../core/thing/internal/ThingImplTest.java | 2 + .../firmware/ProgressCallbackTest.java | 42 +- .../RawButtonOnOffSwitchProfileTest.java | 19 +- .../RawButtonToggleSwitchProfileTest.java | 23 +- .../profiles/SystemDefaultProfileTest.java | 22 +- .../profiles/SystemFollowProfileTest.java | 24 +- .../SystemHysteresisStateProfileTest.java | 11 +- .../profiles/SystemRangeStateProfileTest.java | 43 +- .../type/ChannelGroupTypeBuilderTest.java | 4 +- .../thing/type/ChannelTypeBuilderTest.java | 20 +- .../thing/util/ThingHandlerHelperTest.java | 22 +- .../core/thing/util/ThingHelperTest.java | 2 + .../transform/actions/TransformationTest.java | 2 + .../AbstractResourceIconProviderTest.java | 14 +- .../ui/icon/internal/IconServletTest.java | 19 +- .../items/ItemUIRegistryImplTest.java | 386 +++++++++--------- .../proxy/ProxyServletServiceTest.java | 180 ++++---- .../VoiceConsoleCommandExtension.java | 10 +- .../main/java/org/openhab/core/OpenHAB.java | 2 + .../core/internal/items/ItemUpdater.java | 2 + .../library/unit/UnitInitializer.java | 2 + .../core/service/WatchQueueReader.java | 5 +- .../oauth2/AccessTokenResponseTest.java | 2 + .../QueueingThreadPoolExecutorTest.java | 5 +- .../core/common/ThreadFactoryBuilderTest.java | 4 +- .../core/common/ThreadPoolManagerTest.java | 2 + .../osgi/ResourceBundleClassLoaderTest.java | 2 + .../internal/auth/UserRegistryImplTest.java | 30 +- .../internal/i18n/I18nProviderImplTest.java | 18 +- .../internal/items/ExpireManagerTest.java | 56 +-- .../core/internal/items/ItemBuilderTest.java | 68 +-- .../core/internal/items/ItemTagTest.java | 2 + ...etadataCommandDescriptionProviderTest.java | 34 +- .../items/MetadataRegistryImplTest.java | 30 +- ...aStateDescriptionFragmentProviderTest.java | 32 +- .../scheduler/CronAdjusterMiscTest.java | 2 + .../internal/scheduler/CronAdjusterTest.java | 2 + .../scheduler/CronSchedulerImplTest.java | 8 +- .../scheduler/DelegatedSchedulerTest.java | 24 +- .../scheduler/PeriodicSchedulerImplTest.java | 2 + .../internal/scheduler/SchedulerImplTest.java | 9 +- .../service/ReadyServiceImplTest.java | 2 + .../StateDescriptionServiceImplTest.java | 26 +- .../StateDescriptionFragmentImplTest.java | 4 +- .../openhab/core/items/MetadataKeyTest.java | 2 + .../core/items/dto/ItemDTOMapperTest.java | 2 + .../core/library/CoreItemFactoryTest.java | 18 +- .../core/library/items/CallItemTest.java | 2 + .../core/library/items/ColorItemTest.java | 2 + .../core/library/items/ContactItemTest.java | 2 + .../core/library/items/DateTimeItemTest.java | 2 + .../core/library/items/DimmerItemTest.java | 2 + .../core/library/items/ImageItemTest.java | 2 + .../core/library/items/LocationItemTest.java | 2 + .../core/library/items/NumberItemTest.java | 13 +- .../core/library/items/PlayerItemTest.java | 2 + .../library/items/RollershutterItemTest.java | 2 + .../openhab/core/library/items/StateUtil.java | 2 + .../core/library/items/StringItemTest.java | 2 + .../core/library/items/SwitchItemTest.java | 2 + .../types/ArithmeticGroupFunctionTest.java | 59 +-- .../types/DateTimeGroupFunctionTest.java | 17 +- .../core/library/types/HSBTypeTest.java | 2 + .../core/library/types/OnOffTypeTest.java | 2 + .../library/types/OpenClosedTypeTest.java | 2 + .../core/library/types/PointTypeTest.java | 2 + .../core/library/types/QuantityTypeTest.java | 2 + .../library/types/StringListTypeTest.java | 2 + .../core/library/types/StringTypeTest.java | 2 + .../core/library/types/UpDownTypeTest.java | 2 + .../openhab/core/library/unit/UnitsTest.java | 5 +- .../openhab/core/net/HttpServiceUtilTest.java | 26 +- .../org/openhab/core/net/NetUtilTest.java | 2 + .../service/AbstractWatchServiceTest.java | 7 +- .../types/CommandDescriptionBuilderTest.java | 14 +- .../StateDescriptionFragmentBuilderTest.java | 4 +- .../org/openhab/core/util/HexUtilsTest.java | 2 + .../org/openhab/core/util/UIDUtilsTest.java | 2 + .../test/internal/cipher/CipherTest.java | 4 +- .../test/AutomationIntegrationJsonTest.java | 19 +- .../test/HostFragmentSupportTest.java | 10 +- .../defaultscope/ScriptRuleOSGiTest.java | 11 +- .../defaultscope/ScriptScopeOSGiTest.java | 4 +- .../internal/BasicConditionHandlerTest.java | 11 +- .../DayOfWeekConditionHandlerTest.java | 2 + .../timer/internal/RuntimeRuleTest.java | 12 +- .../TimeOfDayConditionHandlerTest.java | 5 +- .../internal/TimeOfDayTriggerHandlerTest.java | 7 +- .../automation/internal/RuleEngineTest.java | 6 +- .../automation/internal/RuleRegistryTest.java | 4 +- .../binding/xml/test/BindingInfoI18nTest.java | 6 +- .../binding/xml/test/BindingInfoTest.java | 8 +- .../binding/xml/test/BindingInstaller.java | 2 + .../itest.bndrun | 3 +- .../core/ConfigOptionRegistryOSGiTest.java | 27 +- .../DiscoveryServiceRegistryOSGiTest.java | 67 +-- .../internal/DeltaUsbSerialScannerTest.java | 23 +- .../internal/PollingUsbSerialScannerTest.java | 8 +- .../internal/SysFsUsbSerialScannerTest.java | 14 +- .../UsbSerialDeviceInformationGenerator.java | 2 + .../UsbSerialDiscoveryServiceTest.java | 6 +- .../UsbSerialDeviceInformationGenerator.java | 2 + .../internal/ConfigDispatcherOSGiTest.java | 192 +++++---- .../xml/test/ConfigDescriptionI18nTest.java | 11 +- .../xml/test/ConfigDescriptionsTest.java | 23 +- .../discovery/InboxResourceOSGITest.java | 14 +- .../internal/item/ItemResourceOSGiTest.java | 80 ++-- .../link/ItemChannelLinkResourceOSGiTest.java | 41 +- .../profile/ProfileTypeResourceTest.java | 25 +- .../ConfigurableServiceResourceOSGiTest.java | 4 +- ...hedItemDTOMapperWithTransformOSGiTest.java | 8 +- .../internal/folder/FolderObserverTest.java | 53 +-- .../internal/GenericItemProviderTest.java | 15 +- .../internal/GenericMetadataProviderTest.java | 2 + .../GenericItemChannelLinkProviderTest.java | 12 +- .../test/hue/GenericThingProviderTest.java | 6 +- .../test/hue/GenericThingProviderTest2.java | 6 +- .../test/hue/GenericThingProviderTest3.java | 8 +- .../test/hue/GenericThingProviderTest4.java | 21 +- .../internal/JsonStorageServiceOSGiTest.java | 15 +- .../core/cache/ExpiringCacheAsyncTest.java | 2 + .../events/OSGiEventManagerOSGiTest.java | 105 ++--- .../i18n/TranslationProviderOSGiTest.java | 111 +++-- .../openhab/core/items/GroupItemOSGiTest.java | 30 +- .../core/items/ItemRegistryImplTest.java | 24 +- .../items/ManagedItemProviderOSGiTest.java | 9 +- .../AbstractItemEventSubscriberOSGiTest.java | 29 +- .../core/thing/ThingPropertiesTest.java | 7 +- .../binding/BindingBaseClassesOSGiTest.java | 61 +-- .../binding/ChangeThingTypeOSGiTest.java | 24 +- .../core/thing/binding/ThingFactoryTest.java | 6 +- .../thing/binding/firmware/FirmwareTest.java | 5 +- ...eUpdateServiceFirmwareRestrictionTest.java | 45 +- ...eUpdateServicePrerequisiteVersionTest.java | 29 +- ...strictedFirmwareUpdateServiceOSGiTest.java | 17 +- ...usInfoI18nLocalizationServiceOSGiTest.java | 109 ++--- .../internal/SimpleThingTypeProvider.java | 7 +- .../thing/internal/ThingManagerOSGiTest.java | 161 +++++--- .../firmware/FirmwareRegistryOSGiTest.java | 119 +++--- .../firmware/FirmwareUpdateServiceTest.java | 201 +++++---- .../SystemProfileFactoryOSGiTest.java | 12 +- .../core/thing/link/LinkEventOSGiTest.java | 10 +- .../i18n/SystemProfileI18nOSGiTest.java | 4 +- .../testutil/i18n/DefaultLocaleSetter.java | 2 + .../thing/xml/test/ChannelTypesI18nTest.java | 8 +- .../core/thing/xml/test/ChannelTypesTest.java | 6 +- .../xml/test/ConfigDescriptionsTest.java | 4 +- .../core/thing/xml/test/LoadedTestBundle.java | 10 +- .../SystemChannelsInChannelGroupsTest.java | 8 +- .../xml/test/SystemWideChannelTypesTest.java | 8 +- .../thing/xml/test/ThingTypeI18nTest.java | 8 +- .../core/thing/xml/test/ThingTypesTest.java | 8 +- .../core/voice/internal/AudioSourceStub.java | 10 +- .../core/voice/internal/ConsoleStub.java | 7 +- .../core/voice/internal/KSServiceStub.java | 5 +- .../voice/internal/VoiceManagerImplTest.java | 25 +- .../InterpretCommandTest.java | 8 +- .../SayCommandTest.java | 14 +- .../VoiceConsoleCommandExtensionTest.java | 14 +- .../VoicesCommandTest.java | 11 +- 296 files changed, 2873 insertions(+), 2323 deletions(-) diff --git a/bundles/org.openhab.core.addon.sample/src/main/java/org/openhab/core/addon/sample/internal/SampleAddonService.java b/bundles/org.openhab.core.addon.sample/src/main/java/org/openhab/core/addon/sample/internal/SampleAddonService.java index 3c18fd21cb2..f085fac1507 100644 --- a/bundles/org.openhab.core.addon.sample/src/main/java/org/openhab/core/addon/sample/internal/SampleAddonService.java +++ b/bundles/org.openhab.core.addon.sample/src/main/java/org/openhab/core/addon/sample/internal/SampleAddonService.java @@ -21,6 +21,8 @@ import java.util.Map; import java.util.Random; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.addon.Addon; import org.openhab.core.addon.AddonEventFactory; import org.openhab.core.addon.AddonService; @@ -40,26 +42,23 @@ * @author Kai Kreuzer - Initial contribution */ @Component +@NonNullByDefault public class SampleAddonService implements AddonService { private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; private static final String[] COLOR_VALUES = new String[] { "80", "C8", "FF" }; - private EventPublisher eventPublisher; + private final EventPublisher eventPublisher; - List types = new ArrayList<>(3); - Map extensions = new HashMap<>(30); + private List types = new ArrayList<>(3); + private Map extensions = new HashMap<>(30); - @Reference - protected void setEventPublisher(EventPublisher eventPublisher) { + @Activate + public SampleAddonService(final @Reference EventPublisher eventPublisher) { this.eventPublisher = eventPublisher; } - protected void unsetEventPublisher(EventPublisher eventPublisher) { - this.eventPublisher = null; - } - @Activate protected void activate() { types.add(new AddonType("binding", "Bindings")); @@ -149,36 +148,32 @@ public void uninstall(String id) { } @Override - public List getAddons(Locale locale) { + public List getAddons(@Nullable Locale locale) { return new ArrayList<>(extensions.values()); } @Override - public Addon getAddon(String id, Locale locale) { + public @Nullable Addon getAddon(String id, @Nullable Locale locale) { return extensions.get(id); } @Override - public List getTypes(Locale locale) { + public List getTypes(@Nullable Locale locale) { return types; } @Override - public String getAddonId(URI extensionURI) { + public @Nullable String getAddonId(URI extensionURI) { return null; } private void postInstalledEvent(String extensionId) { - if (eventPublisher != null) { - Event event = AddonEventFactory.createAddonInstalledEvent(extensionId); - eventPublisher.post(event); - } + Event event = AddonEventFactory.createAddonInstalledEvent(extensionId); + eventPublisher.post(event); } private void postUninstalledEvent(String extensionId) { - if (eventPublisher != null) { - Event event = AddonEventFactory.createAddonUninstalledEvent(extensionId); - eventPublisher.post(event); - } + Event event = AddonEventFactory.createAddonUninstalledEvent(extensionId); + eventPublisher.post(event); } } diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java index ad4a54a2905..c8c6986bb8f 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -170,7 +171,8 @@ private void playOnSink(@Nullable String sinkId, String fileName, @Nullable Perc try { audioManager.playFile(fileName, sinkId, volume); } catch (AudioException e) { - console.println(e.getMessage()); + console.println(Objects.requireNonNullElse(e.getMessage(), + String.format("An error occurred while playing '%s' on sink '%s'", fileName, sinkId))); } } @@ -197,7 +199,8 @@ private void streamOnSink(@Nullable String sinkId, String url, Console console) try { audioManager.stream(url, sinkId); } catch (AudioException e) { - console.println(e.getMessage()); + console.println(Objects.requireNonNullElse(e.getMessage(), + String.format("An error occurred while streaming '%s' to sink '%s'", url, sinkId))); } } } diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/AudioWaveUtils.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/AudioWaveUtils.java index 6db5165e5cb..49298824206 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/AudioWaveUtils.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/AudioWaveUtils.java @@ -35,7 +35,7 @@ public class AudioWaveUtils { /** * This "magic" packet marks the beginning of the read data */ - private final static int DATA_MAGIC = 0x64617461; + private static final int DATA_MAGIC = 0x64617461; private static final AudioFormat DEFAULT_WAVE_AUDIO_FORMAT = new AudioFormat(AudioFormat.CONTAINER_WAVE, AudioFormat.CODEC_PCM_SIGNED, false, 16, 705600, 44100L, 1); diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AbstractAudioServletTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AbstractAudioServletTest.java index 368b874847c..803d58eedee 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AbstractAudioServletTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AbstractAudioServletTest.java @@ -16,6 +16,8 @@ import java.util.concurrent.CompletableFuture; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; @@ -45,22 +47,21 @@ */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) +@NonNullByDefault public abstract class AbstractAudioServletTest extends JavaTest { - protected AudioServlet audioServlet; - - private int port; - private TestServer server; - private static final String AUDIO_SERVLET_PROTOCOL = "http"; private static final String AUDIO_SERVLET_HOSTNAME = "localhost"; - private CompletableFuture serverStarted; + protected @NonNullByDefault({}) AudioServlet audioServlet; - private HttpClient httpClient; + private int port; + private @NonNullByDefault({}) TestServer server; + private @NonNullByDefault({}) HttpClient httpClient; + private @NonNullByDefault({}) CompletableFuture serverStarted; - private @Mock HttpService httpServiceMock; - private @Mock HttpContext httpContextMock; + private @Mock @NonNullByDefault({}) HttpService httpServiceMock; + private @Mock @NonNullByDefault({}) HttpContext httpContextMock; @BeforeEach public void setupServerAndClient() { @@ -115,7 +116,7 @@ protected Request getHttpRequest(String url) { return httpClient.newRequest(url).method(HttpMethod.GET); } - protected String serveStream(AudioStream stream, Integer timeInterval) throws Exception { + protected String serveStream(AudioStream stream, @Nullable Integer timeInterval) throws Exception { serverStarted.get(); // wait for the server thread to be started String path; diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioConsoleTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioConsoleTest.java index 5fea24c7971..ad00045e637 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioConsoleTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioConsoleTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,19 +42,16 @@ * @author Christoph Weitkamp - Added parameter to adjust the volume * @author Wouter Born - Migrate tests from Groovy to Java */ +@NonNullByDefault public class AudioConsoleTest extends AbstractAudioServletTest { - private BundledSoundFileHandler fileHandler; - - private AudioConsoleCommandExtension audioConsoleCommandExtension; - - private AudioManagerImpl audioManager; - - private AudioSinkFake audioSink; + private @NonNullByDefault({}) AudioConsoleCommandExtension audioConsoleCommandExtension; + private @NonNullByDefault({}) AudioManagerImpl audioManager; + private @NonNullByDefault({}) AudioSinkFake audioSink; + private @NonNullByDefault({}) String consoleOutput; + private @NonNullByDefault({}) BundledSoundFileHandler fileHandler; private final byte[] testByteArray = new byte[] { 0, 1, 2 }; - - private String consoleOutput; private final Console consoleMock = new Console() { @Override diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java index 91fa7514867..d83adb8a2f5 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java @@ -18,6 +18,7 @@ import java.util.HashSet; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioFormat; @@ -27,6 +28,7 @@ * @author Petar Valchev - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java */ +@NonNullByDefault public class AudioFormatTest { private final String testContainer = AudioFormat.CONTAINER_WAVE; private final String testCodec = AudioFormat.CODEC_PCM_SIGNED; diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerServletTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerServletTest.java index e8aa078c401..f7be947252b 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerServletTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerServletTest.java @@ -15,6 +15,8 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioFormat; @@ -31,11 +33,11 @@ * @author Wouter Born - Migrate tests from Groovy to Java * @author Henning Treu - extract servlet tests */ +@NonNullByDefault public class AudioManagerServletTest extends AbstractAudioServletTest { - private AudioManagerImpl audioManager; - - private AudioSinkFake audioSink; + private @NonNullByDefault({}) AudioManagerImpl audioManager; + private @NonNullByDefault({}) AudioSinkFake audioSink; @BeforeEach public void setup() { @@ -62,7 +64,7 @@ public void audioManagerDoesNotProcessStreamsIfThereIsNoRegisteredSink() throws assertServedStream(streamTimeout); } - private void assertServedStream(Integer timeInterval) throws Exception { + private void assertServedStream(@Nullable Integer timeInterval) throws Exception { AudioStream audioStream = getByteArrayAudioStream(AudioFormat.CONTAINER_WAVE, AudioFormat.CODEC_PCM_SIGNED); String url = serveStream(audioStream, timeInterval); diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java index 98f9c6e7316..d7441d83273 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioManagerTest.java @@ -25,8 +25,10 @@ import java.util.Collections; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.function.BiFunction; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,14 +52,13 @@ * @author Wouter Born - Migrate tests from Groovy to Java * @author Henning Treu - Convert to plain java tests */ +@NonNullByDefault public class AudioManagerTest { - private BundledSoundFileHandler fileHandler; - - private AudioManagerImpl audioManager; - - private AudioSinkFake audioSink; - private AudioSource audioSource; + private @NonNullByDefault({}) AudioManagerImpl audioManager; + private @NonNullByDefault({}) AudioSinkFake audioSink; + private @NonNullByDefault({}) AudioSource audioSource; + private @NonNullByDefault({}) BundledSoundFileHandler fileHandler; @BeforeEach public void setup() throws IOException { @@ -283,12 +284,12 @@ private void assertAddedParameterOption(String param, Locale locale) { case AudioManagerImpl.CONFIG_DEFAULT_SINK: audioManager.addAudioSink(audioSink); id = audioSink.getId(); - label = audioSink.getLabel(locale); + label = Objects.requireNonNull(audioSink.getLabel(locale)); break; case AudioManagerImpl.CONFIG_DEFAULT_SOURCE: audioManager.addAudioSource(audioSource); id = audioSource.getId(); - label = audioSource.getLabel(locale); + label = Objects.requireNonNull(audioSource.getLabel(locale)); break; default: fail("The parameter must be either default sink or default source"); diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioServletTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioServletTest.java index bc4c76cc79c..3a246d6f069 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioServletTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioServletTest.java @@ -18,6 +18,7 @@ import java.io.File; import java.util.concurrent.TimeUnit; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.http.HttpStatus; import org.junit.jupiter.api.Test; @@ -32,6 +33,7 @@ * @author Petar Valchev - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java */ +@NonNullByDefault public class AudioServletTest extends AbstractAudioServletTest { private static final String MEDIA_TYPE_AUDIO_WAV = "audio/wav"; diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/utils/BundledSoundFileHandler.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/utils/BundledSoundFileHandler.java index b3a6eb86dc7..ec1abfd7d46 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/utils/BundledSoundFileHandler.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/utils/BundledSoundFileHandler.java @@ -22,6 +22,7 @@ import java.nio.file.Path; import java.util.Comparator; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.OpenHAB; import org.openhab.core.audio.internal.AudioManagerTest; import org.slf4j.Logger; @@ -32,6 +33,7 @@ * * @author Markus Rathgeb - Initial contribution */ +@NonNullByDefault public class BundledSoundFileHandler implements Closeable { private static final String MP3_FILE_NAME = "mp3AudioFile.mp3"; private static final String WAV_FILE_NAME = "wavAudioFile.wav"; diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcher.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcher.java index a837f29e24d..7e7488d1155 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcher.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcher.java @@ -256,7 +256,6 @@ protected boolean createAndLoad(ScriptFileReference ref) { } else { logger.error("Script loading error, ignoring file: {}", fileName); } - } catch (IOException e) { logger.error("Failed to load file '{}': {}", ref.getScriptFileURL().getFile(), e.getMessage()); } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/AnnotatedActions.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/AnnotatedActions.java index 823d20e3bd8..30c3330f48d 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/AnnotatedActions.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/AnnotatedActions.java @@ -12,6 +12,8 @@ */ package org.openhab.core.automation; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * Marker interface for RuleActions * @@ -19,6 +21,7 @@ * * @author Stefan Triller - Initial contribution */ +@NonNullByDefault public interface AnnotatedActions { } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatus.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatus.java index 44f564b292f..e1e77dd55df 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatus.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatus.java @@ -12,6 +12,8 @@ */ package org.openhab.core.automation; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * This enumeration is used to present the main status of a {@link Rule}. * @@ -73,6 +75,7 @@ * @author Kai Kreuzer - Refactored to match ThingStatus implementation * @author Ana Dimova - add java doc */ +@NonNullByDefault public enum RuleStatus { UNINITIALIZED(1), INITIALIZING(2), diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatusDetail.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatusDetail.java index 101568304d5..0be7b325691 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatusDetail.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/RuleStatusDetail.java @@ -12,6 +12,8 @@ */ package org.openhab.core.automation; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * This enumeration is used to represent a detail of a {@link RuleStatus}. It can be considered as a sub-status. * It shows the specific reasons why the status of the rule is like as is. @@ -81,6 +83,7 @@ * @author Kai Kreuzer - Refactored to match ThingStatusDetail implementation * @author Ana Dimova - add java doc */ +@NonNullByDefault public enum RuleStatusDetail { NONE(0), HANDLER_MISSING_ERROR(1), diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/Visibility.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/Visibility.java index e9606461644..fc2a7ef48d1 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/Visibility.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/Visibility.java @@ -12,6 +12,7 @@ */ package org.openhab.core.automation; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.automation.template.Template; import org.openhab.core.automation.type.ModuleType; @@ -20,6 +21,7 @@ * * @author Yordan Mihaylov - Initial contribution */ +@NonNullByDefault public enum Visibility { /** * The UI has always to show an object with such visibility. diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/ConnectionValidatorTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/ConnectionValidatorTest.java index cdb553e63a4..26131c3bbe8 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/ConnectionValidatorTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/ConnectionValidatorTest.java @@ -16,11 +16,13 @@ import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; /** * @author Ana Dimova - Initial contribution */ +@NonNullByDefault public class ConnectionValidatorTest { @Test diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/RulePrefixTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/RulePrefixTest.java index 4b7f440cf06..dd430c9ce38 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/RulePrefixTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/RulePrefixTest.java @@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.*; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; import org.openhab.core.automation.RulePredicates; @@ -22,6 +23,7 @@ * * @author Victor Toni - Initial contribution */ +@NonNullByDefault public class RulePrefixTest { private static final String TESTING_PREFIX = "Testing"; diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java index 2f48834a43b..6d2acc768c2 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.when; import java.util.Collection; import java.util.HashMap; @@ -22,8 +22,12 @@ import java.util.Map; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.OpenHAB; import org.openhab.core.automation.AnnotatedActions; import org.openhab.core.automation.Visibility; @@ -46,6 +50,8 @@ * * @author Stefan Triller - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@NonNullByDefault public class AnnotationActionModuleTypeProviderTest extends JavaTest { private static final String TEST_ACTION_TYPE_ID = "binding.test.testMethod"; @@ -67,24 +73,20 @@ public class AnnotationActionModuleTypeProviderTest extends JavaTest { private static final String ACTION_OUTPUT2 = "output2"; private static final String ACTION_OUTPUT2_TYPE = "java.lang.String"; - private ModuleTypeI18nService moduleTypeI18nService; + private @Mock @NonNullByDefault({}) ModuleTypeI18nService moduleTypeI18nServiceMock; - private AnnotatedActions actionProviderConf1; - private AnnotatedActions actionProviderConf2; + private AnnotatedActions actionProviderConf1 = new TestActionProvider(); + private AnnotatedActions actionProviderConf2 = new TestActionProvider(); @BeforeEach public void setUp() { - actionProviderConf1 = new TestActionProvider(); - actionProviderConf2 = new TestActionProvider(); - - moduleTypeI18nService = mock(ModuleTypeI18nService.class); - when(moduleTypeI18nService.getModuleTypePerLocale(any(ModuleType.class), any(), any())) + when(moduleTypeI18nServiceMock.getModuleTypePerLocale(any(ModuleType.class), any(), any())) .thenAnswer(i -> i.getArguments()[0]); } @Test public void testMultiServiceAnnotationActions() { - AnnotatedActionModuleTypeProvider prov = new AnnotatedActionModuleTypeProvider(moduleTypeI18nService); + AnnotatedActionModuleTypeProvider prov = new AnnotatedActionModuleTypeProvider(moduleTypeI18nServiceMock); Map properties1 = new HashMap<>(); properties1.put(OpenHAB.SERVICE_CONTEXT, "conf1"); diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java index 1bac55a3f53..aa872e4c8df 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.when; import java.util.Collection; import java.util.HashMap; @@ -22,9 +22,13 @@ import java.util.Map; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.automation.Visibility; import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.ActionOutput; @@ -49,6 +53,8 @@ * * @author Christoph Weitkamp - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@NonNullByDefault public class AnnotatedThingActionModuleTypeProviderTest extends JavaTest { private static final ThingTypeUID TEST_THING_TYPE_UID = new ThingTypeUID("binding", "thing-type"); @@ -72,36 +78,33 @@ public class AnnotatedThingActionModuleTypeProviderTest extends JavaTest { private static final String ACTION_OUTPUT2 = "output2"; private static final String ACTION_OUTPUT2_TYPE = "java.lang.String"; - private ModuleTypeI18nService moduleTypeI18nService; + private @Mock @NonNullByDefault({}) ModuleTypeI18nService moduleTypeI18nServiceMock; + private @Mock @NonNullByDefault({}) ThingHandler handler1Mock; + private @Mock @NonNullByDefault({}) ThingHandler handler2Mock; - private ThingHandler mockHandler1; - private ThingHandler mockHandler2; - - private ThingActions actionProviderConf1; - private ThingActions actionProviderConf2; + private ThingActions actionProviderConf1 = new TestThingActionProvider(); + private ThingActions actionProviderConf2 = new TestThingActionProvider(); @BeforeEach public void setUp() { - mockHandler1 = mock(ThingHandler.class); - when(mockHandler1.getThing()).thenReturn(ThingBuilder.create(TEST_THING_TYPE_UID, "test1").build()); + when(handler1Mock.getThing()).thenReturn(ThingBuilder.create(TEST_THING_TYPE_UID, "test1").build()); actionProviderConf1 = new TestThingActionProvider(); - actionProviderConf1.setThingHandler(mockHandler1); + actionProviderConf1.setThingHandler(handler1Mock); - mockHandler2 = mock(ThingHandler.class); - when(mockHandler2.getThing()).thenReturn(ThingBuilder.create(TEST_THING_TYPE_UID, "test2").build()); + when(handler2Mock.getThing()).thenReturn(ThingBuilder.create(TEST_THING_TYPE_UID, "test2").build()); actionProviderConf2 = new TestThingActionProvider(); - actionProviderConf2.setThingHandler(mockHandler2); + actionProviderConf2.setThingHandler(handler2Mock); - moduleTypeI18nService = mock(ModuleTypeI18nService.class); - when(moduleTypeI18nService.getModuleTypePerLocale(any(ModuleType.class), any(), any())) + when(moduleTypeI18nServiceMock.getModuleTypePerLocale(any(ModuleType.class), any(), any())) .thenAnswer(i -> i.getArguments()[0]); } @Test public void testMultiServiceAnnotationActions() { - AnnotatedThingActionModuleTypeProvider prov = new AnnotatedThingActionModuleTypeProvider(moduleTypeI18nService); + AnnotatedThingActionModuleTypeProvider prov = new AnnotatedThingActionModuleTypeProvider( + moduleTypeI18nServiceMock); prov.addAnnotatedThingActions(actionProviderConf1); diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java index 17cde209f48..e6087a0c36b 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ReferenceResolverUtilTest.java @@ -19,6 +19,8 @@ import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.Test; import org.openhab.core.automation.Module; import org.openhab.core.config.core.Configuration; @@ -28,6 +30,7 @@ /** * @author Vasil Ilchev - Initial contribution */ +@NonNullByDefault public class ReferenceResolverUtilTest { private static final String CONTEXT_PROPERTY1 = "contextProperty1"; private static final String CONTEXT_PROPERTY2 = "contextProperty2"; @@ -36,9 +39,9 @@ public class ReferenceResolverUtilTest { private static final Map CONTEXT = new HashMap<>(); private static final Map MODULE_CONFIGURATION = new HashMap<>(); - private static final Map EXPECTED_MODULE_CONFIGURATION = new HashMap<>(); + private static final Map EXPECTED_MODULE_CONFIGURATION = new HashMap<>(); private static final Map COMPOSITE_CHILD_MODULE_INPUTS_REFERENCES = new HashMap<>(); - private static final Map EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT = new HashMap<>(); + private static final Map EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT = new HashMap<>(); private final Logger logger = LoggerFactory.getLogger(ReferenceResolverUtilTest.class); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java index 251d5812ed4..cda5deae058 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java @@ -19,6 +19,7 @@ import java.net.URI; import java.util.List; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -28,6 +29,7 @@ * * @author Christoph Weitkamp - Initial contribution */ +@NonNullByDefault public class ConfigDescriptionBuilderTest { private static final URI CONFIG_URI = URI.create("system:ephemeris"); @@ -39,7 +41,7 @@ public class ConfigDescriptionBuilderTest { .create("TEST GROUP 1").withLabel("Test Group 1").build(); private static final ConfigDescriptionParameterGroup GROUP2 = ConfigDescriptionParameterGroupBuilder .create("TEST GROUP 2").withAdvanced(Boolean.TRUE).withLabel("Test Group 2").build(); - private ConfigDescriptionBuilder builder; + private @NonNullByDefault({}) ConfigDescriptionBuilder builder; @BeforeEach public void setup() { diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java index 2f2a145ed2c..619c5cc5cfe 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterBuilderTest.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.util.List; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -27,6 +28,7 @@ * * @author Christoph Knauf - Initial contribution */ +@NonNullByDefault public class ConfigDescriptionParameterBuilderTest { @Test diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java index f2dadbfe925..7bbd9bf60fa 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigUtilTest.java @@ -22,11 +22,13 @@ import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution */ +@NonNullByDefault public class ConfigUtilTest { private final URI configUri = URI.create("system:ephemeris"); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProviderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProviderTest.java index d935aa47232..ba1aee710fd 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProviderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProviderTest.java @@ -18,6 +18,7 @@ import java.net.URI; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.hamcrest.collection.IsEmptyCollection; import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ParameterOption; @@ -27,6 +28,7 @@ * * @author Simon Kaufmann - Initial contribution */ +@NonNullByDefault public class I18nConfigOptionsProviderTest { private final I18nConfigOptionsProvider provider = new I18nConfigOptionsProvider(); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java index 7666ef0e352..a255892916d 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -43,6 +44,7 @@ */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) +@NonNullByDefault public class MetadataConfigDescriptionProviderImplTest extends JavaTest { private static final String LIBERAL = "liberal"; @@ -53,34 +55,34 @@ public class MetadataConfigDescriptionProviderImplTest extends JavaTest { private static final URI URI_RESTRICTED_DIMMER = URI.create(SCHEME + SEPARATOR + RESTRICTED + SEPARATOR + "dimmer"); - private @Mock MetadataConfigDescriptionProvider mockProviderRestricted; - private @Mock MetadataConfigDescriptionProvider mockProviderLiberal; + private @Mock @NonNullByDefault({}) MetadataConfigDescriptionProvider providerRestrictedMock; + private @Mock @NonNullByDefault({}) MetadataConfigDescriptionProvider providerLiberalMock; - private MetadataConfigDescriptionProviderImpl service; + private MetadataConfigDescriptionProviderImpl service = new MetadataConfigDescriptionProviderImpl(); @BeforeEach public void setup() { service = new MetadataConfigDescriptionProviderImpl(); - when(mockProviderRestricted.getNamespace()).thenReturn(RESTRICTED); - when(mockProviderRestricted.getDescription(any())).thenReturn("Restricted"); - when(mockProviderRestricted.getParameterOptions(any())).thenReturn(List.of( // + when(providerRestrictedMock.getNamespace()).thenReturn(RESTRICTED); + when(providerRestrictedMock.getDescription(any())).thenReturn("Restricted"); + when(providerRestrictedMock.getParameterOptions(any())).thenReturn(List.of( // new ParameterOption("dimmer", "Dimmer"), // new ParameterOption("switch", "Switch") // )); - when(mockProviderRestricted.getParameters(eq("dimmer"), any())).thenReturn(List.of( // + when(providerRestrictedMock.getParameters(eq("dimmer"), any())).thenReturn(List.of( // ConfigDescriptionParameterBuilder.create("width", Type.INTEGER).build(), // ConfigDescriptionParameterBuilder.create("height", Type.INTEGER).build() // )); - when(mockProviderLiberal.getNamespace()).thenReturn(LIBERAL); - when(mockProviderLiberal.getDescription(any())).thenReturn("Liberal"); - when(mockProviderLiberal.getParameterOptions(any())).thenReturn(null); + when(providerLiberalMock.getNamespace()).thenReturn(LIBERAL); + when(providerLiberalMock.getDescription(any())).thenReturn("Liberal"); + when(providerLiberalMock.getParameterOptions(any())).thenReturn(null); } @Test public void testGetConfigDescriptionsNoOptions() { - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); Collection res = service.getConfigDescriptions(Locale.ENGLISH); assertNotNull(res); @@ -98,7 +100,7 @@ public void testGetConfigDescriptionsNoOptions() { @Test public void testGetConfigDescriptionsWithOptions() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); Collection res = service.getConfigDescriptions(Locale.ENGLISH); assertNotNull(res); @@ -118,16 +120,16 @@ public void testGetConfigDescriptionsWithOptions() { @Test public void testGetConfigDescriptionWrongScheme() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); assertNull(service.getConfigDescription(URI.create("some:nonsense"), null)); } @Test public void testGetConfigDescriptionValueDescription() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); ConfigDescription desc = service.getConfigDescription(URI_LIBERAL, null); assertNotNull(desc); @@ -142,8 +144,8 @@ public void testGetConfigDescriptionValueDescription() { @Test public void testGetConfigDescriptionValueDescriptionNonExistingNamespace() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); ConfigDescription desc = service.getConfigDescription(URI.create("metadata:nonsense"), null); assertNull(desc); @@ -151,8 +153,8 @@ public void testGetConfigDescriptionValueDescriptionNonExistingNamespace() { @Test public void testGetConfigDescriptionPropertiesDescription() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); ConfigDescription desc = service.getConfigDescription(URI_RESTRICTED_DIMMER, null); assertNotNull(desc); @@ -168,8 +170,8 @@ public void testGetConfigDescriptionPropertiesDescription() { @Test public void testGetConfigDescriptionPropertiesDescriptionNonExistingNamespace() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); ConfigDescription desc = service.getConfigDescription(URI.create("metadata:nonsense:nonsense"), null); assertNull(desc); @@ -177,8 +179,8 @@ public void testGetConfigDescriptionPropertiesDescriptionNonExistingNamespace() @Test public void testGetConfigDescriptionPropertiesDescriptionNonExistingValue() { - service.addMetadataConfigDescriptionProvider(mockProviderRestricted); - service.addMetadataConfigDescriptionProvider(mockProviderLiberal); + service.addMetadataConfigDescriptionProvider(providerRestrictedMock); + service.addMetadataConfigDescriptionProvider(providerLiberalMock); ConfigDescription desc = service.getConfigDescription(URI.create("metadata:foo:nonsense"), null); assertNull(desc); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java index a8b5de00f41..b86bbdb60c8 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java @@ -21,6 +21,7 @@ import java.util.TreeSet; import java.util.stream.Stream; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameterBuilder; @@ -29,6 +30,7 @@ * @author Simon Kaufmann - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java */ +@NonNullByDefault public class NormalizerTest { @Test diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java index c0b9cc30c8c..ce3b360164f 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java @@ -22,6 +22,7 @@ import java.util.Locale; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -36,6 +37,7 @@ * @author Thomas Höfer - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java */ +@NonNullByDefault public class ConfigValidationExceptionTest { private static final String PARAM1 = "param1"; @@ -67,7 +69,7 @@ public class ConfigValidationExceptionTest { private static final TranslationProvider TRANSLATION_PROVIDER = new TranslationProvider() { @Override public @Nullable String getText(@Nullable Bundle bundle, @Nullable String key, @Nullable String defaultText, - @Nullable Locale locale, @Nullable Object... arguments) { + @Nullable Locale locale, @Nullable Object @Nullable... arguments) { return getText(bundle, key, defaultText, locale); } diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultFlag.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultFlag.java index 9923174d484..84b9fbe9daa 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultFlag.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/DiscoveryResultFlag.java @@ -12,6 +12,8 @@ */ package org.openhab.core.config.discovery; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link DiscoveryResultFlag} class specifies a list of flags * which a {@link DiscoveryResult} object can take. @@ -20,6 +22,7 @@ * * @see DiscoveryResult */ +@NonNullByDefault public enum DiscoveryResultFlag { /** diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java index 61c3d05e686..76d16847ee4 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java @@ -17,6 +17,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -80,7 +81,8 @@ public void execute(String[] args, Console console) { } inbox.approve(thingUID, label, newThingId); } catch (IllegalArgumentException e) { - console.println(e.getMessage()); + console.println(Objects.requireNonNullElse(e.getMessage(), + String.format("An error occurred while approving '%s'", args[1]))); } } else { console.println("Specify thing id to approve: inbox approve