From d3ea6063c009afc8d234edfc0f33e3bf6bc97015 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 9 Aug 2020 14:36:46 +0200 Subject: [PATCH] Migrate to JUnit 5 (#1580) * Migrates all tests to the JUnit 5 Jupiter API * Updates bnd to 5.1.2 * Updates maven-surefire-plugin to 3.0.0-M5 * Updates Mockito to 3.4.6 * Updates Hamcrest to 2.2 * Removes org.openhab.core.boot POM dependencies Signed-off-by: Wouter Born --- bom/test-index/pom.xml | 16 +- bom/test/pom.xml | 24 ++- .../internal/AbstractAudioServletTest.java | 19 +- .../core/audio/internal/AudioConsoleTest.java | 12 +- .../core/audio/internal/AudioFormatTest.java | 4 +- .../internal/AudioManagerServletTest.java | 8 +- .../core/audio/internal/AudioManagerTest.java | 13 +- .../core/audio/internal/AudioServletTest.java | 4 +- .../internal/ConnectionValidatorTest.java | 143 +++++++------ .../automation/internal/RulePrefixTest.java | 29 +-- .../EphemerisModuleHandlerFactoryTest.java | 15 +- ...nnotationActionModuleTypeProviderTest.java | 8 +- ...atedThingActionModuleTypeProviderTest.java | 8 +- .../util/ReferenceResolverUtilTest.java | 68 +++--- .../core/ConfigDescriptionBuilderTest.java | 8 +- ...ConfigDescriptionParameterBuilderTest.java | 45 ++-- ...gDescriptionParameterGroupBuilderTest.java | 8 +- .../core/ConfigDescriptionRegistryTest.java | 17 +- .../core/config/core/ConfigUtilTest.java | 4 +- .../core/config/core/ConfigurationTest.java | 6 +- .../i18n/I18nConfigOptionsProviderTest.java | 8 +- ...dataConfigDescriptionProviderImplTest.java | 16 +- .../normalization/NormalizerTest.java | 4 +- .../ConfigDescriptionValidatorTest.java | 18 +- .../ConfigValidationExceptionTest.java | 10 +- .../core/status/ConfigStatusInfoTest.java | 13 +- .../core/status/ConfigStatusServiceTest.java | 8 +- .../discovery/inbox/InboxPredicatesTest.java | 8 +- .../inbox/events/InboxEventFactoryTest.java | 4 +- .../internal/AutomaticInboxProcessorTest.java | 60 +++--- .../internal/DiscoveryResultImplTest.java | 16 +- .../internal/PersistentInboxTest.java | 44 ++-- .../ConfigDispatcherFileWatcherTest.java | 15 +- .../org/openhab/core/id/InstanceUUIDTest.java | 4 +- .../core/io/bin2json/Bin2JsonTest.java | 23 ++- .../HttpContextFactoryServiceImplTest.java | 20 +- .../core/io/net/exec/ExecUtilTest.java | 4 +- .../core/io/net/http/BaseHttpUtilTest.java | 28 ++- .../io/net/http/HttpRequestBuilderTest.java | 4 +- .../core/io/net/http/HttpUtilTest.java | 23 +-- .../ExtensibleTrustManagerImplTest.java | 49 ++--- .../internal/WebClientFactoryImplTest.java | 42 ++-- ...nrichedConfigDescriptionDTOMapperTest.java | 4 +- .../channel/ChannelTypeResourceTest.java | 20 +- .../item/MetadataSelectorMatcherTest.java | 26 +-- .../core/item/EnrichedItemDTOMapperTest.java | 8 +- .../thing/EnrichedThingDTOMapperTest.java | 36 ++-- .../sitemap/internal/SitemapResourceTest.java | 17 +- .../rest/sse/internal/util/SseUtilTest.java | 4 +- .../core/io/rest/JSONResponseTest.java | 5 +- .../io/rest/Stream2JSONInputStreamTest.java | 9 +- .../rest/internal/filter/CorsFilterTest.java | 19 +- .../rest/internal/filter/ProxyFilterTest.java | 16 +- .../mqtt/MqttBrokerConnectionTests.java | 25 +-- .../mqtt/internal/MqttServiceTests.java | 5 +- .../upnp/internal/UpnpIOServiceTest.java | 18 +- bundles/org.openhab.core.karaf/pom.xml | 3 +- .../core/karaf/internal/FeatureInstaller.java | 3 +- .../internal/MappingUriExtensionsTest.java | 67 +++--- .../internal/actions/TimerImplTest.java | 8 +- ...nericThingProviderMultipleBundlesTest.java | 16 +- .../core/semantics/SemanticTagsTest.java | 8 +- .../internal/SemanticsServiceImplTest.java | 16 +- .../json/internal/JsonStorageTest.java | 8 +- .../handler/MagicColorLightHandlerTest.java | 22 +- .../MagicDimmableLightHandlerTest.java | 22 +- .../handler/MagicOnOffLightHandlerTest.java | 22 +- .../internal/MagicHandlerFactoryTest.java | 8 +- .../internal/MagicServiceImplTest.java | 9 +- .../core/test/SyntheticBundleInstaller.java | 5 +- .../openhab/core/test/java/JavaOSGiTest.java | 14 +- .../openhab/core/test/java/JavaTestTest.java | 14 +- .../core/thing/xml/internal/Example.java | 2 +- .../thing/xml/internal/XmlHelperTest.java | 4 +- .../core/thing/ChannelGroupUIDTest.java | 12 +- .../org/openhab/core/thing/ChannelTest.java | 2 +- .../openhab/core/thing/ChannelUIDTest.java | 17 +- .../org/openhab/core/thing/ThingUIDTest.java | 4 +- .../java/org/openhab/core/thing/UIDTest.java | 8 +- .../binding/builder/ChannelBuilderTest.java | 8 +- .../binding/builder/ThingBuilderTest.java | 38 ++-- .../builder/ThingStatusInfoBuilderTest.java | 8 +- .../core/thing/dto/ChannelDTOTest.java | 4 +- .../openhab/core/thing/dto/ThingDTOTest.java | 4 +- .../firmware/FirmwareEventFactoryTest.java | 28 +-- .../thing/internal/AutoUpdateManagerTest.java | 16 +- .../internal/ChannelItemProviderTest.java | 15 +- .../core/thing/internal/ThingImplTest.java | 4 +- .../thing/internal/ThingManagerImplTest.java | 17 +- .../firmware/ProgressCallbackTest.java | 69 ++++--- .../RawButtonOnOffSwitchProfileTest.java | 9 +- .../RawButtonToggleSwitchProfileTest.java | 9 +- .../profiles/SystemDefaultProfileTest.java | 17 +- .../profiles/SystemFollowProfileTest.java | 17 +- .../profiles/SystemOffsetProfileTest.java | 9 +- .../profiles/TimestampProfileTest.java | 4 +- .../type/ChannelGroupTypeBuilderTest.java | 13 +- .../thing/type/ChannelTypeBuilderTest.java | 21 +- .../core/thing/type/ThingTypeBuilderTest.java | 26 +-- .../thing/util/ThingHandlerHelperTest.java | 16 +- .../core/thing/util/ThingHelperTest.java | 12 +- .../transform/actions/TransformationTest.java | 4 +- .../AbstractResourceIconProviderTest.java | 15 +- .../ui/icon/internal/IconServletTest.java | 16 +- .../items/ItemUIRegistryImplTest.java | 21 +- .../proxy/ProxyServletServiceTest.java | 8 +- .../openhab/core/voice/STTExceptionTest.java | 13 +- .../SpeechRecognitionErrorEventTest.java | 9 +- .../voice/SpeechRecognitionEventTest.java | 13 +- .../openhab/core/voice/TTSExceptionTest.java | 13 +- .../oauth2/AccessTokenResponseTest.java | 12 +- .../core/cache/ExpiringCacheMapTest.java | 16 +- .../openhab/core/cache/ExpiringCacheTest.java | 8 +- .../QueueingThreadPoolExecutorTest.java | 36 ++-- .../core/common/ThreadFactoryBuilderTest.java | 18 +- .../core/common/ThreadPoolManagerTest.java | 5 +- .../osgi/ResourceBundleClassLoaderTest.java | 4 +- .../internal/i18n/I18nProviderImplTest.java | 23 +-- .../core/internal/items/ItemBuilderTest.java | 27 +-- .../items/ItemStateConverterImplTest.java | 9 +- .../core/internal/items/ItemTagTest.java | 4 +- ...etadataCommandDescriptionProviderTest.java | 19 +- .../items/MetadataRegistryImplTest.java | 19 +- ...aStateDescriptionFragmentProviderTest.java | 19 +- .../scheduler/CronAdjusterMiscTest.java | 57 ++--- .../internal/scheduler/CronAdjusterTest.java | 30 +-- .../scheduler/CronSchedulerImplTest.java | 23 ++- .../scheduler/DelegatedSchedulerTest.java | 35 ++-- .../scheduler/PeriodicSchedulerImplTest.java | 12 +- .../internal/scheduler/SchedulerImplTest.java | 160 ++++++++------ .../service/ReadyServiceImplTest.java | 6 +- .../StateDescriptionServiceImplTest.java | 8 +- .../StateDescriptionFragmentImplTest.java | 11 +- .../openhab/core/items/GenericItemTest.java | 18 +- .../openhab/core/items/MetadataKeyTest.java | 4 +- .../core/items/dto/ItemDTOMapperTest.java | 7 +- .../events/AbstractEventFactoryTest.java | 4 +- .../items/events/ItemEventFactoryTest.java | 7 +- .../core/library/CoreItemFactoryTest.java | 8 +- .../dimension/VolumetricFlowRateTest.java | 50 ++--- .../core/library/items/CallItemTest.java | 4 +- .../core/library/items/ColorItemTest.java | 4 +- .../core/library/items/ContactItemTest.java | 4 +- .../core/library/items/DateTimeItemTest.java | 4 +- .../core/library/items/DimmerItemTest.java | 4 +- .../core/library/items/ImageItemTest.java | 4 +- .../core/library/items/LocationItemTest.java | 4 +- .../core/library/items/NumberItemTest.java | 21 +- .../core/library/items/PlayerItemTest.java | 4 +- .../library/items/RollershutterItemTest.java | 4 +- .../openhab/core/library/items/StateUtil.java | 2 +- .../core/library/items/StringItemTest.java | 4 +- .../core/library/items/SwitchItemTest.java | 4 +- .../types/ArithmeticGroupFunctionTest.java | 9 +- .../types/DateTimeGroupFunctionTest.java | 8 +- .../core/library/types/DateTimeTypeTest.java | 64 +++--- .../core/library/types/DecimalTypeTest.java | 4 +- .../core/library/types/HSBTypeTest.java | 29 +-- .../core/library/types/OnOffTypeTest.java | 5 +- .../library/types/OpenClosedTypeTest.java | 5 +- .../core/library/types/PercentTypeTest.java | 12 +- .../core/library/types/PointTypeTest.java | 25 +-- ...antityTypeArithmeticGroupFunctionTest.java | 21 +- .../core/library/types/QuantityTypeTest.java | 15 +- .../library/types/StringListTypeTest.java | 4 +- .../core/library/types/StringTypeTest.java | 4 +- .../core/library/types/UpDownTypeTest.java | 5 +- .../core/library/unit/SmartHomeUnitsTest.java | 5 +- .../openhab/core/net/HttpServiceUtilTest.java | 20 +- .../org/openhab/core/net/NetUtilTest.java | 4 +- .../types/CommandDescriptionBuilderTest.java | 8 +- .../StateDescriptionFragmentBuilderTest.java | 8 +- .../core/types/util/UnitUtilsTest.java | 15 +- .../org/openhab/core/util/HexUtilsTest.java | 4 +- .../org/openhab/core/util/UIDUtilsTest.java | 7 +- itests/itest-include.bndrun | 8 +- .../itest.bndrun | 18 +- .../test/internal/cipher/CipherTest.java | 16 +- .../itest.bndrun | 62 +++++- .../test/AutomationIntegrationJsonTest.java | 13 +- .../test/AutomationIntegrationTest.java | 13 +- .../test/HostFragmentSupportTest.java | 13 +- .../itest.bndrun | 62 +++++- .../internal/module/RunRuleModuleTest.java | 19 +- .../internal/module/RuntimeRuleTest.java | 52 +++-- .../itest.bndrun | 61 +++++- .../module/script/ScriptRuleOSGiTest.java | 8 +- .../defaultscope/ScriptScopeOSGiTest.java | 12 +- .../itest.bndrun | 62 +++++- .../internal/BasicConditionHandlerTest.java | 8 +- .../DayOfWeekConditionHandlerTest.java | 4 +- .../timer/internal/RuntimeRuleTest.java | 8 +- .../TimeOfDayConditionHandlerTest.java | 4 +- .../internal/TimeOfDayTriggerHandlerTest.java | 8 +- .../itest.bndrun | 62 +++++- .../core/automation/event/RuleEventTest.java | 9 +- .../automation/internal/RuleEngineTest.java | 144 +++++++------ .../automation/internal/RuleRegistryTest.java | 195 +++++++++--------- .../itest.bndrun | 12 +- .../binding/xml/test/BindingInfoI18nTest.java | 8 +- .../binding/xml/test/BindingInfoTest.java | 8 +- .../binding/xml/test/BindingInstaller.java | 2 +- .../itest.bndrun | 18 +- .../core/ConfigOptionRegistryOSGiTest.java | 8 +- .../itest.bndrun | 12 +- .../MDNSDiscoveryServiceOSGiTest.java | 8 +- .../itest.bndrun | 18 +- .../DiscoveryServiceRegistryOSGiTest.java | 29 +-- .../inbox/DynamicThingUpdateOSGiTest.java | 8 +- .../discovery/internal/InboxOSGiTest.java | 17 +- .../itest.bndrun | 18 +- .../internal/DeltaUsbSerialScannerTest.java | 8 +- .../internal/PollingUsbSerialScannerTest.java | 21 +- .../internal/SysFsUsbSerialScannerTest.java | 26 +-- .../itest.bndrun | 18 +- .../UsbSerialDiscoveryServiceTest.java | 8 +- .../itest.bndrun | 67 +++++- .../internal/ConfigDispatcherOSGiTest.java | 34 ++- .../itest.bndrun | 12 +- .../config/xml/test/BindingInstaller.java | 2 +- .../xml/test/ConfigDescriptionI18nTest.java | 9 +- .../xml/test/ConfigDescriptionsTest.java | 8 +- .../itest.bndrun | 12 +- .../EphemerisManagerImplOSGiTest.java | 22 +- .../itest.bndrun | 58 +++++- .../discovery/InboxResourceOSGITest.java | 22 +- .../internal/item/ItemResourceOSGiTest.java | 25 ++- .../persistence/PersistenceResourceTest.java | 22 +- .../profile/ProfileTypeResourceTest.java | 22 +- .../ConfigurableServiceResourceOSGiTest.java | 8 +- ...hedItemDTOMapperWithTransformOSGiTest.java | 25 ++- .../itest.bndrun | 17 +- .../internal/folder/FolderObserverTest.java | 39 ++-- .../itest.bndrun | 11 +- .../internal/GenericItemProviderTest.java | 12 +- .../internal/GenericMetadataProviderTest.java | 4 +- .../itest.bndrun | 11 +- .../extensions/PersistenceExtensionsTest.java | 12 +- .../itest.bndrun | 14 +- .../rule/runtime/DSLRuleProviderTest.java | 13 +- .../itest.bndrun | 13 +- .../script/engine/ScriptEngineOSGiTest.java | 70 ++++--- .../script/lib/NumberExtensionsTest.java | 5 +- .../tests/lib/NumberExtensionsTest.java | 148 +++++++------ .../itest.bndrun | 19 +- ...enericItemChannelLinkProviderJavaTest.java | 27 ++- .../GenericItemChannelLinkProviderTest.java | 12 +- .../test/hue/GenericThingProviderTest.java | 15 +- .../test/hue/GenericThingProviderTest2.java | 12 +- .../test/hue/GenericThingProviderTest3.java | 12 +- .../test/hue/GenericThingProviderTest4.java | 72 ++++--- .../itest.bndrun | 12 +- .../internal/JsonStorageServiceOSGiTest.java | 17 +- itests/org.openhab.core.tests/itest.bndrun | 18 +- .../core/cache/ExpiringCacheAsyncTest.java | 8 +- .../internal/common/SafeCallerImplTest.java | 54 ++--- .../events/OSGiEventManagerOSGiTest.java | 24 ++- .../i18n/TranslationProviderOSGiTest.java | 8 +- .../internal/items/ItemUpdaterOSGiTest.java | 8 +- .../openhab/core/items/GroupItemOSGiTest.java | 31 ++- .../core/items/ItemRegistryImplTest.java | 28 ++- .../items/ManagedItemProviderOSGiTest.java | 17 +- .../AbstractItemEventSubscriberOSGiTest.java | 25 ++- .../service/AbstractWatchServiceTest.java | 16 +- .../org.openhab.core.thing.tests/itest.bndrun | 18 +- .../thing/SystemWideChannelTypesTest.java | 8 +- .../core/thing/ThingPropertiesTest.java | 16 +- .../binding/BindingBaseClassesOSGiTest.java | 32 +-- .../binding/ChangeThingTypeOSGiTest.java | 8 +- .../core/thing/binding/ThingFactoryTest.java | 4 +- .../thing/binding/firmware/FirmwareTest.java | 26 +-- .../thing/events/ThingEventFactoryTest.java | 5 +- .../factory/ManagedThingProviderOSGiTest.java | 17 +- ...eUpdateServiceFirmwareRestrictionTest.java | 12 +- ...eUpdateServicePrerequisiteVersionTest.java | 8 +- ...strictedFirmwareUpdateServiceOSGiTest.java | 8 +- ...usInfoI18nLocalizationServiceOSGiTest.java | 18 +- ...nelCommandDescriptionProviderOSGiTest.java | 34 ++- ...annelStateDescriptionProviderOSGiTest.java | 35 +++- .../CommunicationManagerOSGiTest.java | 26 ++- .../internal/ThingManagerOSGiJavaTest.java | 29 +-- .../thing/internal/ThingManagerOSGiTest.java | 22 +- .../thing/internal/ThingRegistryOSGiTest.java | 19 +- .../firmware/FirmwareRegistryOSGiTest.java | 12 +- .../firmware/FirmwareUpdateServiceTest.java | 147 +++++++------ .../SystemProfileFactoryOSGiTest.java | 32 +-- .../thing/link/ItemChannelLinkOSGiTest.java | 12 +- .../core/thing/link/LinkEventOSGiTest.java | 8 +- .../i18n/SystemProfileI18nOSGiTest.java | 8 +- .../testutil/i18n/DefaultLocaleSetter.java | 2 +- .../itest.bndrun | 12 +- .../thing/xml/test/ChannelTypesI18nTest.java | 12 +- .../core/thing/xml/test/ChannelTypesTest.java | 8 +- .../xml/test/ConfigDescriptionsTest.java | 8 +- .../core/thing/xml/test/LoadedTestBundle.java | 2 +- .../SystemChannelsInChannelGroupsTest.java | 8 +- .../xml/test/SystemWideChannelTypesTest.java | 9 +- .../thing/xml/test/ThingTypeI18nTest.java | 9 +- .../core/thing/xml/test/ThingTypesTest.java | 8 +- .../org.openhab.core.voice.tests/itest.bndrun | 52 ++++- .../voice/internal/VoiceManagerImplTest.java | 24 +-- .../InterpretCommandTest.java | 8 +- .../SayCommandTest.java | 42 ++-- .../VoiceConsoleCommandExtensionTest.java | 6 +- .../VoicesCommandTest.java | 8 +- pom.xml | 4 +- 306 files changed, 3308 insertions(+), 2607 deletions(-) diff --git a/bom/test-index/pom.xml b/bom/test-index/pom.xml index 68ad47be6..c57b3de7c 100644 --- a/bom/test-index/pom.xml +++ b/bom/test-index/pom.xml @@ -16,9 +16,19 @@ - org.osgi - osgi.enroute.junit.wrapper - 4.12.0 + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + + + org.junit.platform + junit-platform-launcher + 1.6.2 + + + biz.aQute.bnd + biz.aQute.tester.junit-platform + 5.1.2 org.openhab.core.bom diff --git a/bom/test/pom.xml b/bom/test/pom.xml index b897b36fa..44a27c3f1 100644 --- a/bom/test/pom.xml +++ b/bom/test/pom.xml @@ -17,19 +17,29 @@ - junit - junit - 4.12 + org.hamcrest + hamcrest-library + 2.2 - org.osgi - osgi.enroute.hamcrest.wrapper - 1.3.0 + org.junit.jupiter + junit-jupiter-api + 5.6.2 + + + org.junit.jupiter + junit-jupiter-params + 5.6.2 org.mockito mockito-core - 3.1.0 + 3.4.6 + + + org.mockito + mockito-junit-jupiter + 3.4.6 org.slf4j 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 ec920053b..10e822058 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 @@ -12,8 +12,7 @@ */ package org.openhab.core.audio.internal; -import static org.junit.Assert.fail; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.junit.jupiter.api.Assertions.fail; import java.util.concurrent.CompletableFuture; @@ -22,9 +21,13 @@ import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; import org.openhab.core.audio.ByteArrayAudioStream; @@ -40,6 +43,8 @@ import org.osgi.service.http.HttpService; * * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public abstract class AbstractAudioServletTest extends JavaTest { protected AudioServlet audioServlet; @@ -57,10 +62,8 @@ public abstract class AbstractAudioServletTest extends JavaTest { private @Mock HttpService httpServiceMock; private @Mock HttpContext httpContextMock; - @Before + @BeforeEach public void setupServerAndClient() { - initMocks(this); - audioServlet = new AudioServlet(httpServiceMock, httpContextMock); ServletHolder servletHolder = new ServletHolder(audioServlet); @@ -72,7 +75,7 @@ public abstract class AbstractAudioServletTest extends JavaTest { httpClient = new HttpClient(); } - @After + @AfterEach public void tearDownServerAndClient() throws Exception { server.stopServer(); httpClient.stop(); 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 92d64a05d..ebf8da28f 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 @@ -13,16 +13,16 @@ package org.openhab.core.audio.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; import java.io.File; import java.io.IOException; import java.util.Locale; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioException; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioSource; @@ -73,7 +73,7 @@ public class AudioConsoleTest extends AbstractAudioServletTest { private final int testTimeout = 1; - @Before + @BeforeEach public void setUp() throws IOException { fileHandler = new BundledSoundFileHandler(); audioSink = new AudioSinkFake(); @@ -87,7 +87,7 @@ public class AudioConsoleTest extends AbstractAudioServletTest { audioConsoleCommandExtension = new AudioConsoleCommandExtension(audioManager, localeProvider); } - @After + @AfterEach public void tearDown() { fileHandler.close(); } 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 defa10776..b7a7996f1 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 @@ -13,12 +13,12 @@ package org.openhab.core.audio.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioFormat; /** 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 a9c2a401e..2aff8f3e2 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 @@ -13,10 +13,10 @@ package org.openhab.core.audio.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; import org.openhab.core.audio.ByteArrayAudioStream; @@ -37,7 +37,7 @@ public class AudioManagerServletTest extends AbstractAudioServletTest { private AudioSinkFake audioSink; - @Before + @BeforeEach public void setup() { audioManager = new AudioManagerImpl(); audioSink = new AudioSinkFake(); 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 89f872998..e7b12b7c8 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 @@ -13,7 +13,8 @@ package org.openhab.core.audio.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -25,9 +26,9 @@ import java.util.Collections; import java.util.Locale; import java.util.function.BiFunction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioException; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioSource; @@ -57,7 +58,7 @@ public class AudioManagerTest { private AudioSinkFake audioSink; private AudioSource audioSource; - @Before + @BeforeEach public void setup() throws IOException { fileHandler = new BundledSoundFileHandler(); audioManager = new AudioManagerImpl(); @@ -68,7 +69,7 @@ public class AudioManagerTest { when(audioSource.getLabel(any(Locale.class))).thenReturn("audioSourceLabel"); } - @After + @AfterEach public void tearDown() throws IOException { fileHandler.close(); } 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 0d7905f6e..55d1b36ea 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 @@ -12,8 +12,8 @@ */ package org.openhab.core.audio.internal; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; import java.io.File; import java.util.concurrent.TimeUnit; @@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioStream; import org.openhab.core.audio.FileAudioStream; 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 fa5ab18a7..cb7c6eaf7 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 @@ -12,10 +12,11 @@ */ package org.openhab.core.automation.internal; +import static org.junit.jupiter.api.Assertions.*; + import java.util.regex.Pattern; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Ana Dimova - Initial contribution @@ -24,91 +25,89 @@ public class ConnectionValidatorTest { @Test public void testValidConnections() { - Assert.assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "${name}")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "moduleId.outputName")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list[1].name.values")); - Assert.assertTrue( - Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module1.map[\"na[m}.\"e\"][1].values_1-2")); + assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name")); + assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "${name}")); + assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "moduleId.outputName")); + assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list[1].name.values")); + assertTrue(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module1.map[\"na[m}.\"e\"][1].values_1-2")); } @Test public void testInvalidConnections() { - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "{name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "${name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "${name.values}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "moduleId.outputName.")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "[1].name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "list.[1]name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, ".module.array[1].name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module1.map\"na[m}.\"e\"]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.map[\"na[m}.\"e\"")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list[1.name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list1].name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list[1].name.")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module[\"name\"]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.[name]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module[\"name]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.[name\"]")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "name")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "{name")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "${name")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "${name.values}")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "$name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "moduleId.outputName.")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "[1].name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "list.[1]name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, ".module.array[1].name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module1.map\"na[m}.\"e\"]")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.map[\"na[m}.\"e\"")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list[1.name")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list1].name")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.list[1].name.")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module[\"name\"]")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.[name]")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module[\"name]")); + assertFalse(Pattern.matches(ConnectionValidator.CONNECTION_PATTERN, "module.[name\"]")); } @Test public void testInvalidConfigReference() { - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "{name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "${name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "${name.values}")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "[1].name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "${name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name.values}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "name")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "{name")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "${name")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "${name.values}")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "[1].name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "${name.values")); + assertFalse(Pattern.matches(ConnectionValidator.CONFIG_REFERENCE_PATTERN, "$name.values}")); } @Test public void testValidOutputReference() { - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "[1]")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".phones[1]")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".phones[1].number")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "[\"test\"]")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "[\"test\"].name")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".map[\"test\"]")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".map[\"test\"].name")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.values")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.array[1]")); - Assert.assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.map[\"na[m}.\"e\"]")); - Assert.assertTrue( - Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.map[\"na[m}.\"e\"].values")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "[1]")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".phones[1]")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".phones[1].number")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "[\"test\"]")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "[\"test\"].name")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".map[\"test\"]")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".map[\"test\"].name")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.values")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.array[1]")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.map[\"na[m}.\"e\"]")); + assertTrue(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".bean.map[\"na[m}.\"e\"].values")); } @Test public void testInvalidOutputReference() { - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones.")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones[")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "]phones")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones[].name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones[\"\"].name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "list.[1]name.values")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".map\"na[m}.\"e\"]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.map[\"na[m}.\"e\"")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.list[1.name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.list1].name")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.list[1].name.")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module[\"name\"]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.[name]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module[\"name]")); - Assert.assertTrue(!Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.[name\"]")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones.")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones[")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "]phones")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones[].name")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "phones[\"\"].name")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "list.[1]name.values")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, ".map\"na[m}.\"e\"]")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.map[\"na[m}.\"e\"")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.list[1.name")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.list1].name")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.list[1].name.")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module[\"name\"]")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.[name]")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module[\"name]")); + assertFalse(Pattern.matches(ConnectionValidator.OUTPUT_REFERENCE_PATTERN, "module.[name\"]")); } } 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 1a531435d..ac86ad030 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 @@ -12,8 +12,9 @@ */ package org.openhab.core.automation.internal; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; import org.openhab.core.automation.RulePredicates; /** @@ -34,18 +35,18 @@ public class RulePrefixTest { @Test public void testEmptyPrefix() { final RuleImpl rule0 = new RuleImpl(null); - Assert.assertNotNull("Returned UID is null instead of generated one", rule0.getUID()); - Assert.assertNull("Returned a prefix instead of null", RulePredicates.getPrefix(rule0)); + assertNotNull(rule0.getUID(), "Returned UID is null instead of generated one"); + assertNull(RulePredicates.getPrefix(rule0), "Returned a prefix instead of null"); final String somethingWithoutSeparator = "something_without_separator"; final RuleImpl rule1 = new RuleImpl(somethingWithoutSeparator); - Assert.assertEquals("Returned wrong UID", somethingWithoutSeparator, rule1.getUID()); - Assert.assertNull("Returned a prefix instead of null", RulePredicates.getPrefix(rule1)); + assertEquals(somethingWithoutSeparator, rule1.getUID(), "Returned wrong UID"); + assertNull(RulePredicates.getPrefix(rule1), "Returned a prefix instead of null"); final String withSeparatorButEmpty = RulePredicates.PREFIX_SEPARATOR + "with_separator_but_empty"; final RuleImpl rule2 = new RuleImpl(withSeparatorButEmpty); - Assert.assertEquals("Returned wrong UID", withSeparatorButEmpty, rule2.getUID()); - Assert.assertNull("Returned a prefix instead of null", RulePredicates.getPrefix(rule2)); + assertEquals(withSeparatorButEmpty, rule2.getUID(), "Returned wrong UID"); + assertNull(RulePredicates.getPrefix(rule2), "Returned a prefix instead of null"); } /** @@ -60,18 +61,18 @@ public class RulePrefixTest { final String someName = "someName"; final RuleImpl rule0 = new RuleImpl(testingPrefixPrefix + someName); - Assert.assertEquals("Returned wrong prefix", TESTING_PREFIX, RulePredicates.getPrefix(rule0)); - Assert.assertEquals("Returned wrong UID", testingPrefixPrefix + someName, rule0.getUID()); + assertEquals(TESTING_PREFIX, RulePredicates.getPrefix(rule0), "Returned wrong prefix"); + assertEquals(testingPrefixPrefix + someName, rule0.getUID(), "Returned wrong UID"); final String multipleSeparatorName = RulePredicates.PREFIX_SEPARATOR + "nameBetweenSeparator" + RulePredicates.PREFIX_SEPARATOR; final RuleImpl rule1 = new RuleImpl(testingPrefixPrefix + multipleSeparatorName); - Assert.assertEquals("Returned wrong prefix", TESTING_PREFIX, RulePredicates.getPrefix(rule1)); - Assert.assertEquals("Returned wrong UID", testingPrefixPrefix + someName, rule0.getUID()); + assertEquals(TESTING_PREFIX, RulePredicates.getPrefix(rule1), "Returned wrong prefix"); + assertEquals(testingPrefixPrefix + someName, rule0.getUID(), "Returned wrong UID"); final String emptyName = ""; final RuleImpl rule2 = new RuleImpl(testingPrefixPrefix + emptyName); - Assert.assertEquals("Returned wrong prefix", TESTING_PREFIX, RulePredicates.getPrefix(rule2)); - Assert.assertEquals("Returned wrong UID", testingPrefixPrefix + emptyName, rule2.getUID()); + assertEquals(TESTING_PREFIX, RulePredicates.getPrefix(rule2), "Returned wrong prefix"); + assertEquals(testingPrefixPrefix + emptyName, rule2.getUID(), "Returned wrong UID"); } } diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java index 263f480a3..35d8839e6 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/factory/EphemerisModuleHandlerFactoryTest.java @@ -13,14 +13,15 @@ package org.openhab.core.automation.internal.module.factory; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; import java.util.Collections; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Condition; import org.openhab.core.automation.Module; import org.openhab.core.automation.handler.ModuleHandler; @@ -39,7 +40,7 @@ public class EphemerisModuleHandlerFactoryTest { private @NonNullByDefault({}) EphemerisModuleHandlerFactory factory; private @NonNullByDefault({}) Module moduleMock; - @Before + @BeforeEach public void setUp() { factory = new EphemerisModuleHandlerFactory(mock(EphemerisManager.class)); @@ -47,14 +48,12 @@ public class EphemerisModuleHandlerFactoryTest { when(moduleMock.getId()).thenReturn("My id"); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFactoryFailsCreatingModuleHandlerForDaysetCondition() { when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID); when(moduleMock.getConfiguration()).thenReturn(new Configuration()); - ModuleHandler handler = factory.internalCreate(moduleMock, "My first rule"); - assertThat(handler, is(notNullValue())); - assertThat(handler, instanceOf(EphemerisConditionHandler.class)); + assertThrows(IllegalArgumentException.class, () -> factory.internalCreate(moduleMock, "My first rule")); } @Test 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 fa944c12a..ef447d852 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 @@ -12,7 +12,7 @@ */ package org.openhab.core.automation.internal.module.provider; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -22,8 +22,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.OpenHAB; import org.openhab.core.automation.AnnotatedActions; import org.openhab.core.automation.Visibility; @@ -72,7 +72,7 @@ public class AnnotationActionModuleTypeProviderTest extends JavaTest { private AnnotatedActions actionProviderConf1; private AnnotatedActions actionProviderConf2; - @Before + @BeforeEach public void setUp() { actionProviderConf1 = new TestActionProvider(); actionProviderConf2 = new TestActionProvider(); 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 edb0e33b4..d25b9286a 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 @@ -12,7 +12,7 @@ */ package org.openhab.core.automation.thingsupport; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -23,8 +23,8 @@ import java.util.Map; import java.util.Set; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Visibility; import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.ActionOutput; @@ -80,7 +80,7 @@ public class AnnotatedThingActionModuleTypeProviderTest extends JavaTest { private ThingActions actionProviderConf1; private ThingActions actionProviderConf2; - @Before + @BeforeEach public void setUp() { mockHandler1 = mock(ThingHandler.class); when(mockHandler1.getThing()).thenReturn(ThingBuilder.create(TEST_THING_TYPE_UID, "test1").build()); 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 f5a1e1f67..fc4787aec 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 @@ -12,14 +12,15 @@ */ package org.openhab.core.automation.util; +import static org.junit.jupiter.api.Assertions.*; + import java.math.BigDecimal; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Module; import org.openhab.core.config.core.Configuration; import org.slf4j.Logger; @@ -95,17 +96,17 @@ public class ReferenceResolverUtilTest { Module trigger = ModuleBuilder.createTrigger().withId("id1").withTypeUID("typeUID1") .withConfiguration(new Configuration(MODULE_CONFIGURATION)).build(); ReferenceResolver.updateConfiguration(trigger.getConfiguration(), CONTEXT, logger); - Assert.assertEquals(trigger.getConfiguration(), new Configuration(EXPECTED_MODULE_CONFIGURATION)); + assertEquals(trigger.getConfiguration(), new Configuration(EXPECTED_MODULE_CONFIGURATION)); // test condition configuration. Module condition = ModuleBuilder.createCondition().withId("id2").withTypeUID("typeUID2") .withConfiguration(new Configuration(MODULE_CONFIGURATION)).build(); ReferenceResolver.updateConfiguration(condition.getConfiguration(), CONTEXT, logger); - Assert.assertEquals(condition.getConfiguration(), new Configuration(EXPECTED_MODULE_CONFIGURATION)); + assertEquals(condition.getConfiguration(), new Configuration(EXPECTED_MODULE_CONFIGURATION)); // test action configuration. Module action = ModuleBuilder.createAction().withId("id3").withTypeUID("typeUID3") .withConfiguration(new Configuration(MODULE_CONFIGURATION)).build(); ReferenceResolver.updateConfiguration(action.getConfiguration(), CONTEXT, logger); - Assert.assertEquals(action.getConfiguration(), new Configuration(EXPECTED_MODULE_CONFIGURATION)); + assertEquals(action.getConfiguration(), new Configuration(EXPECTED_MODULE_CONFIGURATION)); } @Test @@ -114,39 +115,39 @@ public class ReferenceResolverUtilTest { Module condition = ModuleBuilder.createCondition().withId("id1").withTypeUID("typeUID1") .withInputs(COMPOSITE_CHILD_MODULE_INPUTS_REFERENCES).build(); Map conditionContext = ReferenceResolver.getCompositeChildContext(condition, CONTEXT); - Assert.assertEquals(conditionContext, EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT); + assertEquals(conditionContext, EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT); // test Composite child ModuleImpl(action) context Module action = ModuleBuilder.createAction().withId("id2").withTypeUID("typeUID2") .withInputs(COMPOSITE_CHILD_MODULE_INPUTS_REFERENCES).build(); - Assert.assertEquals(EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT, conditionContext); + assertEquals(EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT, conditionContext); Map actionContext = ReferenceResolver.getCompositeChildContext(action, CONTEXT); - Assert.assertEquals(actionContext, EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT); + assertEquals(actionContext, EXPECTED_COMPOSITE_CHILD_MODULE_CONTEXT); } @Test public void testSplitReferenceToTokens() { - Assert.assertNull(ReferenceResolver.splitReferenceToTokens(null)); - Assert.assertTrue(ReferenceResolver.splitReferenceToTokens("").length == 0); + assertNull(ReferenceResolver.splitReferenceToTokens(null)); + assertTrue(ReferenceResolver.splitReferenceToTokens("").length == 0); final String[] referenceTokens = ReferenceResolver .splitReferenceToTokens(".module.array[\".na[m}.\"e\"][1].values1"); - Assert.assertTrue("module".equals(referenceTokens[0])); - Assert.assertTrue("array".equals(referenceTokens[1])); - Assert.assertTrue(".na[m}.\"e".equals(referenceTokens[2])); - Assert.assertTrue("1".equals(referenceTokens[3])); - Assert.assertTrue("values1".equals(referenceTokens[4])); + assertTrue("module".equals(referenceTokens[0])); + assertTrue("array".equals(referenceTokens[1])); + assertTrue(".na[m}.\"e".equals(referenceTokens[2])); + assertTrue("1".equals(referenceTokens[3])); + assertTrue("values1".equals(referenceTokens[4])); } @Test public void testResolvingFromNull() { String ken = "Ken"; - Assert.assertEquals(ken, + assertEquals(ken, ReferenceResolver.resolveComplexDataReference(ken, ReferenceResolver.splitReferenceToTokens(null))); } @Test public void testResolvingFromEmptyString() { String ken = "Ken"; - Assert.assertEquals(ken, + assertEquals(ken, ReferenceResolver.resolveComplexDataReference(ken, ReferenceResolver.splitReferenceToTokens(""))); } @@ -154,14 +155,15 @@ public class ReferenceResolverUtilTest { public void testGetFromList() { String ken = "Ken"; List names = Arrays.asList("John", ken, "Sue"); - Assert.assertEquals(ken, + assertEquals(ken, ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[1]"))); } - @Test(expected = NumberFormatException.class) + @Test public void testGetFromListInvalidIndexFormat() { List names = Arrays.asList("John", "Ken", "Sue"); - ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[Ten]")); + assertThrows(NumberFormatException.class, () -> ReferenceResolver.resolveComplexDataReference(names, + ReferenceResolver.splitReferenceToTokens("[Ten]"))); } @Test @@ -171,7 +173,7 @@ public class ReferenceResolverUtilTest { phones.put("John", phone); phones.put("Sue", "0222 2184 121"); phones.put("Mark", "0222 5641 121"); - Assert.assertEquals(phone, ReferenceResolver.resolveComplexDataReference(phones, + assertEquals(phone, ReferenceResolver.resolveComplexDataReference(phones, ReferenceResolver.splitReferenceToTokens("[\"John\"]"))); } @@ -182,7 +184,7 @@ public class ReferenceResolverUtilTest { phones.put("John[].Smi\"th].", phone); phones.put("Sue", "0222 2184 121"); phones.put("Mark", "0222 5641 121"); - Assert.assertEquals(phone, ReferenceResolver.resolveComplexDataReference(phones, + assertEquals(phone, ReferenceResolver.resolveComplexDataReference(phones, ReferenceResolver.splitReferenceToTokens("[\"John[].Smi\"th].\"]"))); } @@ -191,7 +193,7 @@ public class ReferenceResolverUtilTest { Map phones = new HashMap<>(); phones.put("Sue", "0222 2184 121"); phones.put("Mark", "0222 5641 121"); - Assert.assertNull(ReferenceResolver.resolveComplexDataReference(phones, + assertNull(ReferenceResolver.resolveComplexDataReference(phones, ReferenceResolver.splitReferenceToTokens("[\"John\"]"))); } @@ -199,27 +201,29 @@ public class ReferenceResolverUtilTest { public void getFromList() { String ken = "Ken"; List names = Arrays.asList(new String[] { "John", ken, "Sue" }); - Assert.assertEquals(ken, + assertEquals(ken, ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[1]"))); } - @Test(expected = ArrayIndexOutOfBoundsException.class) + @Test public void testGetFromListInvalidIndex() { List names = Arrays.asList(new String[] { "John", "Ken", "Sue" }); - ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[10]")); + assertThrows(ArrayIndexOutOfBoundsException.class, () -> ReferenceResolver.resolveComplexDataReference(names, + ReferenceResolver.splitReferenceToTokens("[10]"))); } - @Test(expected = NumberFormatException.class) + @Test public void testGetFromInvalidIndexFormat() { List names = Arrays.asList(new String[] { "John", "Ken", "Sue" }); - ReferenceResolver.resolveComplexDataReference(names, ReferenceResolver.splitReferenceToTokens("[Ten]")); + assertThrows(NumberFormatException.class, () -> ReferenceResolver.resolveComplexDataReference(names, + ReferenceResolver.splitReferenceToTokens("[Ten]"))); } @Test public void testGetFromBean() { String name = "John"; B1 b3 = new B1<>(name); - Assert.assertEquals(name, + assertEquals(name, ReferenceResolver.resolveComplexDataReference(b3, ReferenceResolver.splitReferenceToTokens("value"))); } @@ -227,7 +231,7 @@ public class ReferenceResolverUtilTest { public void testGetFromBeanWithPrivateField() { String name = "John"; B2 b4 = new B2<>(name); - Assert.assertEquals(name, + assertEquals(name, ReferenceResolver.resolveComplexDataReference(b4, ReferenceResolver.splitReferenceToTokens("value"))); } @@ -238,7 +242,7 @@ public class ReferenceResolverUtilTest { phones.put("John", phone); B1> b3 = new B1<>(phones); B2>> b4 = new B2<>(b3); - Assert.assertEquals(phone, ReferenceResolver.resolveComplexDataReference(b4, + assertEquals(phone, ReferenceResolver.resolveComplexDataReference(b4, ReferenceResolver.splitReferenceToTokens("value.value[\"John\"]"))); } @@ -249,7 +253,7 @@ public class ReferenceResolverUtilTest { B1 b32 = new B1<>("Sue"); B1 b33 = new B1<>(name); List> b = Arrays.asList(b31, b32, b33); - Assert.assertEquals(name, ReferenceResolver.resolveComplexDataReference(b, + assertEquals(name, ReferenceResolver.resolveComplexDataReference(b, ReferenceResolver.splitReferenceToTokens("[2].value"))); } 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 b27834a31..91450d49e 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 @@ -13,15 +13,15 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import java.net.URI; import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; /** @@ -42,7 +42,7 @@ public class ConfigDescriptionBuilderTest { .create("TEST GROUP 2").withAdvanced(Boolean.TRUE).withLabel("Test Group 2").build(); private ConfigDescriptionBuilder builder; - @Before + @BeforeEach public void setup() { builder = ConfigDescriptionBuilder.create(CONFIG_URI); } 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 e03bbc164..a78f53728 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 @@ -13,12 +13,13 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; /** @@ -163,43 +164,51 @@ public class ConfigDescriptionParameterBuilderTest { assertTrue(param2.getOptions().isEmpty()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatNameMustNotBeNull() { - ConfigDescriptionParameterBuilder.create(null, Type.BOOLEAN).build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create(null, Type.BOOLEAN).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatNameMustNotBeEmpty() { - ConfigDescriptionParameterBuilder.create("", Type.BOOLEAN).build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("", Type.BOOLEAN).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatTypeMustNotBeNull() { - ConfigDescriptionParameterBuilder.create("Dummy", null).build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("Dummy", null).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUnitForTextParameterIsNotAllowed() { - ConfigDescriptionParameterBuilder.create("Dummy", Type.TEXT).withUnit("m").build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("Dummy", Type.TEXT).withUnit("m").build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUnitForBooleanParameterIsNotAllowed() { - ConfigDescriptionParameterBuilder.create("Dummy", Type.BOOLEAN).withUnit("m").build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("Dummy", Type.BOOLEAN).withUnit("m").build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUnitLabelForTextParameterIsNotAllowed() { - ConfigDescriptionParameterBuilder.create("Dummy", Type.TEXT).withUnitLabel("Runs").build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("Dummy", Type.TEXT).withUnitLabel("Runs").build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUnitLabelForBooleanParameterIsNotAllowed() { - ConfigDescriptionParameterBuilder.create("Dummy", Type.BOOLEAN).withUnitLabel("Runs").build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("Dummy", Type.BOOLEAN).withUnitLabel("Runs").build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatAparameterWithAnInvalidUnitCannotBeCreated() { - ConfigDescriptionParameterBuilder.create("Dummy", Type.BOOLEAN).withUnit("invalid").build(); + assertThrows(IllegalArgumentException.class, + () -> ConfigDescriptionParameterBuilder.create("Dummy", Type.BOOLEAN).withUnit("invalid").build()); } } diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilderTest.java index a9cf66920..a9f2d89aa 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilderTest.java @@ -13,11 +13,11 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for {@link ConfigDescriptionParameterGroupBuilder) class. @@ -29,7 +29,7 @@ public class ConfigDescriptionParameterGroupBuilderTest { private @NonNullByDefault({}) ConfigDescriptionParameterGroupBuilder builder; - @Before + @BeforeEach public void setup() { builder = ConfigDescriptionParameterGroupBuilder.create("test") // .withContext("My Context") // diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java index db27d1f28..b60433dc7 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java @@ -13,20 +13,23 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.test.java.JavaTest; /** @@ -34,6 +37,8 @@ import org.openhab.core.test.java.JavaTest; * * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class ConfigDescriptionRegistryTest extends JavaTest { private URI uriDummy; @@ -52,10 +57,8 @@ public class ConfigDescriptionRegistryTest extends JavaTest { private @Mock ConfigOptionProvider configOptionsProviderMockAliased; private @Mock ConfigOptionProvider configOptionsProviderMock; - @Before + @BeforeEach public void setUp() throws Exception { - initMocks(this); - uriDummy = new URI("config:Dummy"); uriDummy1 = new URI("config:Dummy1"); uriAliases = new URI("config:Aliased"); 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 e70859e1f..ede0062e8 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 @@ -13,7 +13,7 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.openhab.core.config.core.ConfigDescriptionParameter.Type.*; import java.math.BigDecimal; @@ -23,7 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java index 690844d00..57b877edd 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java @@ -13,8 +13,8 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.core.IsCollectionContaining.hasItems; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsIterableContaining.hasItems; import java.math.BigDecimal; import java.util.ArrayList; @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for Configuration class. 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 52b4131fc..e100fb28a 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 @@ -13,14 +13,14 @@ package org.openhab.core.config.core.internal.i18n; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.net.URI; import java.util.Locale; import org.hamcrest.collection.IsEmptyCollection; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ParameterOption; /** @@ -38,7 +38,7 @@ public class I18nConfigOptionsProviderTest { private final ParameterOption expectedCntryFRJava9 = new ParameterOption("US", "États-Unis"); private URI uriI18N; - @Before + @BeforeEach public void setup() throws Exception { provider = new I18nConfigOptionsProvider(); uriI18N = new URI("system:i18n"); 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 8500dead5..22407ddf1 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 @@ -12,10 +12,9 @@ */ package org.openhab.core.config.core.internal.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import static org.openhab.core.config.core.internal.metadata.MetadataConfigDescriptionProviderImpl.*; import java.net.URI; @@ -23,9 +22,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -38,6 +41,8 @@ import org.openhab.core.test.java.JavaTest; * * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class MetadataConfigDescriptionProviderImplTest extends JavaTest { private static final String LIBERAL = "liberal"; @@ -53,9 +58,8 @@ public class MetadataConfigDescriptionProviderImplTest extends JavaTest { private MetadataConfigDescriptionProviderImpl service; - @Before + @BeforeEach public void setup() { - initMocks(this); service = new MetadataConfigDescriptionProviderImpl(); when(mockProviderRestricted.getNamespace()).thenReturn(RESTRICTED); 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 0a0f3f473..ae0827012 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 @@ -14,14 +14,14 @@ package org.openhab.core.config.core.internal.normalization; import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.math.BigDecimal; import java.util.List; import java.util.TreeSet; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameterBuilder; diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java index c001704e6..a7105663d 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java @@ -14,7 +14,8 @@ package org.openhab.core.config.core.internal.validation; import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -28,8 +29,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.openhab.core.config.core.ConfigDescription; @@ -147,7 +148,7 @@ public class ConfigDescriptionValidatorTest { private Map params; private ConfigDescriptionValidatorImpl configDescriptionValidator; - @Before + @BeforeEach public void setUp() { ConfigDescriptionRegistry configDescriptionRegistry = mock(ConfigDescriptionRegistry.class); when(configDescriptionRegistry.getConfigDescription(any())).thenAnswer(new Answer() { @@ -481,14 +482,15 @@ public class ConfigDescriptionValidatorTest { configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI); } - @Test(expected = NullPointerException.class) + @Test public void assertValidateThrowsNPEforNullParamerters() { - configDescriptionValidator.validate(null, CONFIG_DESCRIPTION_URI); + assertThrows(NullPointerException.class, + () -> configDescriptionValidator.validate(null, CONFIG_DESCRIPTION_URI)); } - @Test(expected = NullPointerException.class) + @Test public void assertValidateThrowsNPEforNullConfigDescriptionUri() { - configDescriptionValidator.validate(params, null); + assertThrows(NullPointerException.class, () -> configDescriptionValidator.validate(params, null)); } @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 acfd30c66..dac516452 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 @@ -15,7 +15,8 @@ package org.openhab.core.config.core.internal.validation; import static java.util.Collections.*; import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.text.MessageFormat; import java.util.Collection; @@ -25,7 +26,7 @@ import java.util.Map; import java.util.stream.Stream; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.openhab.core.config.core.validation.ConfigValidationException; import org.openhab.core.config.core.validation.ConfigValidationMessage; @@ -140,10 +141,11 @@ public class ConfigValidationExceptionTest { assertThat(messages.get(PARAM2), is(TXT_DEFAULT2)); } - @Test(expected = NullPointerException.class) + @Test @SuppressWarnings("unused") public void assertThatNPEisThrownForNullConfigValidationMessages() { - new ConfigValidationException(BUNDLE, TRANSLATION_PROVIDER, null); + assertThrows(NullPointerException.class, + () -> new ConfigValidationException(BUNDLE, TRANSLATION_PROVIDER, null)); } static ConfigValidationMessage createMessage(String parameterName, String defaultMessage, String messageKey, diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java index d87f619ce..8e3e664fa 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusInfoTest.java @@ -15,12 +15,13 @@ package org.openhab.core.config.core.status; import static java.util.Collections.*; import static java.util.stream.Collectors.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.status.ConfigStatusMessage.Type; /** @@ -88,16 +89,16 @@ public class ConfigStatusInfoTest { assertConfigStatusInfo(info); } - @Test(expected = NullPointerException.class) + @Test public void assertNPEisThrownIfTypesAreNull() { ConfigStatusInfo info = new ConfigStatusInfo(); - info.getConfigStatusMessages(null, emptySet()); + assertThrows(NullPointerException.class, () -> info.getConfigStatusMessages(null, emptySet())); } - @Test(expected = NullPointerException.class) + @Test public void assertNPEisThrownIfParameterNamesAreNull() { ConfigStatusInfo info = new ConfigStatusInfo(); - info.getConfigStatusMessages(emptySet(), null); + assertThrows(NullPointerException.class, () -> info.getConfigStatusMessages(emptySet(), null)); } private void assertConfigStatusInfo(ConfigStatusInfo info) { diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java index d9733cce8..5c14f5bb1 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java @@ -13,7 +13,7 @@ package org.openhab.core.config.core.status; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.status.ConfigStatusMessage.Type; import org.openhab.core.events.EventPublisher; import org.openhab.core.i18n.LocaleProvider; @@ -80,7 +80,7 @@ public class ConfigStatusServiceTest extends JavaTest { private final Collection messagesEntity1En = new ArrayList<>(); private final Collection messagesEntity2En = new ArrayList<>(); - @Before + @BeforeEach public void setUp() { messagesEntity1.add(PARAM1_MSG1); messagesEntity1.add(PARAM2_MSG2); diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java index 1ed70a719..ebbb330ab 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java @@ -13,7 +13,7 @@ package org.openhab.core.config.discovery.inbox; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.openhab.core.config.discovery.inbox.InboxPredicates.*; import java.util.AbstractMap.SimpleEntry; @@ -25,8 +25,8 @@ import java.util.Map.Entry; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.config.discovery.DiscoveryResultFlag; @@ -76,7 +76,7 @@ public class InboxPredicatesTest { DiscoveryResultBuilder.create(THING_UID22).withThingType(THING_TYPE_UID21).withProperties(PROPS2) .withLabel("label").build()); - @Before + @BeforeEach public void setUp() throws Exception { ((DiscoveryResultImpl) RESULTS.get(3)).setFlag(DiscoveryResultFlag.IGNORED); } diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java index 5caf16ed5..4e774a8aa 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java @@ -13,9 +13,9 @@ package org.openhab.core.config.discovery.inbox.events; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.config.discovery.dto.DiscoveryResultDTOMapper; diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java index 5f660ed1e..b57687971 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java @@ -13,11 +13,10 @@ package org.openhab.core.config.discovery.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import static org.openhab.core.config.discovery.inbox.InboxPredicates.withFlag; import java.util.Collections; @@ -27,11 +26,15 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.config.core.ConfigDescriptionRegistry; import org.openhab.core.config.core.Configuration; import org.openhab.core.config.discovery.DiscoveryResult; @@ -58,6 +61,8 @@ import org.openhab.core.thing.type.ThingTypeRegistry; * @author Andre Fuechsel - Initial contribution * @author Henning Sudbrock - Added tests for auto-approving inbox entries */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class AutomaticInboxProcessorTest { private static final String DEVICE_ID = "deviceId"; @@ -90,37 +95,18 @@ public class AutomaticInboxProcessorTest { private AutomaticInboxProcessor automaticInboxProcessor; private PersistentInbox inbox; - @Mock - private ThingRegistry thingRegistry; + private @Mock ThingRegistry thingRegistry; + private @Mock ThingTypeRegistry thingTypeRegistry; + private @Mock Thing thing; + private @Mock Thing thing2; + private @Mock Thing thing3; + private @Mock ThingStatusInfoChangedEvent thingStatusInfoChangedEvent; + private @Mock ConfigDescriptionRegistry configDescriptionRegistry; + private @Mock ThingHandlerFactory thingHandlerFactory; + private @Mock ManagedThingProvider thingProvider; - @Mock - private ThingTypeRegistry thingTypeRegistry; - - @Mock - private Thing thing; - - @Mock - private Thing thing2; - - @Mock - private Thing thing3; - - @Mock - private ThingStatusInfoChangedEvent thingStatusInfoChangedEvent; - - @Mock - private ConfigDescriptionRegistry configDescriptionRegistry; - - @Mock - private ThingHandlerFactory thingHandlerFactory; - - @Mock - private ManagedThingProvider thingProvider; - - @Before + @BeforeEach public void setUp() { - initMocks(this); - when(thing.getConfiguration()).thenReturn(CONFIG); when(thing.getThingTypeUID()).thenReturn(THING_TYPE_UID); when(thing.getProperties()).thenReturn(THING_PROPERTIES); @@ -163,7 +149,7 @@ public class AutomaticInboxProcessorTest { automaticInboxProcessor.activate(null); } - @After + @AfterEach public void tearDown() { automaticInboxProcessor.deactivate(); } @@ -447,7 +433,7 @@ public class AutomaticInboxProcessorTest { } @Test - @Ignore("Should this test pass? It will fail currently, as RuntimeExceptions are not explicitly caught in AutomaticInboxProcessor#isToBeAutoApproved") + @Disabled("Should this test pass? It will fail currently, as RuntimeExceptions are not explicitly caught in AutomaticInboxProcessor#isToBeAutoApproved") public void testRogueInboxAutoApprovePredicatesDoNoHarm() { automaticInboxProcessor.addInboxAutoApprovePredicate(discoveryResult -> { throw new RuntimeException("I am an evil inboxAutoApprovePredicate"); diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/DiscoveryResultImplTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/DiscoveryResultImplTest.java index 7d8c4c9b2..fadc1ac33 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/DiscoveryResultImplTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/DiscoveryResultImplTest.java @@ -12,12 +12,12 @@ */ package org.openhab.core.config.discovery.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultFlag; import org.openhab.core.thing.ThingTypeUID; @@ -36,16 +36,18 @@ public class DiscoveryResultImplTest { private static final int DEFAULT_TTL = 60; @SuppressWarnings("unused") - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidConstructorForThingType() { - new DiscoveryResultImpl(null, new ThingUID("aa"), null, null, null, null, DEFAULT_TTL); + assertThrows(IllegalArgumentException.class, + () -> new DiscoveryResultImpl(null, new ThingUID("aa"), null, null, null, null, DEFAULT_TTL)); } @SuppressWarnings("unused") - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidConstructorForTTL() { ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId", "thingType"); - new DiscoveryResultImpl(thingTypeUID, new ThingUID(thingTypeUID, "thingId"), null, null, null, null, -2); + assertThrows(IllegalArgumentException.class, () -> new DiscoveryResultImpl(thingTypeUID, + new ThingUID(thingTypeUID, "thingId"), null, null, null, null, -2)); } @Test @@ -61,7 +63,7 @@ public class DiscoveryResultImplTest { assertEquals("", discoveryResult.getLabel()); assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag()); - assertNotNull("The properties must never be null!", discoveryResult.getProperties()); + assertNotNull(discoveryResult.getProperties(), "The properties must never be null!"); assertNull(discoveryResult.getRepresentationProperty()); } diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/PersistentInboxTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/PersistentInboxTest.java index 5af25020a..c1f05ad4e 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/PersistentInboxTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/PersistentInboxTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.config.discovery.internal; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsMapContaining.hasEntry; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.math.BigDecimal; import java.net.URI; @@ -25,10 +25,14 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionBuilder; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -57,38 +61,26 @@ import org.openhab.core.thing.type.ThingTypeRegistry; /** * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class PersistentInboxTest { private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID("test", "test"); private static final ThingUID THING_UID = new ThingUID(THING_TYPE_UID, "test"); private PersistentInbox inbox; - - @Mock - private ThingRegistry thingRegistry; private Thing lastAddedThing = null; - @Mock - private StorageService storageService; + private @Mock ThingRegistry thingRegistry; + private @Mock StorageService storageService; + private @Mock Storage storage; + private @Mock ManagedThingProvider thingProvider; + private @Mock ThingTypeRegistry thingTypeRegistry; + private @Mock ConfigDescriptionRegistry configDescriptionRegistry; + private @Mock ThingHandlerFactory thingHandlerFactory; - @Mock - private Storage storage; - - @Mock - private ManagedThingProvider thingProvider; - - @Mock - private ThingTypeRegistry thingTypeRegistry; - - @Mock - private ConfigDescriptionRegistry configDescriptionRegistry; - - @Mock - private ThingHandlerFactory thingHandlerFactory; - - @Before + @BeforeEach public void setup() { - initMocks(this); when(storageService.getStorage(any(String.class), any(ClassLoader.class))).thenReturn(storage); doAnswer(invocation -> lastAddedThing = (Thing) invocation.getArguments()[0]).when(thingRegistry) .add(any(Thing.class)); diff --git a/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java b/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java index 3a7389397..75c790441 100644 --- a/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java +++ b/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java @@ -13,7 +13,6 @@ package org.openhab.core.config.dispatch.internal; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.io.File; import java.nio.file.Path; @@ -21,24 +20,24 @@ import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchEvent; import java.nio.file.WatchEvent.Kind; -import org.junit.Before; -import org.junit.Test; +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; /** * @author Stefan Triller - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class ConfigDispatcherFileWatcherTest { private TestConfigDispatcherFileWatcher configDispatcherFileWatcher; - @Mock - ConfigDispatcher configDispatcher; + private @Mock ConfigDispatcher configDispatcher; - @Before + @BeforeEach public void setUp() throws Exception { - initMocks(this); - configDispatcherFileWatcher = new TestConfigDispatcherFileWatcher(configDispatcher); } diff --git a/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java b/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java index f5313f02e..02b772b25 100644 --- a/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java +++ b/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java @@ -12,14 +12,14 @@ */ package org.openhab.core.id; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.OpenHAB; /** diff --git a/bundles/org.openhab.core.io.bin2json/src/test/java/org/openhab/core/io/bin2json/Bin2JsonTest.java b/bundles/org.openhab.core.io.bin2json/src/test/java/org/openhab/core/io/bin2json/Bin2JsonTest.java index 16d0bab78..8d9267f6a 100644 --- a/bundles/org.openhab.core.io.bin2json/src/test/java/org/openhab/core/io/bin2json/Bin2JsonTest.java +++ b/bundles/org.openhab.core.io.bin2json/src/test/java/org/openhab/core/io/bin2json/Bin2JsonTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.io.bin2json; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.gson.JsonObject; @@ -29,9 +29,10 @@ import com.google.gson.JsonObject; */ public class Bin2JsonTest { - @Test(expected = ConversionException.class) + @Test public void testParserRuleError() throws ConversionException { - new Bin2Json("byte a byte b ubyte c;").convert(new byte[] { 3, 34, (byte) 255 }); + assertThrows(ConversionException.class, + () -> new Bin2Json("byte a byte b ubyte c;").convert(new byte[] { 3, 34, (byte) 255 })); } @Test @@ -40,9 +41,9 @@ public class Bin2JsonTest { assertEquals("{\"a\":3,\"b\":-6,\"c\":255}", json.toString()); } - @Test(expected = ConversionException.class) + @Test public void testHexStringDataError() throws ConversionException { - new Bin2Json("byte a; byte b; ubyte c;").convert("0322F"); + assertThrows(ConversionException.class, () -> new Bin2Json("byte a; byte b; ubyte c;").convert("0322F")); } @Test @@ -52,9 +53,10 @@ public class Bin2JsonTest { assertEquals("{\"length\":4,\"data\":[8,33,1,2]}", json.toString()); } - @Test(expected = ConversionException.class) + @Test public void testByteArrayDataError() throws ConversionException { - new Bin2Json("byte a; byte b; ubyte c;").convert(new byte[] { 3, 34 }); + assertThrows(ConversionException.class, + () -> new Bin2Json("byte a; byte b; ubyte c;").convert(new byte[] { 3, 34 })); } @Test @@ -64,9 +66,10 @@ public class Bin2JsonTest { assertEquals("{\"length\":4,\"data\":[8,33,1,2]}", json.toString()); } - @Test(expected = ConversionException.class) + @Test public void testInputStreamDataError() throws ConversionException { InputStream inputStream = new ByteArrayInputStream(new byte[] { 4, 8, 33 }); - new Bin2Json("ubyte length; ubyte[length] data;").convert(inputStream); + assertThrows(ConversionException.class, + () -> new Bin2Json("ubyte length; ubyte[length] data;").convert(inputStream)); } } diff --git a/bundles/org.openhab.core.io.http/src/test/java/org/openhab/core/io/http/internal/HttpContextFactoryServiceImplTest.java b/bundles/org.openhab.core.io.http/src/test/java/org/openhab/core/io/http/internal/HttpContextFactoryServiceImplTest.java index c20d7476c..740a88c2f 100644 --- a/bundles/org.openhab.core.io.http/src/test/java/org/openhab/core/io/http/internal/HttpContextFactoryServiceImplTest.java +++ b/bundles/org.openhab.core.io.http/src/test/java/org/openhab/core/io/http/internal/HttpContextFactoryServiceImplTest.java @@ -13,13 +13,14 @@ package org.openhab.core.io.http.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Before; -import org.junit.Test; +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.io.http.WrappingHttpContext; import org.osgi.framework.Bundle; import org.osgi.service.http.HttpContext; @@ -28,21 +29,18 @@ import org.osgi.service.http.HttpContext; * * @author Łukasz Dywicki - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class HttpContextFactoryServiceImplTest { private static final String RESOURCE = "resource"; private HttpContextFactoryServiceImpl httpContextFactoryService; - @Mock - private Bundle bundle; + private @Mock Bundle bundle; + private @Mock WrappingHttpContext httpContext; - @Mock - private WrappingHttpContext httpContext; - - @Before + @BeforeEach public void setup() { - initMocks(this); httpContextFactoryService = new HttpContextFactoryServiceImpl(); httpContextFactoryService.setHttpContext(httpContext); diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/exec/ExecUtilTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/exec/ExecUtilTest.java index b8ca4728d..0ba50abac 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/exec/ExecUtilTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/exec/ExecUtilTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.io.net.exec; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for the ExecUtil diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/BaseHttpUtilTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/BaseHttpUtilTest.java index 0c4a421bb..1eef736ad 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/BaseHttpUtilTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/BaseHttpUtilTest.java @@ -14,7 +14,6 @@ package org.openhab.core.io.net.http; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.lang.reflect.Field; import java.util.concurrent.TimeUnit; @@ -23,8 +22,12 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpMethod; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** * Base class for tests for the HttpRequestBuilder and HttpUtil to validate their behavior @@ -32,25 +35,18 @@ import org.mockito.Mock; * @author Martin van Wingerden & Wouter Born - Initial contribution * @author Markus Rathgeb - Base test classes without tests needs to be abstract */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public abstract class BaseHttpUtilTest { static final String URL = "http://example.org/test"; - @Mock - private HttpClientFactory clientFactoryMock; + protected @Mock HttpClientFactory clientFactoryMock; + protected @Mock HttpClient httpClientMock; + protected @Mock Request requestMock; + protected @Mock ContentResponse contentResponseMock; - @Mock - HttpClient httpClientMock; - - @Mock - Request requestMock; - - @Mock - ContentResponse contentResponseMock; - - @Before + @BeforeEach public void setUp() throws Exception { - initMocks(this); - Field httpClientFactory = HttpUtil.class.getDeclaredField("httpClientFactory"); httpClientFactory.setAccessible(true); httpClientFactory.set(null, clientFactoryMock); diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpRequestBuilderTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpRequestBuilderTest.java index 04193e3cc..651c531dd 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpRequestBuilderTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpRequestBuilderTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.io.net.http; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.verify; import java.nio.Buffer; @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.client.api.ContentProvider; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpUtilTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpUtilTest.java index 6bba2eb0f..2b4c23e04 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpUtilTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/HttpUtilTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.io.net.http; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.util.concurrent.TimeUnit; @@ -20,9 +20,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; /** * Tests for the HttpUtil @@ -32,9 +30,6 @@ import org.junit.rules.ExpectedException; */ public class HttpUtilTest extends BaseHttpUtilTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void baseTest() throws Exception { mockResponse(HttpStatus.OK_200); @@ -71,17 +66,15 @@ public class HttpUtilTest extends BaseHttpUtilTest { @Test public void testCreateHttpMethodForUnsupportedFake() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Given HTTP Method 'FAKE' is unknown"); - - HttpUtil.createHttpMethod("FAKE"); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> HttpUtil.createHttpMethod("FAKE")); + assertEquals("Given HTTP Method 'FAKE' is unknown", exception.getMessage()); } @Test public void testCreateHttpMethodForUnsupportedTrace() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Given HTTP Method 'TRACE' is unknown"); - - HttpUtil.createHttpMethod("TRACE"); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> HttpUtil.createHttpMethod("TRACE")); + assertEquals("Given HTTP Method 'TRACE' is unknown", exception.getMessage()); } } diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java index 899d26086..3fc35be6d 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java @@ -13,7 +13,6 @@ package org.openhab.core.io.net.http.internal; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.lang.reflect.Field; import java.net.Socket; @@ -30,9 +29,13 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.X509ExtendedTrustManager; import javax.security.auth.x500.X500Principal; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.io.net.http.TlsTrustManagerProvider; /** @@ -40,40 +43,24 @@ import org.openhab.core.io.net.http.TlsTrustManagerProvider; * * @author Martin van Wingerden - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class ExtensibleTrustManagerImplTest { + private X509Certificate[] chain; private ExtensibleTrustManagerImpl subject; - @Mock - private TlsTrustManagerProvider trustmanagerProvider; + private @Mock TlsTrustManagerProvider trustmanagerProvider; + private @Mock TlsTrustManagerProvider trustmanagerProviderHostPort; + private @Mock X509ExtendedTrustManager trustmanager; + private @Mock X509ExtendedTrustManager trustmanager2; + private @Mock X509ExtendedTrustManager defaultTrustManager; + private @Mock SSLEngine sslEngine; + private @Mock X509Certificate topOfChain; + private @Mock X509Certificate bottomOfChain; - @Mock - private TlsTrustManagerProvider trustmanagerProviderHostPort; - - @Mock - private X509ExtendedTrustManager trustmanager; - - @Mock - private X509ExtendedTrustManager trustmanager2; - - @Mock - private X509ExtendedTrustManager defaultTrustManager; - - @Mock - private SSLEngine sslEngine; - - @Mock - private X509Certificate topOfChain; - - @Mock - private X509Certificate bottomOfChain; - - private X509Certificate[] chain; - - @Before + @BeforeEach public void setup() { - initMocks(this); - when(trustmanagerProvider.getHostName()).thenReturn("example.org"); when(trustmanagerProvider.getTrustManager()).thenReturn(trustmanager); diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java index c5d411d31..93114b366 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java @@ -13,10 +13,10 @@ package org.openhab.core.io.net.http.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; @@ -36,17 +36,20 @@ import javax.net.ssl.SSLHandshakeException; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; /** * @author Kai Kreuzer - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class WebClientFactoryImplTest { private WebClientFactoryImpl webClientFactory; @@ -55,14 +58,13 @@ public class WebClientFactoryImplTest { private @Mock ExtensibleTrustManagerImpl extensibleTrustManager; - @Before + @BeforeEach public void setup() { - initMocks(this); webClientFactory = new WebClientFactoryImpl(extensibleTrustManager); webClientFactory.activate(createConfigMap(4, 200, 60, 2, 10, 60)); } - @After + @AfterEach public void tearDown() { webClientFactory.deactivate(); } @@ -76,8 +78,8 @@ public class WebClientFactoryImplTest { assertThat(webSocketClient, is(notNullValue())); } + @Disabled("connecting to the outside world makes this test flaky") @Test - @Ignore("connecting to the outside world makes this test flaky") public void testCommonClientUsesExtensibleTrustManager() throws Exception { ArgumentCaptor certificateChainCaptor = ArgumentCaptor.forClass(X509Certificate[].class); ArgumentCaptor sslEngineCaptor = ArgumentCaptor.forClass(SSLEngine.class); @@ -97,21 +99,23 @@ public class WebClientFactoryImplTest { containsString("eclipse.org")); } - @Ignore("connecting to the outside world makes this test flaky") - @Test(expected = SSLHandshakeException.class) + @Disabled("connecting to the outside world makes this test flaky") + @Test public void testCommonClientUsesExtensibleTrustManagerFailure() throws Throwable { doThrow(new CertificateException()).when(extensibleTrustManager).checkServerTrusted( ArgumentMatchers.any(X509Certificate[].class), anyString(), ArgumentMatchers.any(SSLEngine.class)); HttpClient httpClient = webClientFactory.getCommonHttpClient(); - try { - httpClient.GET(TEST_URL); - } catch (ExecutionException e) { - throw e.getCause(); - } + assertThrows(SSLHandshakeException.class, () -> { + try { + httpClient.GET(TEST_URL); + } catch (ExecutionException e) { + throw e.getCause(); + } + }); } - @Ignore("only for manual test") + @Disabled("only for manual test") @Test public void testMultiThreadedShared() throws Exception { ThreadPoolExecutor workers = new ThreadPoolExecutor(20, 80, 60, TimeUnit.SECONDS, @@ -154,7 +158,7 @@ public class WebClientFactoryImplTest { } } - @Ignore("only for manual test") + @Disabled("only for manual test") @Test public void testMultiThreadedCustom() throws Exception { ThreadPoolExecutor workers = new ThreadPoolExecutor(20, 80, 60, TimeUnit.SECONDS, diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java index a7a78d90e..b96039232 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java @@ -13,13 +13,13 @@ package org.openhab.core.io.rest.core.config; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import java.net.URI; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionBuilder; import org.openhab.core.config.core.ConfigDescriptionParameter; diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResourceTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResourceTest.java index 341f2dc45..a484a28ad 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResourceTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/channel/ChannelTypeResourceTest.java @@ -13,9 +13,8 @@ package org.openhab.core.io.rest.core.internal.channel; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.io.IOException; import java.util.Arrays; @@ -25,14 +24,15 @@ import java.util.Set; import javax.ws.rs.core.Response; -import org.hamcrest.core.IsCollectionContaining; -import org.junit.Before; -import org.junit.Test; +import org.hamcrest.core.IsIterableContaining; +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.config.core.ConfigDescriptionRegistry; import org.openhab.core.io.rest.LocaleServiceImpl; import org.openhab.core.thing.profiles.ProfileTypeRegistry; -import org.openhab.core.thing.profiles.ProfileTypeUID; import org.openhab.core.thing.profiles.TriggerProfileType; import org.openhab.core.thing.type.ChannelKind; import org.openhab.core.thing.type.ChannelType; @@ -42,6 +42,7 @@ import org.openhab.core.thing.type.ChannelTypeUID; /** * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class ChannelTypeResourceTest { private ChannelTypeResource channelTypeResource; @@ -51,9 +52,8 @@ public class ChannelTypeResourceTest { private @Mock LocaleServiceImpl localeService; private @Mock ProfileTypeRegistry profileTypeRegistry; - @Before + @BeforeEach public void setup() { - initMocks(this); channelTypeResource = new ChannelTypeResource(channelTypeRegistry, configDescriptionRegistry, localeService, profileTypeRegistry); } @@ -70,12 +70,10 @@ public class ChannelTypeResourceTest { public void returnLinkableItemTypesForTriggerChannelType() throws IOException { ChannelType channelType = mockChannelType("ct"); ChannelTypeUID uid = channelType.getUID(); - ProfileTypeUID profileTypeUID = new ProfileTypeUID("system:profileType"); when(channelTypeRegistry.getChannelType(uid)).thenReturn(channelType); TriggerProfileType profileType = mock(TriggerProfileType.class); - when(profileType.getUID()).thenReturn(profileTypeUID); when(profileType.getSupportedChannelTypeUIDs()).thenReturn(Collections.singletonList(uid)); when(profileType.getSupportedItemTypes()).thenReturn(Arrays.asList("Switch", "Dimmer")); @@ -86,7 +84,7 @@ public class ChannelTypeResourceTest { verify(channelTypeRegistry).getChannelType(uid); verify(profileTypeRegistry).getProfileTypes(); assertThat(response.getStatus(), is(200)); - assertThat((Set) response.getEntity(), IsCollectionContaining.hasItems("Switch", "Dimmer")); + assertThat((Set) response.getEntity(), IsIterableContaining.hasItems("Switch", "Dimmer")); } private ChannelType mockChannelType(String channelId) { diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/item/MetadataSelectorMatcherTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/item/MetadataSelectorMatcherTest.java index 0421053db..5fffed066 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/item/MetadataSelectorMatcherTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/item/MetadataSelectorMatcherTest.java @@ -13,12 +13,11 @@ package org.openhab.core.io.rest.core.internal.item; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.core.IsCollectionContaining.hasItem; -import static org.junit.Assert.assertThat; +import static org.hamcrest.core.IsIterableContaining.hasItem; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.net.URI; import java.util.ArrayList; @@ -26,9 +25,13 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionBuilder; import org.openhab.core.config.core.ConfigDescriptionRegistry; @@ -39,20 +42,17 @@ import org.openhab.core.items.MetadataRegistry; * * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class MetadataSelectorMatcherTest { private MetadataSelectorMatcher matcher; - @Mock - private ConfigDescriptionRegistry configDescriptionRegistry; + private @Mock ConfigDescriptionRegistry configDescriptionRegistry; + private @Mock MetadataRegistry metadataRegistry; - @Mock - private MetadataRegistry metadataRegistry; - - @Before + @BeforeEach public void setup() throws Exception { - initMocks(this); - when(configDescriptionRegistry.getConfigDescriptions(null)).thenReturn(mockConfigDescriptions()); when(metadataRegistry.isInternalNamespace(anyString())).thenReturn(false); diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperTest.java index 85af14eb9..9ba3dc8f8 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperTest.java @@ -13,10 +13,10 @@ package org.openhab.core.io.rest.core.item; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.GenericItem; import org.openhab.core.items.GroupItem; import org.openhab.core.library.CoreItemFactory; @@ -29,7 +29,7 @@ public class EnrichedItemDTOMapperTest extends JavaTest { private CoreItemFactory itemFactory; - @Before + @BeforeEach public void setup() { itemFactory = new CoreItemFactory(); } diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java index 792df296d..0bce5da7d 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java @@ -13,11 +13,10 @@ package org.openhab.core.io.rest.core.thing; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.ArrayList; import java.util.List; @@ -27,9 +26,11 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.hamcrest.CoreMatchers; -import org.junit.Before; -import org.junit.Test; +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.config.core.Configuration; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; @@ -43,6 +44,7 @@ import org.openhab.core.thing.firmware.dto.FirmwareStatusDTO; /** * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class EnrichedThingDTOMapperTest { private static final String ITEM_TYPE = "itemType"; @@ -51,27 +53,15 @@ public class EnrichedThingDTOMapperTest { private static final String THING_LABEL = "label"; private static final String LOCATION = "location"; - @Mock - private Thing thing; + private @Mock Thing thing; + private @Mock ThingStatusInfo thingStatusInfo; + private @Mock FirmwareStatusDTO firmwareStatus; + private @Mock Map> linkedItemsMap; + private @Mock Configuration configuration; + private @Mock Map properties; - @Mock - private ThingStatusInfo thingStatusInfo; - - @Mock - private FirmwareStatusDTO firmwareStatus; - - @Mock - private Map> linkedItemsMap; - - @Mock - private Configuration configuration; - - @Mock - private Map properties; - - @Before + @BeforeEach public void setup() { - initMocks(this); when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID(THING_TYPE_UID)); when(thing.getUID()).thenReturn(new ThingUID(UID)); when(thing.getLabel()).thenReturn(THING_LABEL); diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java b/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java index cffefd24c..bc49d1630 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java @@ -13,11 +13,10 @@ package org.openhab.core.io.rest.sitemap.internal; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.math.BigDecimal; import java.util.Collection; @@ -34,9 +33,13 @@ import javax.ws.rs.core.UriInfo; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.io.rest.LocaleService; import org.openhab.core.io.rest.sitemap.SitemapSubscriptionService; import org.openhab.core.items.GenericItem; @@ -59,6 +62,8 @@ import org.openhab.core.ui.items.ItemUIRegistry; * * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class SitemapResourceTest extends JavaTest { private static final int STATE_UPDATE_WAIT_TIME = 100; @@ -96,10 +101,8 @@ public class SitemapResourceTest extends JavaTest { private EList widgets; - @Before + @BeforeEach public void setup() throws Exception { - initMocks(this); - sitemapResource = new SitemapResource(itemUIRegistry, localeService, subscriptions); when(uriInfo.getAbsolutePathBuilder()).thenReturn(UriBuilder.fromPath(SITEMAP_PATH)); diff --git a/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java b/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java index d1291891b..49244c4e6 100644 --- a/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java +++ b/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java @@ -13,11 +13,11 @@ package org.openhab.core.io.rest.sse.internal.util; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dennis Nobel - Initial contribution diff --git a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java index e36f4e206..43cde9e2a 100644 --- a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java +++ b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java @@ -13,8 +13,9 @@ package org.openhab.core.io.rest; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.object.IsCompatibleType.typeCompatibleWith; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -27,7 +28,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.gson.JsonObject; diff --git a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java index 8bd3fffd5..3690ba93a 100644 --- a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java +++ b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java @@ -13,7 +13,8 @@ package org.openhab.core.io.rest; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.io.InputStream; @@ -23,7 +24,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -39,9 +40,9 @@ public class Stream2JSONInputStreamTest { private static final Gson GSON = new GsonBuilder().create(); - @Test(expected = IllegalArgumentException.class) + @Test public void shouldFailForNullSource() throws IOException { - new Stream2JSONInputStream(null).close(); + assertThrows(IllegalArgumentException.class, () -> new Stream2JSONInputStream(null).close()); } @Test diff --git a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/CorsFilterTest.java b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/CorsFilterTest.java index 5d1839dec..cee43aee4 100644 --- a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/CorsFilterTest.java +++ b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/CorsFilterTest.java @@ -14,7 +14,7 @@ package org.openhab.core.io.rest.internal.filter; import static java.util.Collections.*; import static java.util.stream.Collectors.toList; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; import static org.openhab.core.io.rest.internal.filter.CorsFilter.*; @@ -27,12 +27,13 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +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.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** * Test for the {@link CorsFilter} filter @@ -40,6 +41,8 @@ import org.mockito.junit.MockitoRule; * @author Antoine Besnard - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java and use Mockito */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class CorsFilterTest { private static final String CONTENT_TYPE_HEADER = HttpHeaders.CONTENT_TYPE; @@ -56,9 +59,7 @@ public class CorsFilterTest { private @Mock ContainerRequestContext requestContext; private @Mock ContainerResponseContext responseContext; - public @Rule MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Before + @BeforeEach public void setUp() { filter = new CorsFilter(); filter.activate(singletonMap("enable", "true")); diff --git a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/ProxyFilterTest.java b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/ProxyFilterTest.java index 40cf9d422..1acea42e8 100644 --- a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/ProxyFilterTest.java +++ b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/ProxyFilterTest.java @@ -26,12 +26,13 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +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.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** * Test for {@link ProxyFilter} @@ -39,15 +40,16 @@ import org.mockito.junit.MockitoRule; * @author Ivan Iliev - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java and use Mockito */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class ProxyFilterTest { private final ProxyFilter filter = new ProxyFilter(); private @Mock ContainerRequestContext context; private @Mock UriInfo uriInfo; - public @Rule MockitoRule mockitoRule = MockitoJUnit.rule(); - @Before + @BeforeEach public void before() { when(context.getUriInfo()).thenReturn(uriInfo); } diff --git a/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/MqttBrokerConnectionTests.java b/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/MqttBrokerConnectionTests.java index ee4aac150..4c442555a 100644 --- a/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/MqttBrokerConnectionTests.java +++ b/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/MqttBrokerConnectionTests.java @@ -13,7 +13,8 @@ package org.openhab.core.io.transport.mqtt; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -27,7 +28,7 @@ import java.util.concurrent.TimeoutException; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.io.transport.mqtt.internal.client.MqttAsyncClientWrapper; import org.openhab.core.io.transport.mqtt.reconnect.AbstractReconnectStrategy; import org.openhab.core.io.transport.mqtt.reconnect.PeriodicReconnectStrategy; @@ -281,29 +282,29 @@ public class MqttBrokerConnectionTests extends JavaTest { assertArrayEquals(connection.getLastWill().getPayload(), b); } - @Test(expected = IllegalArgumentException.class) + @Test public void lastWillAndTestamentConstructorTests() { - new MqttWillAndTestament("", new byte[0], 0, false); + assertThrows(IllegalArgumentException.class, () -> new MqttWillAndTestament("", new byte[0], 0, false)); } - @Test(expected = IllegalArgumentException.class) + @Test public void qosInvalid() throws ConfigurationException { MqttBrokerConnectionEx connection = new MqttBrokerConnectionEx("123.123.123.123", null, false, "qosInvalid"); - connection.setQos(10); + assertThrows(IllegalArgumentException.class, () -> connection.setQos(10)); } @Test public void setterGetterTests() { MqttBrokerConnectionEx connection = new MqttBrokerConnectionEx("123.123.123.123", null, false, "setterGetterTests"); - assertEquals("URL getter", connection.getHost(), "123.123.123.123"); - assertEquals("Name getter", connection.getPort(), 1883); // Check for non-secure port - assertFalse("Secure getter", connection.isSecure()); - assertEquals("ClientID getter", "setterGetterTests", connection.getClientId()); + assertEquals(connection.getHost(), "123.123.123.123", "URL getter"); + assertEquals(connection.getPort(), 1883, "Name getter"); // Check for non-secure port + assertFalse(connection.isSecure(), "Secure getter"); + assertEquals("setterGetterTests", connection.getClientId(), "ClientID getter"); connection.setCredentials("user@!", "password123@^"); - assertEquals("User getter/setter", "user@!", connection.getUser()); - assertEquals("Password getter/setter", "password123@^", connection.getPassword()); + assertEquals("user@!", connection.getUser(), "User getter/setter"); + assertEquals("password123@^", connection.getPassword(), "Password getter/setter"); assertEquals(MqttBrokerConnection.DEFAULT_KEEPALIVE_INTERVAL, connection.getKeepAliveInterval()); connection.setKeepAliveInterval(80); diff --git a/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/internal/MqttServiceTests.java b/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/internal/MqttServiceTests.java index 7ba835535..21f1072f1 100644 --- a/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/internal/MqttServiceTests.java +++ b/bundles/org.openhab.core.io.transport.mqtt/src/test/java/org/openhab/core/io/transport/mqtt/internal/MqttServiceTests.java @@ -13,11 +13,12 @@ package org.openhab.core.io.transport.mqtt.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.io.transport.mqtt.MqttBrokerConnection; import org.openhab.core.io.transport.mqtt.MqttBrokerConnectionEx; diff --git a/bundles/org.openhab.core.io.transport.upnp/src/test/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceTest.java b/bundles/org.openhab.core.io.transport.upnp/src/test/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceTest.java index 1ad9996dc..cc26b3e00 100644 --- a/bundles/org.openhab.core.io.transport.upnp/src/test/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceTest.java +++ b/bundles/org.openhab.core.io.transport.upnp/src/test/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.io.transport.upnp.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.jupnp.UpnpService; import org.jupnp.controlpoint.ControlPoint; import org.jupnp.model.meta.DeviceDetails; @@ -32,6 +32,9 @@ import org.jupnp.model.types.UDAServiceId; import org.jupnp.model.types.UDN; import org.jupnp.registry.Registry; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.io.transport.upnp.UpnpIOParticipant; /** @@ -39,6 +42,8 @@ import org.openhab.core.io.transport.upnp.UpnpIOParticipant; * * @author Andre Fuechsel - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class UpnpIOServiceTest { private static final String UDN_1_STRING = "UDN"; @@ -59,12 +64,9 @@ public class UpnpIOServiceTest { private UpnpIOServiceImpl upnpIoService; - @Before + @BeforeEach public void setup() throws Exception { - initMocks(this); - when(upnpIoParticipant.getUDN()).thenReturn(UDN_1_STRING); - when(upnpIoParticipant2.getUDN()).thenReturn(UDN_2_STRING); DeviceIdentity deviceIdentity = new DeviceIdentity(UDN_1); diff --git a/bundles/org.openhab.core.karaf/pom.xml b/bundles/org.openhab.core.karaf/pom.xml index f9da9b5fa..c3770e746 100644 --- a/bundles/org.openhab.core.karaf/pom.xml +++ b/bundles/org.openhab.core.karaf/pom.xml @@ -22,10 +22,9 @@ org.openhab.core.bundles - org.openhab.core.boot + org.openhab.core.config.core ${project.version} - org.apache.karaf.features org.apache.karaf.features.core diff --git a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java index 4e96c403e..4c6d37377 100644 --- a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java +++ b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java @@ -38,7 +38,6 @@ import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; import org.openhab.core.OpenHAB; import org.openhab.core.addon.AddonEventFactory; -import org.openhab.core.config.core.ConfigConstants; import org.openhab.core.config.core.ConfigurableService; import org.openhab.core.events.Event; import org.openhab.core.events.EventPublisher; @@ -247,7 +246,7 @@ public class FeatureInstaller implements ConfigurationListener { private void setOnlineRepoUrl() { Properties prop = new Properties(); - Path versionFilePath = Paths.get(ConfigConstants.getUserDataFolder(), "etc", "version.properties"); + Path versionFilePath = Paths.get(OpenHAB.getUserDataFolder(), "etc", "version.properties"); try (FileInputStream fis = new FileInputStream(versionFilePath.toFile())) { prop.load(fis); } catch (Exception e) { diff --git a/bundles/org.openhab.core.model.lsp/src/test/java/org/openhab/core/model/lsp/internal/MappingUriExtensionsTest.java b/bundles/org.openhab.core.model.lsp/src/test/java/org/openhab/core/model/lsp/internal/MappingUriExtensionsTest.java index 9b5854168..94b7d58fc 100644 --- a/bundles/org.openhab.core.model.lsp/src/test/java/org/openhab/core/model/lsp/internal/MappingUriExtensionsTest.java +++ b/bundles/org.openhab.core.model.lsp/src/test/java/org/openhab/core/model/lsp/internal/MappingUriExtensionsTest.java @@ -12,40 +12,29 @@ */ package org.openhab.core.model.lsp.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Collection; import org.eclipse.emf.common.util.URI; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * * @author Simon Kaufmann - Initial contribution */ -@RunWith(Parameterized.class) public class MappingUriExtensionsTest { - @Rule - public final TemporaryFolder folder = new TemporaryFolder(); + public @TempDir File folder; private File confFolder; - private File itemsFolder; - private File itemsFile; - private final String conf; - private final String request; - private final String expectedClientPath; - private final String expectedUriPath; - @Parameters - public static Collection data() { + private static Collection data() { return Arrays.asList(new Object[][] { // { "conf", // "file:///q:/conf", // @@ -82,40 +71,38 @@ public class MappingUriExtensionsTest { }); } - public MappingUriExtensionsTest(String conf, String request, String expectedClientPath, String expectedUriPath) { - this.conf = conf; - this.request = request; - this.expectedClientPath = expectedClientPath; - this.expectedUriPath = expectedUriPath; - } + @BeforeEach + public void setup() throws IOException { + confFolder = new File(folder, "conf"); - @Before - public void setup() throws Exception { - confFolder = folder.newFolder("conf"); - itemsFolder = new File(confFolder, "items"); + File itemsFolder = new File(confFolder, "items"); itemsFolder.mkdirs(); - itemsFile = new File(itemsFolder, "test.items"); + + File itemsFile = new File(itemsFolder, "test.items"); itemsFile.deleteOnExit(); itemsFile.createNewFile(); } - @Test - public void testGuessClientPath() { - MappingUriExtensions mapper = createMapper(); + @ParameterizedTest + @MethodSource("data") + public void testGuessClientPath(String conf, String request, String expectedClientPath, String expectedUriPath) { + MappingUriExtensions mapper = createMapper(conf); String clientPath = mapper.guessClientPath(request); assertEquals(expectedClientPath, clientPath); } - @Test - public void testToUri() { - MappingUriExtensions mapper = createMapper(); + @ParameterizedTest + @MethodSource("data") + public void testToUri(String conf, String request, String expectedClientPath, String expectedUriPath) { + MappingUriExtensions mapper = createMapper(conf); URI clientPath = mapper.toUri(request); assertEquals(confFolder.toPath().toUri().toString() + expectedUriPath, clientPath.toString()); } - @Test - public void testToPathEmfURI() { - MappingUriExtensions mapper = createMapper(); + @ParameterizedTest + @MethodSource("data") + public void testToPathEmfURI(String conf, String request, String expectedClientPath, String expectedUriPath) { + MappingUriExtensions mapper = createMapper(conf); mapper.toUri(request); URI uri = URI.createURI(confFolder.toPath().toUri().toString() + expectedUriPath); @@ -123,7 +110,7 @@ public class MappingUriExtensionsTest { assertEquals(request, res); } - private MappingUriExtensions createMapper() { + private MappingUriExtensions createMapper(String conf) { return new MappingUriExtensions(conf) { @Override protected String calcServerLocation(String configFolder) { diff --git a/bundles/org.openhab.core.model.script/src.moved/test/java/org/openhab/core/model/script/internal/actions/TimerImplTest.java b/bundles/org.openhab.core.model.script/src.moved/test/java/org/openhab/core/model/script/internal/actions/TimerImplTest.java index 0aab152cc..fb172fa69 100644 --- a/bundles/org.openhab.core.model.script/src.moved/test/java/org/openhab/core/model/script/internal/actions/TimerImplTest.java +++ b/bundles/org.openhab.core.model.script/src.moved/test/java/org/openhab/core/model/script/internal/actions/TimerImplTest.java @@ -13,14 +13,14 @@ package org.openhab.core.model.script.internal.actions; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.time.ZonedDateTime; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.internal.scheduler.SchedulerImpl; import org.openhab.core.model.script.actions.Timer; import org.openhab.core.scheduler.SchedulerRunnable; @@ -41,7 +41,7 @@ public class TimerImplTest { private final SchedulerImpl scheduler = new SchedulerImpl(); private @NonNullByDefault({}) Timer subject; - @Before + @BeforeEach public void setUp() { subject = createTimer(ZonedDateTime.now().plusSeconds(DEFAULT_TIMEOUT_SECONDS), () -> { Thread.sleep(TimeUnit.SECONDS.toMillis(DEFAULT_RUNTIME_SECONDS)); diff --git a/bundles/org.openhab.core.model.thing/src.moved/test/java/org/openhab/core/model/thing/internal/GenericThingProviderMultipleBundlesTest.java b/bundles/org.openhab.core.model.thing/src.moved/test/java/org/openhab/core/model/thing/internal/GenericThingProviderMultipleBundlesTest.java index 4233522ab..d659590bf 100644 --- a/bundles/org.openhab.core.model.thing/src.moved/test/java/org/openhab/core/model/thing/internal/GenericThingProviderMultipleBundlesTest.java +++ b/bundles/org.openhab.core.model.thing/src.moved/test/java/org/openhab/core/model/thing/internal/GenericThingProviderMultipleBundlesTest.java @@ -17,7 +17,14 @@ import static org.mockito.Mockito.*; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.Configuration; +import org.openhab.core.model.core.EventType; +import org.openhab.core.model.core.ModelRepository; +import org.openhab.core.model.thing.thing.ModelBridge; +import org.openhab.core.model.thing.thing.ModelThing; +import org.openhab.core.model.thing.thing.ThingModel; import org.openhab.core.service.ReadyMarker; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingUID; @@ -25,13 +32,6 @@ import org.openhab.core.thing.binding.ThingHandlerFactory; import org.openhab.core.thing.binding.builder.BridgeBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder; import org.openhab.core.util.BundleResolver; -import org.openhab.core.model.core.EventType; -import org.openhab.core.model.core.ModelRepository; -import org.openhab.core.model.thing.thing.ModelBridge; -import org.openhab.core.model.thing.thing.ModelThing; -import org.openhab.core.model.thing.thing.ThingModel; -import org.junit.Before; -import org.junit.Test; import org.osgi.framework.Bundle; /** @@ -55,7 +55,7 @@ public class GenericThingProviderMultipleBundlesTest { private ThingHandlerFactory bridgeHandlerFactory; private ThingHandlerFactory thingHandlerFactory; - @Before + @BeforeEach public void setup() { thingProvider = new GenericThingProvider(); diff --git a/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/SemanticTagsTest.java b/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/SemanticTagsTest.java index 916067b07..4415ab409 100644 --- a/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/SemanticTagsTest.java +++ b/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/SemanticTagsTest.java @@ -12,12 +12,12 @@ */ package org.openhab.core.semantics; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.GenericItem; import org.openhab.core.items.GroupItem; import org.openhab.core.library.CoreItemFactory; @@ -38,7 +38,7 @@ public class SemanticTagsTest { private GroupItem equipmentItem; private GenericItem pointItem; - @Before + @BeforeEach public void setup() throws Exception { CoreItemFactory itemFactory = new CoreItemFactory(); locationItem = new GroupItem("TestBathRoom"); diff --git a/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java b/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java index 13880ad07..bab0e48ed 100644 --- a/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java +++ b/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java @@ -12,18 +12,18 @@ */ package org.openhab.core.semantics.internal; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.Locale; import java.util.Set; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; +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.items.GenericItem; import org.openhab.core.items.GroupItem; import org.openhab.core.items.Item; @@ -36,6 +36,7 @@ import org.openhab.core.semantics.model.location.LivingRoom; /** * @author Kai Kreuzer - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class SemanticsServiceImplTest { private @Mock ItemRegistry itemRegistry; @@ -47,10 +48,8 @@ public class SemanticsServiceImplTest { private SemanticsServiceImpl service; - @Before + @BeforeEach public void setup() throws Exception { - initMocks(this); - CoreItemFactory itemFactory = new CoreItemFactory(); locationItem = new GroupItem("TestBathRoom"); locationItem.addTag("Bathroom"); @@ -66,7 +65,6 @@ public class SemanticsServiceImplTest { pointItem.addGroupName(locationItem.getName()); locationItem.addMember(pointItem); - when(metadataRegistry.get(any())).thenReturn(null); when(itemRegistry.stream()).thenReturn(Stream.of(locationItem, equipmentItem, pointItem)) .thenReturn(Stream.of(locationItem, equipmentItem, pointItem)) .thenReturn(Stream.of(locationItem, equipmentItem, pointItem)); diff --git a/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java b/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java index 2c6b481f2..887a45e40 100644 --- a/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java +++ b/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.storage.json.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.IOException; @@ -22,8 +22,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.Configuration; import org.openhab.core.test.java.JavaTest; @@ -37,7 +37,7 @@ public class JsonStorageTest extends JavaTest { private JsonStorage objectStorage; private File tmpFile; - @Before + @BeforeEach public void setUp() throws IOException { tmpFile = File.createTempFile("storage-debug", ".json"); tmpFile.deleteOnExit(); diff --git a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicColorLightHandlerTest.java b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicColorLightHandlerTest.java index b8faa243c..d8e8d08db 100644 --- a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicColorLightHandlerTest.java +++ b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicColorLightHandlerTest.java @@ -13,15 +13,16 @@ package org.openhab.core.magic.binding.handler; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusInfo; @@ -33,19 +34,16 @@ import org.openhab.core.thing.binding.ThingHandlerCallback; * * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class MagicColorLightHandlerTest { private ThingHandler handler; - @Mock - private ThingHandlerCallback callback; + private @Mock ThingHandlerCallback callback; + private @Mock Thing thing; - @Mock - private Thing thing; - - @Before + @BeforeEach public void setUp() { - initMocks(this); handler = new MagicColorLightHandler(thing); handler.setCallback(callback); } @@ -59,6 +57,6 @@ public class MagicColorLightHandlerTest { verify(callback).statusUpdated(eq(thing), statusInfoCaptor.capture()); ThingStatusInfo thingStatusInfo = statusInfoCaptor.getValue(); - Assert.assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.ONLINE))); + assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.ONLINE))); } } diff --git a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicDimmableLightHandlerTest.java b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicDimmableLightHandlerTest.java index c9710acfe..4a223c3df 100644 --- a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicDimmableLightHandlerTest.java +++ b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicDimmableLightHandlerTest.java @@ -13,15 +13,16 @@ package org.openhab.core.magic.binding.handler; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusInfo; @@ -33,19 +34,16 @@ import org.openhab.core.thing.binding.ThingHandlerCallback; * * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class MagicDimmableLightHandlerTest { private ThingHandler handler; - @Mock - private ThingHandlerCallback callback; + private @Mock ThingHandlerCallback callback; + private @Mock Thing thing; - @Mock - private Thing thing; - - @Before + @BeforeEach public void setUp() { - initMocks(this); handler = new MagicDimmableLightHandler(thing); handler.setCallback(callback); } @@ -59,6 +57,6 @@ public class MagicDimmableLightHandlerTest { verify(callback).statusUpdated(eq(thing), statusInfoCaptor.capture()); ThingStatusInfo thingStatusInfo = statusInfoCaptor.getValue(); - Assert.assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.ONLINE))); + assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.ONLINE))); } } diff --git a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicOnOffLightHandlerTest.java b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicOnOffLightHandlerTest.java index 1321b6d63..b490051ce 100644 --- a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicOnOffLightHandlerTest.java +++ b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/handler/MagicOnOffLightHandlerTest.java @@ -13,15 +13,16 @@ package org.openhab.core.magic.binding.handler; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusInfo; @@ -33,19 +34,16 @@ import org.openhab.core.thing.binding.ThingHandlerCallback; * * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class MagicOnOffLightHandlerTest { private ThingHandler handler; - @Mock - private ThingHandlerCallback callback; + private @Mock ThingHandlerCallback callback; + private @Mock Thing thing; - @Mock - private Thing thing; - - @Before + @BeforeEach public void setUp() { - initMocks(this); handler = new MagicOnOffLightHandler(thing); handler.setCallback(callback); } @@ -59,6 +57,6 @@ public class MagicOnOffLightHandlerTest { verify(callback).statusUpdated(eq(thing), statusInfoCaptor.capture()); ThingStatusInfo thingStatusInfo = statusInfoCaptor.getValue(); - Assert.assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.ONLINE))); + assertThat(thingStatusInfo.getStatus(), is(equalTo(ThingStatus.ONLINE))); } } diff --git a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicHandlerFactoryTest.java b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicHandlerFactoryTest.java index 0ed1aa7aa..d8e7aaa5d 100644 --- a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicHandlerFactoryTest.java +++ b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicHandlerFactoryTest.java @@ -13,12 +13,12 @@ package org.openhab.core.magic.binding.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.magic.binding.MagicBindingConstants; import org.openhab.core.magic.binding.handler.MagicColorLightHandler; import org.openhab.core.magic.binding.handler.MagicDimmableLightHandler; @@ -36,7 +36,7 @@ public class MagicHandlerFactoryTest { private @NonNullByDefault({}) MagicHandlerFactory factory; - @Before + @BeforeEach public void setup() { factory = new MagicHandlerFactory(mock(MagicDynamicStateDescriptionProvider.class)); } diff --git a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicServiceImplTest.java b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicServiceImplTest.java index ef8824566..d6c78741f 100644 --- a/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicServiceImplTest.java +++ b/bundles/org.openhab.core.test.magic/src/test/java/org/openhab/core/magic/binding/internal/MagicServiceImplTest.java @@ -12,14 +12,15 @@ */ package org.openhab.core.magic.binding.internal; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertNull; import java.net.URI; import java.util.Collection; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ParameterOption; import org.openhab.core.magic.binding.MagicService; @@ -34,7 +35,7 @@ public class MagicServiceImplTest { private MagicService magicService; - @Before + @BeforeEach public void setup() { magicService = new MagicServiceImpl(); } diff --git a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/SyntheticBundleInstaller.java b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/SyntheticBundleInstaller.java index 095de14cf..003bbbaa1 100644 --- a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/SyntheticBundleInstaller.java +++ b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/SyntheticBundleInstaller.java @@ -12,6 +12,8 @@ */ package org.openhab.core.test; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -33,7 +35,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.ZipEntry; -import org.junit.Assert; import org.openhab.core.service.ReadyMarker; import org.openhab.core.service.ReadyMarkerUtils; import org.openhab.core.service.ReadyService; @@ -292,7 +293,7 @@ public class SyntheticBundleInstaller { ReadyMarker expected = new ReadyMarker(marker, identifier); while (!readyService.isReady(expected)) { if (System.nanoTime() - startTime > TimeUnit.SECONDS.toNanos(WAIT_TIMOUT)) { - Assert.fail(MessageFormat.format("Timout waiting for marker {0} at bundle {1}", marker, identifier)); + fail(MessageFormat.format("Timout waiting for marker {0} at bundle {1}", marker, identifier)); } try { Thread.sleep(100); diff --git a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java index e74a9e746..4d9994280 100644 --- a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java +++ b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java @@ -13,7 +13,8 @@ package org.openhab.core.test.java; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Arrays; @@ -27,9 +28,8 @@ import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.openhab.core.test.internal.java.MissingServiceAnalyzer; import org.openhab.core.test.storage.VolatileStorageService; import org.osgi.framework.Bundle; @@ -53,7 +53,7 @@ public class JavaOSGiTest extends JavaTest { private final Map>> registeredServices = new HashMap<>(); protected @NonNullByDefault({}) BundleContext bundleContext; - @Before + @BeforeEach public void bindBundleContext() { bundleContext = initBundleContext(); assertThat(bundleContext, is(notNullValue())); @@ -149,7 +149,7 @@ public class JavaOSGiTest extends JavaTest { */ private @Nullable I getSingleServiceInstance(Class clazz, final List filteredServices) { if (filteredServices.size() > 1) { - Assert.fail("More than 1 service matching the filter is registered."); + fail("More than 1 service matching the filter is registered."); } if (filteredServices.isEmpty()) { new MissingServiceAnalyzer(System.out, bundleContext).printMissingServiceDetails(clazz); @@ -351,7 +351,7 @@ public class JavaOSGiTest extends JavaTest { registerService(new VolatileStorageService()); } - @After + @AfterEach public void unregisterMocks() { registeredServices.forEach((interfaceName, services) -> services.forEach(service -> service.unregister())); registeredServices.clear(); diff --git a/bundles/org.openhab.core.test/src/test/java/org/openhab/core/test/java/JavaTestTest.java b/bundles/org.openhab.core.test/src/test/java/org/openhab/core/test/java/JavaTestTest.java index d9ceca1c2..03ddd3b2c 100644 --- a/bundles/org.openhab.core.test/src/test/java/org/openhab/core/test/java/JavaTestTest.java +++ b/bundles/org.openhab.core.test/src/test/java/org/openhab/core/test/java/JavaTestTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.test.java; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Testing the test. Test suite for the JavaTest base test class. @@ -27,7 +27,7 @@ public class JavaTestTest { private JavaTest javaTest; - @Before + @BeforeEach public void setup() { javaTest = new JavaTest(); } @@ -49,10 +49,10 @@ public class JavaTestTest { verify(afterLastCall, times(1)).run(); } - @Test(expected = NullPointerException.class) + @Test public void waitForAssertShouldNotCatchNPE() { - javaTest.waitForAssert(() -> { - getObject().getClass(); + assertThrows(NullPointerException.class, () -> { + javaTest.waitForAssert(() -> getObject().getClass()); }); } diff --git a/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/Example.java b/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/Example.java index 951901834..30393a13a 100644 --- a/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/Example.java +++ b/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/Example.java @@ -14,7 +14,7 @@ package org.openhab.core.thing.xml.internal; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * The {@link Example} test case is a usage example how the according {@code ThingType} parser diff --git a/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/XmlHelperTest.java b/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/XmlHelperTest.java index 216ba4ba3..641b088a4 100644 --- a/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/XmlHelperTest.java +++ b/bundles/org.openhab.core.thing.xml/src/test/java/org/openhab/core/thing/xml/internal/XmlHelperTest.java @@ -13,9 +13,9 @@ package org.openhab.core.thing.xml.internal; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelGroupUIDTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelGroupUIDTest.java index defdd3809..276d3e276 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelGroupUIDTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelGroupUIDTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.thing; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for class {@link ChannelGroupUID}. @@ -30,14 +30,14 @@ public class ChannelGroupUIDTest { private static final ThingUID THING_UID = new ThingUID(BINDING_ID, THING_TYPE_ID, THING_ID); - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidCharacters() { - new ChannelGroupUID(THING_UID, "id_with_invalidchar%"); + assertThrows(IllegalArgumentException.class, () -> new ChannelGroupUID(THING_UID, "id_with_invalidchar%")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNotEnoughNumberOfSegments() { - new ChannelUID("binding:thing-type:group"); + assertThrows(IllegalArgumentException.class, () -> new ChannelUID("binding:thing-type:group")); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelTest.java index 1b77a03a0..f2bf834ae 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.thing; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test cases for the {@link Channel} class. diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelUIDTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelUIDTest.java index 45807a644..c25c1913e 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelUIDTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ChannelUIDTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.thing; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for class {@link ChannelUID}. @@ -31,19 +31,20 @@ public class ChannelUIDTest { private static final String CHANNEL_ID = "id"; private static final ThingUID THING_UID = new ThingUID(BINDING_ID, THING_TYPE_ID, THING_ID); - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidCharacters() { - new ChannelUID(THING_UID, "id_with_invalidchar%"); + assertThrows(IllegalArgumentException.class, () -> new ChannelUID(THING_UID, "id_with_invalidchar%")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNotEnoughNumberOfSegments() { - new ChannelUID("binding:thing-type:group#id"); + assertThrows(IllegalArgumentException.class, () -> new ChannelUID("binding:thing-type:group#id")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMultipleChannelGroupSeparators() { - new ChannelUID("binding:thing-type:thing:group#id#what_ever"); + assertThrows(IllegalArgumentException.class, + () -> new ChannelUID("binding:thing-type:thing:group#id#what_ever")); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java index a737d0698..9362a6205 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.thing; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Stefan Triller - Initial contribution diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/UIDTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/UIDTest.java index f59af1ee8..d1fb32145 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/UIDTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/UIDTest.java @@ -12,16 +12,18 @@ */ package org.openhab.core.thing; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; /** * @author Alex Tugarev - Initial contribution */ public class UIDTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidCharacters() { - new ThingUID("binding:type:id_with_invalidchar#"); + assertThrows(IllegalArgumentException.class, () -> new ThingUID("binding:type:id_with_invalidchar#")); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ChannelBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ChannelBuilderTest.java index 54b1c7b02..37851a339 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ChannelBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ChannelBuilderTest.java @@ -13,16 +13,16 @@ package org.openhab.core.thing.binding.builder; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import static org.openhab.core.thing.DefaultSystemChannelTypeProvider.SYSTEM_OUTDOOR_TEMPERATURE; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; @@ -53,7 +53,7 @@ public class ChannelBuilderTest { private ChannelBuilder builder; private Channel channel; - @Before + @BeforeEach public void setup() { ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("bindingId", "thingTypeId"), "thingLabel") .build(); diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java index e760eb95c..6c2d926e7 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java @@ -13,16 +13,17 @@ package org.openhab.core.thing.binding.builder; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -51,7 +52,7 @@ public class ThingBuilderTest { }; private ThingBuilder thingBuilder; - @Before + @BeforeEach public void setup() { thingBuilder = ThingBuilder.create(THING_TYPE_UID, THING_UID); } @@ -68,26 +69,27 @@ public class ThingBuilderTest { assertThat(bridgeBuilder.build(), is(instanceOf(BridgeImpl.class))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testWithChannelDuplicates() { thingBuilder.withChannel(ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build()); - thingBuilder.withChannel(ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build()); + assertThrows(IllegalArgumentException.class, + () -> thingBuilder.withChannel(ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testWithChannelsDuplicatesCollections() { - thingBuilder.withChannels(Arrays.asList( // + assertThrows(IllegalArgumentException.class, () -> thingBuilder.withChannels(Arrays.asList( // + ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build(), // + ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build()))); + } + + @Test + public void testWithChannelsDuplicatesVararg() { + assertThrows(IllegalArgumentException.class, () -> thingBuilder.withChannels( // ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build(), // ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build())); } - @Test(expected = IllegalArgumentException.class) - public void testWithChannelsDuplicatesVararg() { - thingBuilder.withChannels( // - ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build(), // - ChannelBuilder.create(new ChannelUID(THING_UID, "channel1")).build()); - } - @Test public void testWithoutChannel() { thingBuilder.withChannels( // @@ -108,10 +110,10 @@ public class ThingBuilderTest { assertThat(thingBuilder.build().getChannels(), hasSize(2)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testWithChannelWrongThing() { - thingBuilder.withChannel( - ChannelBuilder.create(new ChannelUID(new ThingUID(THING_TYPE_UID, "wrong"), "channel1")).build()); + assertThrows(IllegalArgumentException.class, () -> thingBuilder.withChannel( + ChannelBuilder.create(new ChannelUID(new ThingUID(THING_TYPE_UID, "wrong"), "channel1")).build())); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingStatusInfoBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingStatusInfoBuilderTest.java index 3c92e0116..af29a588f 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingStatusInfoBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingStatusInfoBuilderTest.java @@ -13,10 +13,10 @@ package org.openhab.core.thing.binding.builder; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusInfo; @@ -30,7 +30,7 @@ public class ThingStatusInfoBuilderTest { private ThingStatusInfoBuilder builder; - @Before + @BeforeEach public void setup() { builder = ThingStatusInfoBuilder.create(ThingStatus.ONLINE); } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ChannelDTOTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ChannelDTOTest.java index a68462bbc..e3a0404cd 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ChannelDTOTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ChannelDTOTest.java @@ -13,14 +13,14 @@ package org.openhab.core.thing.dto; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import java.util.Collections; import java.util.Map; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.thing.Channel; diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ThingDTOTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ThingDTOTest.java index 8e7b44cd2..ce8915f4f 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ThingDTOTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/dto/ThingDTOTest.java @@ -13,14 +13,14 @@ package org.openhab.core.thing.dto; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import java.util.Collections; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.thing.Bridge; diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/firmware/FirmwareEventFactoryTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/firmware/FirmwareEventFactoryTest.java index f9e3507b0..fc40fde68 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/firmware/FirmwareEventFactoryTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/firmware/FirmwareEventFactoryTest.java @@ -13,14 +13,15 @@ package org.openhab.core.thing.firmware; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.test.java.JavaTest; import org.openhab.core.thing.ThingTypeUID; @@ -38,7 +39,7 @@ public class FirmwareEventFactoryTest extends JavaTest { private FirmwareEventFactory eventFactory; - @Before + @BeforeEach public void setUp() { eventFactory = new FirmwareEventFactory(); } @@ -50,24 +51,27 @@ public class FirmwareEventFactoryTest extends JavaTest { FirmwareUpdateProgressInfoEvent.TYPE, FirmwareUpdateResultInfoEvent.TYPE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateEventForUnknownType() throws Exception { - eventFactory.createEventByType("unknownType", "topic", "somePayload", "Source"); + assertThrows(IllegalArgumentException.class, + () -> eventFactory.createEventByType("unknownType", "topic", "somePayload", "Source")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullStatusInfo() { - FirmwareEventFactory.createFirmwareStatusInfoEvent(null); + assertThrows(IllegalArgumentException.class, () -> FirmwareEventFactory.createFirmwareStatusInfoEvent(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullUpdateProgressInfo() { - FirmwareEventFactory.createFirmwareUpdateProgressInfoEvent(null); + assertThrows(IllegalArgumentException.class, + () -> FirmwareEventFactory.createFirmwareUpdateProgressInfoEvent(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullUpdateResultInfo() { - FirmwareEventFactory.createFirmwareUpdateResultInfoEvent(null); + assertThrows(IllegalArgumentException.class, + () -> FirmwareEventFactory.createFirmwareUpdateResultInfoEvent(null)); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/AutoUpdateManagerTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/AutoUpdateManagerTest.java index 867bdc5da..f4974d8da 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/AutoUpdateManagerTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/AutoUpdateManagerTest.java @@ -12,10 +12,9 @@ */ package org.openhab.core.thing.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.Collections; import java.util.HashMap; @@ -23,10 +22,14 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.events.Event; import org.openhab.core.events.EventPublisher; import org.openhab.core.items.GenericItem; @@ -55,6 +58,8 @@ import org.openhab.core.thing.type.ChannelTypeRegistry; * @author Simon Kaufmann - Initial contribution * @author Kai Kreuzer - added tests with multiple links */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class AutoUpdateManagerTest { private static final ThingUID THING_UID_ONLINE = new ThingUID("test::mock-online"); @@ -82,9 +87,8 @@ public class AutoUpdateManagerTest { private AutoUpdateManager aum; private final Map policies = new HashMap<>(); - @Before + @BeforeEach public void setup() { - initMocks(this); event = ItemEventFactory.createCommandEvent("test", new StringType("AFTER")); item = new StringItem("test"); item.setState(new StringType("BEFORE")); diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ChannelItemProviderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ChannelItemProviderTest.java index 41792c3b7..0904d6813 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ChannelItemProviderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ChannelItemProviderTest.java @@ -14,7 +14,6 @@ package org.openhab.core.thing.internal; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -25,9 +24,13 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNull; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.common.registry.ProviderChangeListener; import org.openhab.core.i18n.LocaleProvider; import org.openhab.core.items.Item; @@ -49,6 +52,8 @@ import org.openhab.core.thing.type.ChannelTypeRegistry; /** * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class ChannelItemProviderTest { private static final ChannelUID CHANNEL_UID = new ChannelUID("test:test:test:test"); @@ -70,10 +75,8 @@ public class ChannelItemProviderTest { private ChannelItemProvider provider; - @Before + @BeforeEach public void setup() { - initMocks(this); - provider = createProvider(); Map props = new HashMap<>(); diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingImplTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingImplTest.java index a6ccb50af..30ab21f1b 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingImplTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingImplTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.thing.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingManagerImplTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingManagerImplTest.java index 4ff288cc4..7bca93e0b 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingManagerImplTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/ThingManagerImplTest.java @@ -12,15 +12,18 @@ */ package org.openhab.core.thing.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.common.SafeCaller; import org.openhab.core.config.core.ConfigDescriptionRegistry; import org.openhab.core.config.core.validation.ConfigDescriptionValidator; @@ -43,6 +46,8 @@ import org.osgi.framework.Bundle; /** * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) @NonNullByDefault public class ThingManagerImplTest { @@ -66,10 +71,8 @@ public class ThingManagerImplTest { // This class is final so it cannot be mocked private final ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService = new ThingStatusInfoI18nLocalizationService(); - @Before + @BeforeEach public void setup() { - initMocks(this); - when(bundleMock.getSymbolicName()).thenReturn("test"); when(bundleResolverMock.resolveBundle(any())).thenReturn(bundleMock); when(thingMock.getUID()).thenReturn(new ThingUID("test", "thing")); diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/firmware/ProgressCallbackTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/firmware/ProgressCallbackTest.java index 754b4dbac..3951e664c 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/firmware/ProgressCallbackTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/firmware/ProgressCallbackTest.java @@ -13,7 +13,8 @@ package org.openhab.core.thing.internal.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -22,8 +23,8 @@ import java.util.List; import java.util.Locale; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.events.EventPublisher; import org.openhab.core.i18n.TranslationProvider; @@ -63,7 +64,7 @@ public final class ProgressCallbackTest { private String cancelMessageKey = "update-canceled"; private String usedMessagedKey; - @Before + @BeforeEach public void setUp() { ThingTypeUID thingType = new ThingTypeUID("thing:type"); expectedThingUID = new ThingUID(thingType, "thingid"); @@ -103,31 +104,31 @@ public final class ProgressCallbackTest { expectedThingUID, expectedFirmware, null); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatUpdateThrowsIllegalStateExceptionIfUpdateIsFinished() { sut.defineSequence(ProgressStep.DOWNLOADING); sut.next(); sut.success(); assertThatUpdateResultEventIsValid(postedEvents.get(1), null, FirmwareUpdateResult.SUCCESS); - sut.update(100); + assertThrows(IllegalStateException.class, () -> sut.update(100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatDefineSequenceThrowsIllegalArguumentExceptionIfSequenceIsEmpty() { - sut.defineSequence(); + assertThrows(IllegalArgumentException.class, () -> sut.defineSequence()); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatSuccessThrowsIllegalStateExceptionIfProgressIsNotAt100Percent() { sut.update(99); - sut.success(); + assertThrows(IllegalStateException.class, () -> sut.success()); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatSuccessThrowsIllegalStateExceptionIfLastProgressStepIsNotReached() { sut.defineSequence(ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING); sut.next(); - sut.success(); + assertThrows(IllegalStateException.class, () -> sut.success()); } @Test @@ -138,20 +139,20 @@ public final class ProgressCallbackTest { sut.success(); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUpdateThrowsIllegalArgumentExceptionIfProgressSmaller0() { - sut.update(-1); + assertThrows(IllegalArgumentException.class, () -> sut.update(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUpdateThrowsIllegalArgumentExceptionIfProgressGreater100() { - sut.update(101); + assertThrows(IllegalArgumentException.class, () -> sut.update(101)); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatUpdateThrowsIllegalArgumentExceptionIfNewProgressIsSmallerThanOldProgress() { sut.update(10); - sut.update(9); + assertThrows(IllegalArgumentException.class, () -> sut.update(9)); } @Test @@ -239,14 +240,14 @@ public final class ProgressCallbackTest { assertThat(postedEvents.size(), is(8)); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatCancelThrowsIllegalStateExceptionIfUpdateIsFinished() { sut.defineSequence(ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING); sut.next(); sut.next(); sut.success(); assertThatUpdateResultEventIsValid(postedEvents.get(2), null, FirmwareUpdateResult.SUCCESS); - sut.canceled(); + assertThrows(IllegalStateException.class, () -> sut.canceled()); } @Test @@ -287,9 +288,9 @@ public final class ProgressCallbackTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatPendingThrowsIllegalArgumentExceptionIfStepSequenceIsNotDefinedAndNoProgressWasSet() { - sut.pending(); + assertThrows(IllegalArgumentException.class, () -> sut.pending()); } @Test @@ -305,40 +306,40 @@ public final class ProgressCallbackTest { assertThatUpdateResultEventIsValid(postedEvents.get(0), cancelMessageKey, FirmwareUpdateResult.CANCELED); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatFailedThrowsIllegalStateExceptionIfItsCalledMultipleTimes() { sut.failed("DummyMessageKey"); - sut.failed("DummyMessageKey"); + assertThrows(IllegalStateException.class, () -> sut.failed("DummyMessageKey")); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatFailedThrowsIllegalStateExceptionForSuccessfulUpdates() { sut.update(100); sut.success(); assertThatUpdateResultEventIsValid(postedEvents.get(1), null, FirmwareUpdateResult.SUCCESS); - sut.failed("DummyMessageKey"); + assertThrows(IllegalStateException.class, () -> sut.failed("DummyMessageKey")); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatSuccessThrowsIllegalStateExceptionIfItsCalledMultipleTimes() { sut.update(100); sut.success(); assertThatUpdateResultEventIsValid(postedEvents.get(1), null, FirmwareUpdateResult.SUCCESS); - sut.success(); + assertThrows(IllegalStateException.class, () -> sut.success()); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatPendingThrowsIllegalStateExceptionIfUpdateFailed() { sut.defineSequence(ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING); sut.failed("DummyMessageKey"); - sut.pending(); + assertThrows(IllegalStateException.class, () -> sut.pending()); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatNextThrowsIllegalStateExceptionIfUpdateIsNotPendingAndNoFurtherStepsAvailable() { sut.defineSequence(ProgressStep.DOWNLOADING); sut.next(); - sut.next(); + assertThrows(IllegalStateException.class, () -> sut.next()); } @Test @@ -350,13 +351,13 @@ public final class ProgressCallbackTest { assertThat(sut.getCurrentStep(), is(ProgressStep.DOWNLOADING)); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatPendingThrowsIllegalStateExceptionIfUpdateWasSuccessful() { sut.defineSequence(ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING); sut.next(); sut.next(); sut.success(); - sut.pending(); + assertThrows(IllegalStateException.class, () -> sut.pending()); } private void assertThatProgressInfoEventIsValid(Event event, ProgressStep expectedStep, boolean expectedPending, diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonOnOffSwitchProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonOnOffSwitchProfileTest.java index c2844c87d..b9c0277f5 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonOnOffSwitchProfileTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonOnOffSwitchProfileTest.java @@ -15,8 +15,8 @@ package org.openhab.core.thing.internal.profiles; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.library.types.OnOffType; import org.openhab.core.thing.CommonTriggerEvents; @@ -31,10 +31,9 @@ import org.openhab.core.types.Command; */ public class RawButtonOnOffSwitchProfileTest { - @Mock - private ProfileCallback mockCallback; + private @Mock ProfileCallback mockCallback; - @Before + @BeforeEach public void setup() { mockCallback = mock(ProfileCallback.class); } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonToggleSwitchProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonToggleSwitchProfileTest.java index 18c7cf8d8..9b42c08fe 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonToggleSwitchProfileTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/RawButtonToggleSwitchProfileTest.java @@ -15,8 +15,8 @@ package org.openhab.core.thing.internal.profiles; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.OnOffType; @@ -34,10 +34,9 @@ import org.openhab.core.types.UnDefType; */ public class RawButtonToggleSwitchProfileTest { - @Mock - private ProfileCallback mockCallback; + private @Mock ProfileCallback mockCallback; - @Before + @BeforeEach public void setup() { mockCallback = mock(ProfileCallback.class); } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemDefaultProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemDefaultProfileTest.java index efe4332d1..a94246c77 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemDefaultProfileTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemDefaultProfileTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.thing.internal.profiles; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Before; -import org.junit.Test; +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.library.types.OnOffType; import org.openhab.core.thing.profiles.ProfileCallback; @@ -26,15 +26,10 @@ import org.openhab.core.thing.profiles.ProfileCallback; * * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class SystemDefaultProfileTest { - @Mock - private ProfileCallback mockCallback; - - @Before - public void setup() { - initMocks(this); - } + private @Mock ProfileCallback mockCallback; @Test public void testOnCommand() { diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemFollowProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemFollowProfileTest.java index a7caee9d1..0ba4c3020 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemFollowProfileTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemFollowProfileTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.thing.internal.profiles; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; -import org.junit.Before; -import org.junit.Test; +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.library.types.OnOffType; import org.openhab.core.thing.profiles.ProfileCallback; @@ -26,15 +26,10 @@ import org.openhab.core.thing.profiles.ProfileCallback; * * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class SystemFollowProfileTest { - @Mock - private ProfileCallback mockCallback; - - @Before - public void setup() { - initMocks(this); - } + private @Mock ProfileCallback mockCallback; @Test public void testOnCommand() { diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfileTest.java index 233c180dd..673b827c2 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfileTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfileTest.java @@ -13,15 +13,16 @@ package org.openhab.core.thing.internal.profiles; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; import javax.measure.Unit; import javax.measure.quantity.Temperature; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.types.DecimalType; @@ -40,7 +41,7 @@ import org.openhab.core.types.State; */ public class SystemOffsetProfileTest { - @Before + @BeforeEach public void setup() { // initialize parser with ImperialUnits, otherwise units like °F are unknown @SuppressWarnings("unused") diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TimestampProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TimestampProfileTest.java index fd142789a..ceec41635 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TimestampProfileTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TimestampProfileTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.thing.internal.profiles; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelGroupTypeBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelGroupTypeBuilderTest.java index 6d60601de..3bf81acb0 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelGroupTypeBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelGroupTypeBuilderTest.java @@ -12,14 +12,14 @@ */ package org.openhab.core.thing.type; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests the {@link ChannelGroupTypeBuilder}. @@ -36,15 +36,16 @@ public class ChannelGroupTypeBuilderTest { private ChannelGroupTypeBuilder builder; - @Before + @BeforeEach public void setup() { // set up a valid basic ChannelGroupTypeBuilder builder = ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, LABEL); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenLabelIsBlankForStateShouldFail() { - ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, ""); + assertThrows(IllegalArgumentException.class, + () -> ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, "")); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelTypeBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelTypeBuilderTest.java index c52e6f275..b4b03ef64 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelTypeBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ChannelTypeBuilderTest.java @@ -13,8 +13,9 @@ package org.openhab.core.thing.type; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigDecimal; import java.net.URI; @@ -22,8 +23,8 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.thing.CommonTriggerEvents; import org.openhab.core.types.EventDescription; import org.openhab.core.types.EventOption; @@ -57,7 +58,7 @@ public class ChannelTypeBuilderTest { private StateChannelTypeBuilder stateBuilder; private TriggerChannelTypeBuilder triggerBuilder; - @Before + @BeforeEach public void setup() throws URISyntaxException { configDescriptionUri = new URI("config:dummy"); // set up a valid basic ChannelTypeBuilder @@ -65,19 +66,19 @@ public class ChannelTypeBuilderTest { triggerBuilder = ChannelTypeBuilder.trigger(CHANNEL_TYPE_UID, LABEL); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenLabelIsBlankForStateShouldFail() { - ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "", ITEM_TYPE); + assertThrows(IllegalArgumentException.class, () -> ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "", ITEM_TYPE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenItemTypeIsBlankForStateShouldFail() { - ChannelTypeBuilder.state(CHANNEL_TYPE_UID, LABEL, ""); + assertThrows(IllegalArgumentException.class, () -> ChannelTypeBuilder.state(CHANNEL_TYPE_UID, LABEL, "")); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenLabelIsBlankForTriggerShouldFail() { - ChannelTypeBuilder.trigger(CHANNEL_TYPE_UID, ""); + assertThrows(IllegalArgumentException.class, () -> ChannelTypeBuilder.trigger(CHANNEL_TYPE_UID, "")); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java index fceb174b9..69a226ef2 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java @@ -13,8 +13,9 @@ package org.openhab.core.thing.type; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import java.net.URI; @@ -25,8 +26,8 @@ import java.util.List; import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.thing.ThingTypeUID; /** @@ -47,30 +48,31 @@ public class ThingTypeBuilderTest { private @NonNullByDefault({}) ThingTypeBuilder builder; - @Before + @BeforeEach public void setup() { // set up a valid basic ThingTypeBuilder builder = ThingTypeBuilder.instance(BINDING_ID, THING_TYPE_ID, LABEL); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenThingTypeIdAndBindingIdBlankShouldFail() { - ThingTypeBuilder.instance("", "", LABEL).build(); + assertThrows(IllegalArgumentException.class, () -> ThingTypeBuilder.instance("", "", LABEL).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenThingTypeIdBlankShouldFail() { - ThingTypeBuilder.instance(BINDING_ID, "", LABEL).build(); + assertThrows(IllegalArgumentException.class, () -> ThingTypeBuilder.instance(BINDING_ID, "", LABEL).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenBindingIdBlankShouldFail() { - ThingTypeBuilder.instance("", THING_TYPE_ID, LABEL).build(); + assertThrows(IllegalArgumentException.class, () -> ThingTypeBuilder.instance("", THING_TYPE_ID, LABEL).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void whenLabelBlankShouldFail() { - ThingTypeBuilder.instance(THING_TYPE_ID, BINDING_ID, "").build(); + assertThrows(IllegalArgumentException.class, + () -> ThingTypeBuilder.instance(THING_TYPE_ID, BINDING_ID, "").build()); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHandlerHelperTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHandlerHelperTest.java index cbd344ee7..918230862 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHandlerHelperTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHandlerHelperTest.java @@ -13,17 +13,16 @@ package org.openhab.core.thing.util; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder.create; import static org.openhab.core.thing.util.ThingHandlerHelper.isHandlerInitialized; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +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.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingTypeUID; @@ -37,15 +36,14 @@ import org.openhab.core.thing.binding.builder.ThingBuilder; * @author Simon Kaufmann - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java */ +@ExtendWith(MockitoExtension.class) public class ThingHandlerHelperTest { private Thing thing; private @Mock ThingHandler thingHandler; - public @Rule MockitoRule rule = MockitoJUnit.rule(); - - @Before + @BeforeEach public void setup() { thing = ThingBuilder.create(new ThingTypeUID("test:test"), new ThingUID("test:test:test")).build(); } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHelperTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHelperTest.java index 005285a11..1eceda674 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHelperTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/util/ThingHelperTest.java @@ -14,11 +14,11 @@ package org.openhab.core.thing.util; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.Configuration; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -124,7 +124,7 @@ public class ThingHelperTest { assertFalse(ThingHelper.equals(thingA, thingB)); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatNoDuplicateChannelsCanBeAdded() { ThingTypeUID thingTypeUID = new ThingTypeUID("test", "test"); ThingUID thingUID = new ThingUID(thingTypeUID, "test"); @@ -134,10 +134,10 @@ public class ThingHelperTest { ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build()) .build(); - ThingHelper - .addChannelsToThing(thing, + assertThrows(IllegalArgumentException.class, + () -> ThingHelper.addChannelsToThing(thing, Stream.of(ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build(), ChannelBuilder.create(new ChannelUID(thingUID, "channel3"), "").build()) - .collect(toList())); + .collect(toList()))); } } diff --git a/bundles/org.openhab.core.transform/src/test/java/org/openhab/core/transform/actions/TransformationTest.java b/bundles/org.openhab.core.transform/src/test/java/org/openhab/core/transform/actions/TransformationTest.java index 7f0dad9d7..c2d7d27fb 100644 --- a/bundles/org.openhab.core.transform/src/test/java/org/openhab/core/transform/actions/TransformationTest.java +++ b/bundles/org.openhab.core.transform/src/test/java/org/openhab/core/transform/actions/TransformationTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.transform.actions; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.transform.TransformationException; /** diff --git a/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/AbstractResourceIconProviderTest.java b/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/AbstractResourceIconProviderTest.java index c6476513f..cfa11c0ad 100644 --- a/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/AbstractResourceIconProviderTest.java +++ b/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/AbstractResourceIconProviderTest.java @@ -13,8 +13,8 @@ package org.openhab.core.ui.icon; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -24,9 +24,11 @@ import java.util.Collections; import java.util.Locale; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +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.i18n.TranslationProvider; import org.openhab.core.ui.icon.IconSet.Format; @@ -36,16 +38,15 @@ import org.openhab.core.ui.icon.IconSet.Format; * @author Kai Kreuzer - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java */ +@ExtendWith(MockitoExtension.class) public class AbstractResourceIconProviderTest { private IconProvider provider; private @Mock TranslationProvider i18nProviderMock; - @Before + @BeforeEach public void setUp() { - initMocks(this); - provider = new AbstractResourceIconProvider(i18nProviderMock) { @Override protected InputStream getResource(String iconset, String resourceName) { diff --git a/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java b/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java index facb9a74d..afc44127b 100644 --- a/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java +++ b/bundles/org.openhab.core.ui.icon/src/test/java/org/openhab/core/ui/icon/internal/IconServletTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.ui.icon.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static org.openhab.core.ui.icon.internal.IconServlet.*; @@ -27,12 +27,11 @@ import javax.servlet.WriteListener; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +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.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.ui.icon.IconProvider; import org.openhab.core.ui.icon.IconSet.Format; import org.osgi.service.http.HttpContext; @@ -44,6 +43,7 @@ import org.osgi.service.http.HttpService; * @author Kai Kreuzer - Initial contribution * @author Wouter Born - Migrate tests from Groovy to Java and use Mockito */ +@ExtendWith(MockitoExtension.class) public class IconServletTest { private class ByteArrayServletOutputStream extends ServletOutputStream { @@ -85,9 +85,7 @@ public class IconServletTest { private @Mock IconProvider provider1Mock; private @Mock IconProvider provider2Mock; - public @Rule MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Before + @BeforeEach public void before() throws IOException { servlet = new IconServlet(httpServiceMock, httpContextMock); responseOutputStream.reset(); diff --git a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java index 4d5edec69..3bba76da4 100644 --- a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java +++ b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/items/ItemUIRegistryImplTest.java @@ -13,11 +13,11 @@ package org.openhab.core.ui.internal.items; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.text.DecimalFormatSymbols; import java.util.ArrayList; @@ -27,9 +27,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.emf.common.util.BasicEList; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.i18n.UnitProvider; import org.openhab.core.items.GroupItem; import org.openhab.core.items.Item; @@ -80,6 +84,8 @@ import org.openhab.core.ui.items.ItemUIProvider; /** * @author Kai Kreuzer - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class ItemUIRegistryImplTest { // we need to get the decimal separator of the default locale for our tests @@ -89,16 +95,12 @@ public class ItemUIRegistryImplTest { private ItemUIRegistryImpl uiRegistry; private @Mock ItemRegistry registry; - private @Mock Widget widget; - private @Mock Item item; - private @Mock UnitProvider unitProvider; - @Before + @BeforeEach public void setup() throws Exception { - initMocks(this); uiRegistry = new ItemUIRegistryImpl(); uiRegistry.setItemRegistry(registry); @@ -525,7 +527,6 @@ public class ItemUIRegistryImplTest { when(widget.getLabel()).thenReturn(testLabel); when(widget.eClass()).thenReturn(SitemapFactory.eINSTANCE.createText().eClass()); when(registry.getItem(ITEM_NAME)).thenThrow(new ItemNotFoundException(ITEM_NAME)); - when(item.getState()).thenReturn(new StringType("State")); String label = uiRegistry.getLabel(widget); assertEquals("Label [-]", label); } diff --git a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/proxy/ProxyServletServiceTest.java b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/proxy/ProxyServletServiceTest.java index 477e01280..545fe276c 100644 --- a/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/proxy/ProxyServletServiceTest.java +++ b/bundles/org.openhab.core.ui/src/test/java/org/openhab/core/ui/internal/proxy/ProxyServletServiceTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.ui.internal.proxy; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -25,8 +25,8 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.util.B64Code; import org.eclipse.jetty.util.StringUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.StringType; import org.openhab.core.model.core.ModelRepository; @@ -73,7 +73,7 @@ public class ProxyServletServiceTest { private Image imageWidget; private Video videoWidget; - @Before + @BeforeEach public void setUp() { service = new ProxyServletService(); diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java index 8906ef00a..ca1f2c563 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/STTExceptionTest.java @@ -12,8 +12,9 @@ */ package org.openhab.core.voice; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; /** * Test general purpose STT exception @@ -28,7 +29,7 @@ public class STTExceptionTest { @Test public void testConstructor0() { STTException ttsException = new STTException(); - Assert.assertNotNull("STTException() constructor failed", ttsException); + assertNotNull(ttsException, "STTException() constructor failed"); } /** @@ -37,7 +38,7 @@ public class STTExceptionTest { @Test public void testConstructor1() { STTException ttsException = new STTException("Message", new Throwable()); - Assert.assertNotNull("STTException(String, Throwable) constructor failed", ttsException); + assertNotNull(ttsException, "STTException(String, Throwable) constructor failed"); } /** @@ -46,7 +47,7 @@ public class STTExceptionTest { @Test public void testConstructor2() { STTException ttsException = new STTException("Message"); - Assert.assertNotNull("STTException(String) constructor failed", ttsException); + assertNotNull(ttsException, "STTException(String) constructor failed"); } /** @@ -55,6 +56,6 @@ public class STTExceptionTest { @Test public void testConstructor3() { STTException ttsException = new STTException(new Throwable()); - Assert.assertNotNull("STTException(Throwable) constructor failed", ttsException); + assertNotNull(ttsException, "STTException(Throwable) constructor failed"); } } diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java index 3af707e1e..0194060d8 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionErrorEventTest.java @@ -12,8 +12,9 @@ */ package org.openhab.core.voice; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; /** * Test SpeechRecognitionErrorEvent event @@ -28,7 +29,7 @@ public class SpeechRecognitionErrorEventTest { @Test public void testConstructor() { SpeechRecognitionErrorEvent sRE = new SpeechRecognitionErrorEvent("Message"); - Assert.assertNotNull("SpeechRecognitionErrorEvent(String) constructor failed", sRE); + assertNotNull(sRE, "SpeechRecognitionErrorEvent(String) constructor failed"); } /** @@ -37,6 +38,6 @@ public class SpeechRecognitionErrorEventTest { @Test public void getMessageTest() { SpeechRecognitionErrorEvent sRE = new SpeechRecognitionErrorEvent("Message"); - Assert.assertEquals("SpeechRecognitionErrorEvent.getMessage() method failed", "Message", sRE.getMessage()); + assertEquals("Message", sRE.getMessage(), "SpeechRecognitionErrorEvent.getMessage() method failed"); } } diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java index 1c8ddb5dd..5b8989cf6 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/SpeechRecognitionEventTest.java @@ -12,8 +12,9 @@ */ package org.openhab.core.voice; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; /** * Test SpeechRecognitionEvent event @@ -28,7 +29,7 @@ public class SpeechRecognitionEventTest { @Test public void testConstructor() { SpeechRecognitionEvent sRE = new SpeechRecognitionEvent("Message", 0.5f); - Assert.assertNotNull("SpeechRecognitionEvent(String, float) constructor failed", sRE); + assertNotNull(sRE, "SpeechRecognitionEvent(String, float) constructor failed"); } /** @@ -37,7 +38,7 @@ public class SpeechRecognitionEventTest { @Test public void getTranscriptTest() { SpeechRecognitionEvent sRE = new SpeechRecognitionEvent("Message", 0.5f); - Assert.assertEquals("SpeechRecognitionEvent.getTranscript() method failed", "Message", sRE.getTranscript()); + assertEquals("Message", sRE.getTranscript(), "SpeechRecognitionEvent.getTranscript() method failed"); } /** @@ -46,7 +47,7 @@ public class SpeechRecognitionEventTest { @Test public void getConfidenceTest() { SpeechRecognitionEvent sRE = new SpeechRecognitionEvent("Message", 0.5f); - Assert.assertEquals("SpeechRecognitionEvent.getConfidence() method failed", (double) 0.5f, - (double) sRE.getConfidence(), (double) 0.001f); + assertEquals((double) 0.5f, (double) sRE.getConfidence(), (double) 0.001f, + "SpeechRecognitionEvent.getConfidence() method failed"); } } diff --git a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java index 7f8069d6c..337451dea 100644 --- a/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java +++ b/bundles/org.openhab.core.voice/src/test/java/org/openhab/core/voice/TTSExceptionTest.java @@ -12,8 +12,9 @@ */ package org.openhab.core.voice; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; /** * Test general purpose TTS exception @@ -28,7 +29,7 @@ public class TTSExceptionTest { @Test public void testConstructor0() { TTSException ttsException = new TTSException(); - Assert.assertNotNull("TTSException() constructor failed", ttsException); + assertNotNull(ttsException, "TTSException() constructor failed"); } /** @@ -37,7 +38,7 @@ public class TTSExceptionTest { @Test public void testConstructor1() { TTSException ttsException = new TTSException("Message", new Throwable()); - Assert.assertNotNull("TTSException(String, Throwable) constructor failed", ttsException); + assertNotNull(ttsException, "TTSException(String, Throwable) constructor failed"); } /** @@ -46,7 +47,7 @@ public class TTSExceptionTest { @Test public void testConstructor2() { TTSException ttsException = new TTSException("Message"); - Assert.assertNotNull("TTSException(String) constructor failed", ttsException); + assertNotNull(ttsException, "TTSException(String) constructor failed"); } /** @@ -55,6 +56,6 @@ public class TTSExceptionTest { @Test public void testConstructor3() { TTSException ttsException = new TTSException(new Throwable()); - Assert.assertNotNull("TTSException(Throwable) constructor failed", ttsException); + assertNotNull(ttsException, "TTSException(Throwable) constructor failed"); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseTest.java index a9557067b..37ef53132 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.auth.client.oauth2; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.time.LocalDateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Gary Tse - Initial contribution @@ -34,7 +34,7 @@ public class AccessTokenResponseTest { // token only has a life time of 10 seconds token.setExpiresIn(10); - assertTrue("Token should have been expired", token.isExpired(LocalDateTime.now(), 0)); + assertTrue(token.isExpired(LocalDateTime.now(), 0), "Token should have been expired"); } @Test @@ -48,7 +48,7 @@ public class AccessTokenResponseTest { // token only has a life time of 30 seconds token.setExpiresIn(30); - assertTrue("Token should have been expired due to buffer", token.isExpired(LocalDateTime.now(), 15)); + assertTrue(token.isExpired(LocalDateTime.now(), 15), "Token should have been expired due to buffer"); } @Test @@ -60,7 +60,7 @@ public class AccessTokenResponseTest { // token has life time of 1 minute token.setExpiresIn(60); - assertFalse("Token should not be expired", token.isExpired(LocalDateTime.now(), 0)); + assertFalse(token.isExpired(LocalDateTime.now(), 0), "Token should not be expired"); } @Test @@ -74,6 +74,6 @@ public class AccessTokenResponseTest { // token has a life time of 60 seconds token.setExpiresIn(60); - assertTrue("Token should have been expired due to buffer", !token.isExpired(LocalDateTime.now(), 10)); + assertTrue(!token.isExpired(LocalDateTime.now(), 10), "Token should have been expired due to buffer"); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java index a0ea65742..cb36f4dd2 100755 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.cache; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -23,8 +23,8 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test class for the {@link ExpiringCacheMap} class. @@ -51,14 +51,14 @@ public class ExpiringCacheMapTest { private ExpiringCacheMap subject; - @Before + @BeforeEach public void setUp() { subject = new ExpiringCacheMap<>(CACHE_EXPIRY); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPutIllegalArgumentException3() throws IllegalArgumentException { - subject.put(null, CACHE_ACTION); + assertThrows(IllegalArgumentException.class, () -> subject.put(null, CACHE_ACTION)); } @Test @@ -87,9 +87,9 @@ public class ExpiringCacheMapTest { assertNotEquals(RESPONSE_2, response); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPutValueIllegalArgumentException1() throws IllegalArgumentException { - subject.putValue("KEY_NOT_FOUND", "test"); + assertThrows(IllegalArgumentException.class, () -> subject.putValue("KEY_NOT_FOUND", "test")); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheTest.java index 94677ed56..2b8e293d6 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheTest.java @@ -12,15 +12,15 @@ */ package org.openhab.core.cache; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.nio.charset.StandardCharsets; import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test class for the {@link ExpiringCache} class. @@ -37,7 +37,7 @@ public class ExpiringCacheTest { private ExpiringCache subject; - @Before + @BeforeEach public void setUp() { subject = new ExpiringCache<>(CACHE_EXPIRY, CACHE_ACTION); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/QueueingThreadPoolExecutorTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/QueueingThreadPoolExecutorTest.java index 5d77212d8..2e2d5f43a 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/QueueingThreadPoolExecutorTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/QueueingThreadPoolExecutorTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.common; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ public class QueueingThreadPoolExecutorTest { /** * We can enable logging for all test cases. */ - @Before + @BeforeEach public void setUp() { // enable to see logging. See below how to include slf4j-simple // enableLogging(); @@ -68,19 +68,19 @@ public class QueueingThreadPoolExecutorTest { /** * Tests what happens when poolName == null. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateInstanceInvalidArgsPoolNameNull() throws InterruptedException { - QueueingThreadPoolExecutor.createInstance(null, 1); + assertThrows(IllegalArgumentException.class, () -> QueueingThreadPoolExecutor.createInstance(null, 1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateInstanceInvalidArgsPoolSize0() { - QueueingThreadPoolExecutor.createInstance("test", 0); + assertThrows(IllegalArgumentException.class, () -> QueueingThreadPoolExecutor.createInstance("test", 0)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateInstanceInvalidArgsPoolSizeMinus1() { - QueueingThreadPoolExecutor.createInstance("test", -1); + assertThrows(IllegalArgumentException.class, () -> QueueingThreadPoolExecutor.createInstance("test", -1)); } /** @@ -107,14 +107,14 @@ public class QueueingThreadPoolExecutorTest { pool.shutdown(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPoolWithBlankPoolName() throws InterruptedException { - basicTestForPoolName(" "); + assertThrows(IllegalArgumentException.class, () -> basicTestForPoolName(" ")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPoolWithEmptyPoolName() throws InterruptedException { - basicTestForPoolName(""); + assertThrows(IllegalArgumentException.class, () -> basicTestForPoolName("")); } /** @@ -189,11 +189,11 @@ public class QueueingThreadPoolExecutorTest { /** * Tests what happens when wrong rejected execution handler will be used. */ - @Test(expected = UnsupportedOperationException.class) + @Test public void testSetInvalidRejectionHandler() throws InterruptedException { - String poolName = "testShutdownNoEntriesIntoQueueAnymore"; - ThreadPoolExecutor pool = QueueingThreadPoolExecutor.createInstance(poolName, 2); - pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); + ThreadPoolExecutor pool = QueueingThreadPoolExecutor.createInstance("testShutdownNoEntriesIntoQueueAnymore", 2); + assertThrows(UnsupportedOperationException.class, + () -> pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy())); } // helper methods diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadFactoryBuilderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadFactoryBuilderTest.java index 31cbfba71..223f043d9 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadFactoryBuilderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadFactoryBuilderTest.java @@ -12,14 +12,16 @@ */ package org.openhab.core.common; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.hamcrest.core.StringStartsWith.startsWith; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.lang.Thread.UncaughtExceptionHandler; import java.util.concurrent.ThreadFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for the {@link ThreadFactoryBuilder}. @@ -116,14 +118,16 @@ public class ThreadFactoryBuilderTest { assertThat(threadFactory.newThread(TEST_RUNNABLE).getPriority(), is(Thread.MAX_PRIORITY)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testWithPriorityValidationTooLow() { - ThreadFactoryBuilder.create().withPriority(Thread.MIN_PRIORITY - 1).build(); + assertThrows(IllegalArgumentException.class, + () -> ThreadFactoryBuilder.create().withPriority(Thread.MIN_PRIORITY - 1).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testWithPriorityValidationTooHigh() { - ThreadFactoryBuilder.create().withPriority(Thread.MAX_PRIORITY + 1).build(); + assertThrows(IllegalArgumentException.class, + () -> ThreadFactoryBuilder.create().withPriority(Thread.MAX_PRIORITY + 1).build()); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadPoolManagerTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadPoolManagerTest.java index aa19246b2..ec1d773e1 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadPoolManagerTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/ThreadPoolManagerTest.java @@ -13,7 +13,8 @@ package org.openhab.core.common; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collections; import java.util.concurrent.ExecutorService; @@ -21,7 +22,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * The ThreadPoolManagerTest tests functionality of the ThreadPoolManager class. diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java index 63c1c561d..848794683 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.common.osgi; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -25,7 +25,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.osgi.framework.Bundle; /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/I18nProviderImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/I18nProviderImplTest.java index 81f05ff42..96813da80 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/I18nProviderImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/I18nProviderImplTest.java @@ -13,9 +13,9 @@ package org.openhab.core.internal.i18n; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import static org.openhab.core.internal.i18n.I18nProviderImpl.*; import java.time.ZoneId; @@ -24,9 +24,11 @@ import java.util.Hashtable; import java.util.Locale; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +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.library.types.PointType; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -37,6 +39,7 @@ import org.osgi.service.component.ComponentContext; * * @author Stefan Triller - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class I18nProviderImplTest { private static final String LOCATION_ZERO = "0,0"; @@ -60,16 +63,12 @@ public class I18nProviderImplTest { private I18nProviderImpl i18nProviderImpl; private Dictionary initialConfig = new Hashtable<>(); - @Mock - private ComponentContext componentContext; - @Mock - private BundleContext bundleContext; - @Mock - private Bundle bundle; + private @Mock ComponentContext componentContext; + private @Mock BundleContext bundleContext; + private @Mock Bundle bundle; - @Before + @BeforeEach public void setup() { - initMocks(this); initialConfig = buildInitialConfig(); when(componentContext.getProperties()).thenReturn(initialConfig); when(componentContext.getBundleContext()).thenReturn(bundleContext); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemBuilderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemBuilderTest.java index 534a6725a..c411aca0b 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemBuilderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemBuilderTest.java @@ -12,17 +12,18 @@ */ package org.openhab.core.internal.items; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.Arrays; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +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.items.ActiveItem; import org.openhab.core.items.GroupFunction; import org.openhab.core.items.GroupItem; @@ -33,6 +34,7 @@ import org.openhab.core.items.ItemFactory; * * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class ItemBuilderTest { private ItemBuilderFactoryImpl itemBuilderFactory; @@ -40,9 +42,8 @@ public class ItemBuilderTest { private @Mock ActiveItem mockItem; private @Mock Item originalItem; - @Before + @BeforeEach public void setup() { - initMocks(this); itemBuilderFactory = new ItemBuilderFactoryImpl(mockFactory); } @@ -153,21 +154,23 @@ public class ItemBuilderTest { assertSame(baseItem, res.getBaseItem()); } - @Test(expected = IllegalStateException.class) + @Test public void testNoFactory() { when(mockFactory.createItem(anyString(), anyString())).thenReturn(null); - itemBuilderFactory.newItemBuilder("String", "test").build(); + assertThrows(IllegalStateException.class, () -> itemBuilderFactory.newItemBuilder("String", "test").build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFunctionOnNonGroupItem() { GroupFunction mockFunction = mock(GroupFunction.class); - itemBuilderFactory.newItemBuilder("String", "test").withGroupFunction(mockFunction); + assertThrows(IllegalArgumentException.class, + () -> itemBuilderFactory.newItemBuilder("String", "test").withGroupFunction(mockFunction)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testBaseItemOnNonGroupItem() { Item mockItem = mock(Item.class); - itemBuilderFactory.newItemBuilder("String", "test").withBaseItem(mockItem); + assertThrows(IllegalArgumentException.class, + () -> itemBuilderFactory.newItemBuilder("String", "test").withBaseItem(mockItem)); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemStateConverterImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemStateConverterImplTest.java index eab053a2b..aa9860063 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemStateConverterImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemStateConverterImplTest.java @@ -13,14 +13,15 @@ package org.openhab.core.internal.items; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; import javax.measure.quantity.Length; import javax.measure.quantity.Temperature; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.i18n.UnitProvider; import org.openhab.core.items.Item; import org.openhab.core.library.items.NumberItem; @@ -41,7 +42,7 @@ public class ItemStateConverterImplTest { private ItemStateConverterImpl itemStateConverter; - @Before + @BeforeEach public void setup() { UnitProvider unitProvider = mock(UnitProvider.class); when(unitProvider.getUnit(Temperature.class)).thenReturn(ImperialUnits.FAHRENHEIT); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemTagTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemTagTest.java index 6165072f7..4fff1979d 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemTagTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/ItemTagTest.java @@ -13,11 +13,11 @@ package org.openhab.core.internal.items; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.items.SwitchItem; /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataCommandDescriptionProviderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataCommandDescriptionProviderTest.java index f85bc1933..90fcfa299 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataCommandDescriptionProviderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataCommandDescriptionProviderTest.java @@ -12,20 +12,20 @@ */ package org.openhab.core.internal.items; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.openhab.core.items.Item; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.items.ManagedMetadataProvider; import org.openhab.core.items.Metadata; import org.openhab.core.items.MetadataKey; @@ -39,6 +39,7 @@ import org.osgi.framework.ServiceReference; /** * @author Yannick Schaus - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class MetadataCommandDescriptionProviderTest { private static final String ITEM_NAME = "itemName"; @@ -47,24 +48,18 @@ public class MetadataCommandDescriptionProviderTest { private @Mock ServiceReference managedProviderRef; private @Mock BundleContext bundleContext; private @Mock ManagedMetadataProvider managedProvider; - private @Mock Item item; private @Mock MetadataRegistryImpl metadataRegistry; private MetadataCommandDescriptionProvider commandDescriptionProvider; private ServiceListener providerTracker; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void setup() throws Exception { - initMocks(this); - when(bundleContext.getService(same(managedProviderRef))).thenReturn(managedProvider); - when(item.getName()).thenReturn(ITEM_NAME); - metadataRegistry = new MetadataRegistryImpl(); - metadataRegistry.setManagedProvider(managedProvider); metadataRegistry.activate(bundleContext); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataRegistryImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataRegistryImplTest.java index 00d170953..acbb110e7 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataRegistryImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataRegistryImplTest.java @@ -12,18 +12,18 @@ */ package org.openhab.core.internal.items; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.openhab.core.items.Item; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.items.ManagedMetadataProvider; import org.openhab.core.items.Metadata; import org.openhab.core.items.MetadataKey; @@ -35,6 +35,7 @@ import org.osgi.framework.ServiceReference; /** * @author Simon Kaufmann - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class MetadataRegistryImplTest { private static final String ITEM_NAME = "itemName"; @@ -43,22 +44,16 @@ public class MetadataRegistryImplTest { private @Mock ServiceReference managedProviderRef; private @Mock BundleContext bundleContext; private @Mock ManagedMetadataProvider managedProvider; - private @Mock Item item; private MetadataRegistryImpl registry; private ServiceListener providerTracker; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void setup() throws Exception { - initMocks(this); - when(bundleContext.getService(same(managedProviderRef))).thenReturn(managedProvider); - when(item.getName()).thenReturn(ITEM_NAME); - registry = new MetadataRegistryImpl(); - registry.setManagedProvider(managedProvider); registry.activate(bundleContext); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProviderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProviderTest.java index f43cbcbb7..0b4e3f891 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProviderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProviderTest.java @@ -12,21 +12,21 @@ */ package org.openhab.core.internal.items; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.math.BigDecimal; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.openhab.core.items.Item; +import org.mockito.junit.jupiter.MockitoExtension; import org.openhab.core.items.ManagedMetadataProvider; import org.openhab.core.items.Metadata; import org.openhab.core.items.MetadataKey; @@ -40,6 +40,7 @@ import org.osgi.framework.ServiceReference; /** * @author Yannick Schaus - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class MetadataStateDescriptionFragmentProviderTest { private static final String ITEM_NAME = "itemName"; @@ -48,24 +49,18 @@ public class MetadataStateDescriptionFragmentProviderTest { private @Mock ServiceReference managedProviderRef; private @Mock BundleContext bundleContext; private @Mock ManagedMetadataProvider managedProvider; - private @Mock Item item; private @Mock MetadataRegistryImpl metadataRegistry; private MetadataStateDescriptionFragmentProvider stateDescriptionFragmentProvider; private ServiceListener providerTracker; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void setup() throws Exception { - initMocks(this); - when(bundleContext.getService(same(managedProviderRef))).thenReturn(managedProvider); - when(item.getName()).thenReturn(ITEM_NAME); - metadataRegistry = new MetadataRegistryImpl(); - metadataRegistry.setManagedProvider(managedProvider); metadataRegistry.activate(bundleContext); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java index 63e3db18c..9a452c2a0 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java @@ -13,9 +13,10 @@ package org.openhab.core.internal.scheduler; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test cases for {@link CronAdjuster} to test error handling and misc cases. @@ -32,68 +33,68 @@ public class CronAdjusterMiscTest { is(equalTo(false))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testToShort() { - new CronAdjuster("* * * * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testToLong() { - new CronAdjuster("* * * * * * * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * * * * * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testDayInWeek() { - new CronAdjuster("* * * * * FRI#X"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * * * FRI#X")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalDayInWeek() { - new CronAdjuster("* * * * * NO"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * * * NO")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMonthName() { - new CronAdjuster("* * * * FXB *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * * FXB *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testWeekNumber() { - new CronAdjuster("* * * XW * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * XW * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testBeforeSlash() { - new CronAdjuster("* * * 1/X * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * 1/X * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAfterSlash() { - new CronAdjuster("* * * X/10 * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * X/10 * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRangeLeftSideError() { - new CronAdjuster("X-3 * * * * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("X-3 * * * * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRangeRightSideError() { - new CronAdjuster("3-X * * * * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("3-X * * * * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testBelowMin() { - new CronAdjuster("0 0 0 0 0 0"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("0 0 0 0 0 0")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAboveMax() { - new CronAdjuster("99 * * * * *"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("99 * * * * *")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAboveWeekday() { - new CronAdjuster("* * * * * 8"); + assertThrows(IllegalArgumentException.class, () -> new CronAdjuster("* * * * * 8")); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java index 682a6ab74..01e57c1e1 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java @@ -13,18 +13,17 @@ package org.openhab.core.internal.scheduler; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.time.LocalDateTime; import java.time.temporal.Temporal; import java.util.Arrays; import java.util.Collection; +import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * @@ -32,21 +31,12 @@ import org.junit.runners.Parameterized.Parameters; * @author Simon Kaufmann - adapted to Java 8 * @author Hilbrand Bouwkamp - refactored to run as parameterized unit test and added missing cases to complete coverage */ -@RunWith(Parameterized.class) public class CronAdjusterTest { private static final String JAN_1ST_2000 = "2000-01-01T00:00:00"; private static final String JAN_1ST_2015 = "2015-01-01T00:00:00"; - @Parameter(value = 0) - public String in; - @Parameter(value = 1) - public String cron; - @Parameter(value = 2) - public String[] outs; - - @Parameters(name = "CronAdjusterTest pattern: {1}") - public static Collection data() { + public static Collection arguments() { return Arrays.asList(new Object[][] { { JAN_1ST_2015, "@reboot", new String[] { "2200-01-01T00:00" } }, { JAN_1ST_2015, "@hourly", new String[] { "2015-01-01T01:00", "2015-01-01T02:00", "2015-01-01T03:00", @@ -69,11 +59,9 @@ public class CronAdjusterTest { { JAN_1ST_2015, "0 15 10 LW * ?", new String[] { "2015-01-30T10:15", "2015-02-27T10:15", "2015-03-31T10:15", "2015-04-30T10:15", "2015-05-29T10:15" } }, - { JAN_1ST_2015, "0 15 10 WL * ?", new String[] { "2015-01-30T10:15", "2015-02-27T10:15", "2015-03-31T10:15", "2015-04-30T10:15", "2015-05-29T10:15" } }, - { JAN_1ST_2015, "0 15 10 3W * ?", new String[] { "2015-01-02T10:15", "2015-02-03T10:15", "2015-03-03T10:15", "2015-04-03T10:15", "2015-05-04T10:15" } }, @@ -191,8 +179,10 @@ public class CronAdjusterTest { "2022-01-01T00:00", "2200-01-01T00:00" }, } }); } - @Test(timeout = 1000) - public void testCronExpression() { + @ParameterizedTest + @MethodSource("arguments") + @Timeout(value = 1, unit = TimeUnit.SECONDS) + public void testCronExpression(String in, String cron, String[] outs) { final CronAdjuster cronAdjuster = new CronAdjuster(cron); Temporal ldt = LocalDateTime.parse(in); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronSchedulerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronSchedulerImplTest.java index 2955fed99..820c30ec2 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronSchedulerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronSchedulerImplTest.java @@ -12,14 +12,16 @@ */ package org.openhab.core.internal.scheduler; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collections; import java.util.Map; import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.openhab.core.scheduler.CronJob; import org.openhab.core.scheduler.ScheduledCompletableFuture; @@ -34,7 +36,8 @@ import org.openhab.core.scheduler.ScheduledCompletableFuture; public class CronSchedulerImplTest { private final CronSchedulerImpl cronScheduler = new CronSchedulerImpl(new SchedulerImpl()); - @Test(timeout = 1000) + @Test + @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testCronReboot() throws Exception { long now = System.currentTimeMillis(); Semaphore s = new Semaphore(0); @@ -44,11 +47,12 @@ public class CronSchedulerImplTest { s.acquire(1); long diff = System.currentTimeMillis() - now; - assertTrue("Time difference should be less 200 but was: " + diff, diff < 200); - assertTrue("Scheduler should be done once reboot call done.", future.isDone()); + assertTrue(diff < 200, "Time difference should be less 200 but was: " + diff); + assertTrue(future.isDone(), "Scheduler should be done once reboot call done."); } - @Test(timeout = 6000) + @Test + @Timeout(value = 6, unit = TimeUnit.SECONDS) public void testCronScheduling() throws Exception { long now = System.currentTimeMillis(); AtomicReference ref = new AtomicReference<>(); @@ -65,11 +69,12 @@ public class CronSchedulerImplTest { s.acquire(2); long diff = (System.currentTimeMillis() - now + 50) / 1000; - assertTrue("Difference calculation should be between 3 and 4 but was: " + diff, diff >= 3 && diff <= 4); - assertEquals("Environment variable 'foo' should be correctly set", "bar", ref.get()); + assertTrue(diff >= 3 && diff <= 4, "Difference calculation should be between 3 and 4 but was: " + diff); + assertEquals("bar", ref.get(), "Environment variable 'foo' should be correctly set"); } - @Test(timeout = 2000) + @Test + @Timeout(value = 2, unit = TimeUnit.SECONDS) public void testAddRemoveScheduler() throws InterruptedException { Semaphore s = new Semaphore(0); CronJob cronJob = m -> s.release(); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/DelegatedSchedulerTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/DelegatedSchedulerTest.java index b3fefdc8c..0a5ad1ff9 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/DelegatedSchedulerTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/DelegatedSchedulerTest.java @@ -12,10 +12,9 @@ */ package org.openhab.core.internal.scheduler; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.time.Duration; import java.time.Instant; @@ -24,9 +23,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiFunction; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.scheduler.ScheduledCompletableFuture; /** @@ -34,20 +37,18 @@ import org.openhab.core.scheduler.ScheduledCompletableFuture; * * @author Hilbrand Bouwkamp - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class DelegatedSchedulerTest { private DelegatedSchedulerImpl delegatedscheduler; - @Mock - private SchedulerImpl scheduler; - @Mock - private ScheduledCompletableFuture temporalScheduledFuture; - @Mock - private CompletableFuture completableFuture; + private @Mock SchedulerImpl scheduler; + private @Mock ScheduledCompletableFuture temporalScheduledFuture; + private @Mock CompletableFuture completableFuture; - @Before + @BeforeEach public void setUp() { - initMocks(this); when(scheduler.after(any())).thenReturn(temporalScheduledFuture); when(temporalScheduledFuture.getPromise()).thenReturn(completableFuture); delegatedscheduler = new DelegatedSchedulerImpl(scheduler); @@ -62,9 +63,9 @@ public class DelegatedSchedulerTest { return null; }).when(temporalScheduledFuture).cancel(true); delegatedscheduler.after(Duration.ofMillis(100)); - assertFalse("Check if cancel was not called", check.get()); + assertFalse(check.get(), "Check if cancel was not called"); delegatedscheduler.deactivate(); - assertTrue("Cancel should be called on deactivation", check.get()); + assertTrue(check.get(), "Cancel should be called on deactivation"); } @Test @@ -79,9 +80,9 @@ public class DelegatedSchedulerTest { return null; }); delegatedscheduler.after(Duration.ofMillis(100)); - assertFalse("Check if cancel was not called", check.get()); + assertFalse(check.get(), "Check if cancel was not called"); delegatedscheduler.deactivate(); - assertFalse("When job handled, cancel should not be called on deactivation. Because is job already gone.", - check.get()); + assertFalse(check.get(), + "When job handled, cancel should not be called on deactivation. Because is job already gone."); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/PeriodicSchedulerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/PeriodicSchedulerImplTest.java index 0e7f12c90..687dd1597 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/PeriodicSchedulerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/PeriodicSchedulerImplTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.internal.scheduler; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.time.Duration; @@ -21,7 +21,8 @@ import java.util.Queue; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.openhab.core.scheduler.ScheduledCompletableFuture; /** @@ -35,7 +36,8 @@ import org.openhab.core.scheduler.ScheduledCompletableFuture; public class PeriodicSchedulerImplTest { private final PeriodicSchedulerImpl periodicScheduler = new PeriodicSchedulerImpl(new SchedulerImpl()); - @Test(timeout = 5000) + @Test + @Timeout(value = 5, unit = TimeUnit.SECONDS) public void testSchedule() throws InterruptedException, IOException { Queue times = new ArrayDeque<>(); Semaphore semaphore = new Semaphore(0); @@ -53,8 +55,8 @@ public class PeriodicSchedulerImplTest { long offset = times.poll(); long[] expectedResults = { 2, 5, 8, 11, 14 }; for (long expectedResult : expectedResults) { - assertEquals("Expected periodic time", offset + expectedResult, times.poll().longValue()); + assertEquals(offset + expectedResult, times.poll().longValue(), "Expected periodic time"); } - assertFalse("No more jobs should have been scheduled", semaphore.tryAcquire(1, TimeUnit.SECONDS)); + assertFalse(semaphore.tryAcquire(1, TimeUnit.SECONDS), "No more jobs should have been scheduled"); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java index 68321885f..5dcd6ca3a 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.internal.scheduler; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.FileNotFoundException; import java.lang.reflect.InvocationTargetException; @@ -30,7 +30,8 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.openhab.core.scheduler.ScheduledCompletableFuture; import org.openhab.core.scheduler.SchedulerRunnable; import org.openhab.core.scheduler.SchedulerTemporalAdjuster; @@ -46,20 +47,22 @@ import org.openhab.core.scheduler.SchedulerTemporalAdjuster; public class SchedulerImplTest { private SchedulerImpl scheduler = new SchedulerImpl(); - @Test(expected = CancellationException.class, timeout = 500) + @Test + @Timeout(value = 500, unit = TimeUnit.MILLISECONDS) public void testAfterCancelled() throws InterruptedException, InvocationTargetException, ExecutionException { AtomicBoolean check = new AtomicBoolean(); Callable callable = () -> check.getAndSet(true); ScheduledCompletableFuture after = scheduler.after(callable, Duration.ofMillis(200_0000)); after.cancel(true); Thread.sleep(100); - assertTrue("Scheduled job cancelled before timeout", after.isCancelled()); + assertTrue(after.isCancelled(), "Scheduled job cancelled before timeout"); Thread.sleep(200); - assertFalse("Callable method should not been called", check.get()); - after.get(); + assertFalse(check.get(), "Callable method should not been called"); + assertThrows(CancellationException.class, () -> after.get()); } - @Test(timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testAfterResolved() throws InterruptedException, ExecutionException { AtomicInteger check = new AtomicInteger(); Callable callable = () -> { @@ -68,12 +71,13 @@ public class SchedulerImplTest { }; ScheduledCompletableFuture after = scheduler.after(callable, Duration.ofMillis(100)); Thread.sleep(200); - assertTrue("Scheduled job should finish done", after.isDone()); - assertEquals("After CompletableFuture should return correct value", 10, check.get()); - assertEquals("After CompletableFuture should return correct value", 5, after.get().intValue()); + assertTrue(after.isDone(), "Scheduled job should finish done"); + assertEquals(10, check.get(), "After CompletableFuture should return correct value"); + assertEquals(5, after.get().intValue(), "After CompletableFuture should return correct value"); } - @Test(expected = FileNotFoundException.class, timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testAfterResolvedWithException() throws Throwable { Callable callable = () -> { // Pass a exception not very likely thrown by the scheduler it self to avoid missing real exceptions. @@ -81,96 +85,114 @@ public class SchedulerImplTest { }; ScheduledCompletableFuture after = scheduler.after(callable, Duration.ofMillis(100)); Thread.sleep(200); - assertTrue("Scheduled job should be done", after.isDone()); - assertTrue("After CompletableFuture should have completed with an exception", - after.getPromise().isCompletedExceptionally()); - try { - after.get(); - } catch (ExecutionException e) { - throw e.getCause(); - } + assertTrue(after.isDone(), "Scheduled job should be done"); + assertTrue(after.getPromise().isCompletedExceptionally(), + "After CompletableFuture should have completed with an exception"); + + assertThrows(FileNotFoundException.class, () -> { + try { + after.get(); + } catch (ExecutionException e) { + throw e.getCause(); + } + }); } - @Test(expected = TimeoutException.class, timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testBeforeTimeoutException() throws Throwable { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); Thread.sleep(200); d.complete(3); d.get(); - assertTrue("Scheduled job should be done", before.isDone()); - assertTrue("Before CompletableFuture should have completed with an exception", - before.getPromise().isCompletedExceptionally()); - try { - before.get(); - } catch (ExecutionException e) { - throw e.getCause(); - } + assertTrue(before.isDone(), "Scheduled job should be done"); + assertTrue(before.getPromise().isCompletedExceptionally(), + "Before CompletableFuture should have completed with an exception"); + assertThrows(TimeoutException.class, () -> { + try { + before.get(); + } catch (ExecutionException e) { + throw e.getCause(); + } + }); } - @Test(expected = CancellationException.class, timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testBeforeCancelled() throws InterruptedException, InvocationTargetException, ExecutionException { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); before.cancel(true); - assertTrue("Scheduled job cancelled before timeout", before.getPromise().isCompletedExceptionally()); - before.get(); + assertTrue(before.getPromise().isCompletedExceptionally(), "Scheduled job cancelled before timeout"); + assertThrows(CancellationException.class, () -> { + before.get(); + }); } - @Test(timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testBeforeResolved() throws InterruptedException, ExecutionException { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); d.complete(Boolean.TRUE); - assertTrue("Scheduled job should finish done", before.isDone()); - assertTrue("Before CompletableFuture should return correct value", before.get()); + assertTrue(before.isDone(), "Scheduled job should finish done"); + assertTrue(before.get(), "Before CompletableFuture should return correct value"); } - @Test(expected = FileNotFoundException.class, timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testBeforeResolvedWithException() throws Throwable { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); // Pass an exception not very likely thrown by the scheduler it self to avoid missing real exceptions. d.completeExceptionally(new FileNotFoundException("testBeforeTimeoutException")); - assertTrue("Scheduled job should be done", before.isDone()); - assertTrue("Before CompletableFuture should have completed with an exception", - before.getPromise().isCompletedExceptionally()); - try { - before.get(); - } catch (ExecutionException e) { - throw e.getCause(); - } + assertTrue(before.isDone(), "Scheduled job should be done"); + assertTrue(before.getPromise().isCompletedExceptionally(), + "Before CompletableFuture should have completed with an exception"); + assertThrows(FileNotFoundException.class, () -> { + try { + before.get(); + } catch (ExecutionException e) { + throw e.getCause(); + } + }); } - @Test(expected = TimeoutException.class, timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testAfterTimeoutException() throws Throwable { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); Thread.sleep(200); d.complete(3); d.get(); - assertTrue("Scheduled job should be done", before.isDone()); - assertTrue("Before CompletableFuture should have completed with an exception", - before.getPromise().isCompletedExceptionally()); - try { - before.get(); - } catch (ExecutionException e) { - throw e.getCause(); - } + assertTrue(before.isDone(), "Scheduled job should be done"); + assertTrue(before.getPromise().isCompletedExceptionally(), + "Before CompletableFuture should have completed with an exception"); + assertThrows(TimeoutException.class, () -> { + try { + before.get(); + } catch (ExecutionException e) { + throw e.getCause(); + } + }); } - @Test(timeout = 1000) + @Test + @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testSchedule() throws InterruptedException { Semaphore s = new Semaphore(0); TestSchedulerTemporalAdjuster temporalAdjuster = new TestSchedulerTemporalAdjuster(); scheduler.schedule(s::release, temporalAdjuster); s.acquire(3); Thread.sleep(300); // wait a little longer to see if not more are scheduled. - assertEquals("Scheduler should not have released more after done", 0, s.availablePermits()); - assertEquals("Scheduler should have run 3 times", 3, temporalAdjuster.getCount()); + assertEquals(0, s.availablePermits(), "Scheduler should not have released more after done"); + assertEquals(3, temporalAdjuster.getCount(), "Scheduler should have run 3 times"); } - @Test(timeout = 1000) + @Test + @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testScheduleCancel() throws InterruptedException { Semaphore s = new Semaphore(0); TestSchedulerTemporalAdjuster temporalAdjuster = new TestSchedulerTemporalAdjuster(); @@ -179,11 +201,12 @@ public class SchedulerImplTest { Thread.sleep(50); schedule.cancel(true); Thread.sleep(300); // wait a little longer to see if not more are scheduled. - assertEquals("Scheduler should not have released more after cancel", 0, s.availablePermits()); - assertEquals("Scheduler should have run 1 time", 1, temporalAdjuster.getCount()); + assertEquals(0, s.availablePermits(), "Scheduler should not have released more after cancel"); + assertEquals(1, temporalAdjuster.getCount(), "Scheduler should have run 1 time"); } - @Test(timeout = 1000) + @Test + @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testScheduleException() throws InterruptedException { Semaphore s = new Semaphore(0); TestSchedulerTemporalAdjuster temporalAdjuster = new TestSchedulerTemporalAdjuster(); @@ -201,11 +224,12 @@ public class SchedulerImplTest { }); s.acquire(1); Thread.sleep(300); // wait a little longer to see if not more are scheduled. - assertEquals("Scheduler should not have released more after cancel", 0, s.availablePermits()); - assertEquals("Scheduler should have run 0 time", 0, temporalAdjuster.getCount()); + assertEquals(0, s.availablePermits(), "Scheduler should not have released more after cancel"); + assertEquals(0, temporalAdjuster.getCount(), "Scheduler should have run 0 time"); } - @Test(timeout = 300) + @Test + @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testNegative() throws InterruptedException { Semaphore s = new Semaphore(0); scheduler.after(() -> { @@ -213,28 +237,30 @@ public class SchedulerImplTest { return null; }, Duration.ofMillis(-1000)); Thread.sleep(200); - assertEquals("Negative value should mean after finished right away", 1, s.availablePermits()); + assertEquals(1, s.availablePermits(), "Negative value should mean after finished right away"); } - @Test(timeout = 1000) + @Test + @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testDelay() throws InterruptedException { long duration = 5000; ScheduledCompletableFuture future = scheduler.after(Duration.ofMillis(duration)); Thread.sleep(500); long timeLeft = future.getDelay(TimeUnit.MILLISECONDS); long expectedTimeLeft = duration - 450; // add some slack so don't check at exact time - assertTrue("Delay should be less:" + timeLeft + " < " + expectedTimeLeft, timeLeft < expectedTimeLeft); + assertTrue(timeLeft < expectedTimeLeft, "Delay should be less:" + timeLeft + " < " + expectedTimeLeft); future.cancel(true); } - @Test(timeout = 1000) + @Test + @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testCompareTo() throws InterruptedException { long duration = 5000; ScheduledCompletableFuture future1 = scheduler.after(Duration.ofMillis(duration)); Thread.sleep(500); ScheduledCompletableFuture future2 = scheduler.after(Duration.ofMillis(duration)); int compare = future1.compareTo(future2); - assertTrue("First future should be less than second", compare < 0); + assertTrue(compare < 0, "First future should be less than second"); future1.cancel(true); future2.cancel(true); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/ReadyServiceImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/ReadyServiceImplTest.java index 9167c6f89..a59a208a5 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/ReadyServiceImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/ReadyServiceImplTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.internal.service; -import static org.junit.Assert.*; -import static org.mockito.Matchers.isA; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.service.ReadyMarker; import org.openhab.core.service.ReadyMarkerFilter; import org.openhab.core.service.ReadyService.ReadyTracker; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/StateDescriptionServiceImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/StateDescriptionServiceImplTest.java index 26ecbc40e..894a730e1 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/StateDescriptionServiceImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/service/StateDescriptionServiceImplTest.java @@ -13,7 +13,7 @@ package org.openhab.core.internal.service; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; import java.math.BigDecimal; @@ -21,8 +21,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.library.items.NumberItem; import org.openhab.core.types.StateDescription; import org.openhab.core.types.StateDescriptionFragment; @@ -50,7 +50,7 @@ public class StateDescriptionServiceImplTest { private StateDescriptionServiceImpl stateDescriptionService; private NumberItem item; - @Before + @BeforeEach public void setup() { stateDescriptionService = new StateDescriptionServiceImpl(); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/types/StateDescriptionFragmentImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/types/StateDescriptionFragmentImplTest.java index a237c4f37..4e3e75126 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/types/StateDescriptionFragmentImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/types/StateDescriptionFragmentImplTest.java @@ -12,14 +12,15 @@ */ package org.openhab.core.internal.types; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import java.math.BigDecimal; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.types.StateDescription; import org.openhab.core.types.StateDescriptionFragment; import org.openhab.core.types.StateOption; @@ -33,7 +34,7 @@ public class StateDescriptionFragmentImplTest { private StateDescriptionFragmentImpl source; - @Before + @BeforeEach public void setup() { source = new StateDescriptionFragmentImpl(); source.setMinimum(BigDecimal.ZERO); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java index 4e6b0acfe..0c1b097d1 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java @@ -12,8 +12,9 @@ */ package org.openhab.core.items; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -22,7 +23,7 @@ import java.util.List; import java.util.Locale; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.events.EventPublisher; import org.openhab.core.i18n.UnitProvider; @@ -77,22 +78,23 @@ public class GenericItemTest { verifyNoMoreInteractions(publisher); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAddGroupNameWithNull() { TestItem item = new TestItem("member1"); - item.addGroupName(toNull()); + assertThrows(IllegalArgumentException.class, () -> item.addGroupName(toNull())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAddGroupNamesWithNull() { TestItem item = new TestItem("member1"); - item.addGroupNames(Arrays.asList("group-a", toNull(), "group-b")); + assertThrows(IllegalArgumentException.class, + () -> item.addGroupNames(Arrays.asList("group-a", toNull(), "group-b"))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRemoveGroupNameWithNull() { TestItem item = new TestItem("member1"); - item.removeGroupName(toNull()); + assertThrows(IllegalArgumentException.class, () -> item.removeGroupName(toNull())); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/MetadataKeyTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/MetadataKeyTest.java index c521928a5..aa9cd6979 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/MetadataKeyTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/MetadataKeyTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/dto/ItemDTOMapperTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/dto/ItemDTOMapperTest.java index 9562b8590..2f253678d 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/dto/ItemDTOMapperTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/dto/ItemDTOMapperTest.java @@ -15,10 +15,11 @@ */ package org.openhab.core.items.dto; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.items.GroupFunction; import org.openhab.core.library.items.NumberItem; import org.openhab.core.library.types.ArithmeticGroupFunction; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/AbstractEventFactoryTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/AbstractEventFactoryTest.java index a3d5e7bc2..29b32760c 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/AbstractEventFactoryTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/AbstractEventFactoryTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.items.events; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.events.AbstractEventFactory; /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java index a38b45cfe..b1bb2fa5d 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java @@ -12,10 +12,11 @@ */ package org.openhab.core.items.events; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.items.Item; import org.openhab.core.items.dto.ItemDTOMapper; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/CoreItemFactoryTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/CoreItemFactoryTest.java index d561550ba..a8e6f64cc 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/CoreItemFactoryTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/CoreItemFactoryTest.java @@ -13,16 +13,16 @@ package org.openhab.core.library; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; import java.util.Arrays; import java.util.List; import javax.measure.quantity.Temperature; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.GenericItem; import org.openhab.core.library.items.NumberItem; @@ -36,7 +36,7 @@ public class CoreItemFactoryTest { private List itemTypeNames; - @Before + @BeforeEach public void setup() { coreItemFactory = new CoreItemFactory(); itemTypeNames = Arrays.asList(coreItemFactory.getSupportedItemTypes()); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/dimension/VolumetricFlowRateTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/dimension/VolumetricFlowRateTest.java index dcc23eeee..a30763cd9 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/dimension/VolumetricFlowRateTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/dimension/VolumetricFlowRateTest.java @@ -13,14 +13,16 @@ package org.openhab.core.library.dimension; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.stream.Stream; import javax.measure.Unit; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.openhab.core.library.unit.SmartHomeUnits; import org.openhab.core.types.util.UnitUtils; @@ -32,7 +34,7 @@ import tec.uom.se.quantity.Quantities; * * @author Łukasz Dywicki - Initial contribution */ -@RunWith(Parameterized.class) +@NonNullByDefault public class VolumetricFlowRateTest { /** @@ -40,25 +42,15 @@ public class VolumetricFlowRateTest { */ private static final Unit BASE_UNIT = SmartHomeUnits.CUBICMETRE_PER_HOUR; - private final Unit unit; - private final String symbol; - private final Double value; - private final Double valueInBaseUnit; - - public VolumetricFlowRateTest(Unit unit, String symbol, Double value, Double valueInBaseUnit) { - this.unit = unit; - this.symbol = symbol; - this.value = value; - this.valueInBaseUnit = valueInBaseUnit; - } - /** * An additional test which converts given test quantity into base unit and then compares it with expected value. * * This basic test confirms that values of different flow rates can be exchanged to given base unit. */ - @Test - public void testValueConversionToM3s() { + @ParameterizedTest + @MethodSource("arguments") + public void testValueConversionToM3s(Unit unit, String symbol, Double value, + Double valueInBaseUnit) { ComparableQuantity quantity = Quantities.getQuantity(value, unit); ComparableQuantity quantityInBase = Quantities.getQuantity(valueInBaseUnit, BASE_UNIT); @@ -70,20 +62,20 @@ public class VolumetricFlowRateTest { /** * Verifies that given symbol is recognized by {@link UnitUtils}. */ - @Test - public void testSymbolLookup() { + @ParameterizedTest + @MethodSource("arguments") + public void testSymbolLookup(Unit unit, String symbol, Double value, Double valueInBaseUnit) { Unit parsedUnit = UnitUtils.parseUnit(symbol); assertThat(parsedUnit, is(notNullValue())); assertThat(parsedUnit, is(equalTo(unit))); } - @Parameters - public static Object[] params() { - return new Object[] { new Object[] { SmartHomeUnits.LITRE_PER_MINUTE, "l/min", 100.0, 6.0 }, - new Object[] { SmartHomeUnits.CUBICMETRE_PER_SECOND, "m³/s", 100.0, 360000.0 }, - new Object[] { SmartHomeUnits.CUBICMETRE_PER_MINUTE, "m³/min", 100.0, 6000.0 }, - new Object[] { SmartHomeUnits.CUBICMETRE_PER_HOUR, "m³/h", 100.0, 100.0 }, - new Object[] { SmartHomeUnits.CUBICMETRE_PER_DAY, "m³/d", 100.0, 4.166666666666667 } }; + private static Stream arguments() { + return Stream.of(Arguments.of(SmartHomeUnits.LITRE_PER_MINUTE, "l/min", 100.0, 6.0), + Arguments.of(SmartHomeUnits.CUBICMETRE_PER_SECOND, "m³/s", 100.0, 360000.0), + Arguments.of(SmartHomeUnits.CUBICMETRE_PER_MINUTE, "m³/min", 100.0, 6000.0), + Arguments.of(SmartHomeUnits.CUBICMETRE_PER_HOUR, "m³/h", 100.0, 100.0), + Arguments.of(SmartHomeUnits.CUBICMETRE_PER_DAY, "m³/d", 100.0, 4.166666666666667)); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/CallItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/CallItemTest.java index 4f828ac1e..40806ddc0 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/CallItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/CallItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.StringListType; /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ColorItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ColorItemTest.java index 073cf6030..dba5c27a3 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ColorItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ColorItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.OnOffType; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ContactItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ContactItemTest.java index 4ebe97145..b23973e58 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ContactItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ContactItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.OpenClosedType; /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DateTimeItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DateTimeItemTest.java index c2edd7963..0fd99aac8 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DateTimeItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DateTimeItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DateTimeType; /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DimmerItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DimmerItemTest.java index 09795a541..b91b37188 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DimmerItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/DimmerItemTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.items.Item; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.OnOffType; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ImageItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ImageItemTest.java index cda0d6b12..3dee70dbd 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ImageItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/ImageItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.RawType; import org.openhab.core.types.State; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/LocationItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/LocationItemTest.java index d2d1f6b9c..5c6007ce2 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/LocationItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/LocationItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.PointType; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/NumberItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/NumberItemTest.java index e9dccf0e8..f68c00ae1 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/NumberItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/NumberItemTest.java @@ -13,15 +13,19 @@ package org.openhab.core.library.items; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import javax.measure.quantity.Temperature; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openhab.core.i18n.UnitProvider; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.HSBType; @@ -39,17 +43,16 @@ import org.openhab.core.types.util.UnitUtils; * * @author Stefan Triller - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class NumberItemTest { private static final String ITEM_NAME = "test"; - @Mock - private StateDescriptionService stateDescriptionService; + private @Mock StateDescriptionService stateDescriptionService; - @Before + @BeforeEach public void setup() { - initMocks(this); - when(stateDescriptionService.getStateDescription(ITEM_NAME, null)).thenReturn(StateDescriptionFragmentBuilder .create().withPattern("%.1f " + UnitUtils.UNIT_PLACEHOLDER).build().toStateDescription()); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/PlayerItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/PlayerItemTest.java index 0bcea9d10..9cff10973 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/PlayerItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/PlayerItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.PlayPauseType; import org.openhab.core.library.types.RewindFastforwardType; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/RollershutterItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/RollershutterItemTest.java index 7d0721dc1..3c7fe9ce7 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/RollershutterItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/RollershutterItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.UpDownType; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StateUtil.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StateUtil.java index 7eabe04de..f83d2332a 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StateUtil.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StateUtil.java @@ -12,7 +12,7 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashSet; import java.util.LinkedList; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StringItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StringItemTest.java index bb19fb4da..1c37a4611 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StringItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/StringItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.StringType; import org.openhab.core.types.State; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/SwitchItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/SwitchItemTest.java index 071e0bd67..e935d4673 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/SwitchItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/SwitchItemTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.items; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.OnOffType; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/ArithmeticGroupFunctionTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/ArithmeticGroupFunctionTest.java index ee2b393d1..c815ef401 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/ArithmeticGroupFunctionTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/ArithmeticGroupFunctionTest.java @@ -13,16 +13,17 @@ package org.openhab.core.library.types; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.GenericItem; import org.openhab.core.items.GroupFunction; import org.openhab.core.items.Item; @@ -40,7 +41,7 @@ public class ArithmeticGroupFunctionTest { private GroupFunction function; private Set items; - @Before + @BeforeEach public void init() { items = new HashSet<>(); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeGroupFunctionTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeGroupFunctionTest.java index b98ab0b7d..8a86c9a49 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeGroupFunctionTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeGroupFunctionTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.ZonedDateTime; import java.util.Collections; @@ -20,8 +20,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.GenericItem; import org.openhab.core.items.GroupFunction; import org.openhab.core.items.Item; @@ -37,7 +37,7 @@ public class DateTimeGroupFunctionTest { private GroupFunction function; private Set items; - @Before + @BeforeEach public void init() { items = new HashSet<>(); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeTypeTest.java index 2b904cf75..8e2e9fd87 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DateTimeTypeTest.java @@ -13,7 +13,8 @@ package org.openhab.core.library.types; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.time.DateTimeException; import java.time.LocalDateTime; @@ -30,11 +31,9 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * @author Thomas Eichstaedt-Engelen - Initial contribution @@ -44,7 +43,6 @@ import org.junit.runners.Parameterized.Parameters; * @author Gaël L'hopital - added ability to use second and milliseconds unix time */ @NonNullByDefault -@RunWith(Parameterized.class) public class DateTimeTypeTest { /** @@ -176,7 +174,6 @@ public class DateTimeTypeTest { * * @return collection */ - @Parameters public static Collection parameters() { // for simplicity we use always the same input time. return Arrays.asList(new Object[][] { @@ -236,23 +233,6 @@ public class DateTimeTypeTest { return inputTimeMap; } - private final ParameterSet parameterSet; - - /** - * setup Test class with current parameter map. - * - * @param parameterMap parameter map - */ - public DateTimeTypeTest(ParameterSet parameterSet) { - this.parameterSet = parameterSet; - } - - @Before - public void setUp() { - // set default time zone - TimeZone.setDefault(parameterSet.defaultTimeZone); - } - @Test public void serializationTest() { ZonedDateTime zoned = ZonedDateTime.now(); @@ -300,8 +280,10 @@ public class DateTimeTypeTest { assertThat(epochStandard, is(zdtStandard)); } - @Test - public void createDate() { + @ParameterizedTest + @MethodSource("parameters") + public void createDate(ParameterSet parameterSet) { + TimeZone.setDefault(parameterSet.defaultTimeZone); // get DateTimeType from the current parameter DateTimeType dt1; DateTimeType dt2; @@ -339,9 +321,11 @@ public class DateTimeTypeTest { assertEquals(dt1, dt3); } - @Test - public void formattingTest() { - DateTimeType dt = createDateTimeType(); + @ParameterizedTest + @MethodSource("parameters") + public void formattingTest(ParameterSet parameterSet) { + TimeZone.setDefault(parameterSet.defaultTimeZone); + DateTimeType dt = createDateTimeType(parameterSet); Locale locale = parameterSet.locale; String pattern = parameterSet.pattern; if (locale != null && pattern != null) { @@ -351,22 +335,26 @@ public class DateTimeTypeTest { } } - @Test - public void changingZoneTest() { - DateTimeType dt = createDateTimeType(); + @ParameterizedTest + @MethodSource("parameters") + public void changingZoneTest(ParameterSet parameterSet) { + TimeZone.setDefault(parameterSet.defaultTimeZone); + DateTimeType dt = createDateTimeType(parameterSet); DateTimeType dt2 = dt.toLocaleZone(); assertEquals(parameterSet.expectedResultLocalTZ, dt2.toFullString()); dt2 = dt.toZone(parameterSet.defaultTimeZone.toZoneId()); assertEquals(parameterSet.expectedResultLocalTZ, dt2.toFullString()); } - @Test(expected = DateTimeException.class) - public void changingZoneThrowsExceptionTest() { - DateTimeType dt = createDateTimeType(); - dt.toZone("XXX"); + @ParameterizedTest + @MethodSource("parameters") + public void changingZoneThrowsExceptionTest(ParameterSet parameterSet) { + TimeZone.setDefault(parameterSet.defaultTimeZone); + DateTimeType dt = createDateTimeType(parameterSet); + assertThrows(DateTimeException.class, () -> dt.toZone("XXX")); } - private DateTimeType createDateTimeType() throws DateTimeException { + private DateTimeType createDateTimeType(ParameterSet parameterSet) throws DateTimeException { Map inputTimeMap = parameterSet.inputTimeMap; TimeZone inputTimeZone = parameterSet.inputTimeZone; String inputTimeString = parameterSet.inputTimeString; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DecimalTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DecimalTypeTest.java index 8eb7bd103..1e10245bd 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DecimalTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/DecimalTypeTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.text.DecimalFormatSymbols; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Eichstaedt-Engelen - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java index 5d2fb612b..c20055702 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java @@ -13,11 +13,12 @@ package org.openhab.core.library.types; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @@ -126,14 +127,14 @@ public class HSBTypeTest { assertEquals(new HSBType("11,100,100"), hsb); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithString1() { - new HSBType(""); + assertThrows(IllegalArgumentException.class, () -> new HSBType("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithString2() { - new HSBType("1,2"); + assertThrows(IllegalArgumentException.class, () -> new HSBType("1,2")); } @Test @@ -172,23 +173,23 @@ public class HSBTypeTest { assertThat(hsb.getBrightness(), is(new PercentType(3))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithIllegalHueValue() { - new HSBType("-13,85,51"); + assertThrows(IllegalArgumentException.class, () -> new HSBType("-13,85,51")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithIllegalHueValue2() { - new HSBType("360,85,51"); + assertThrows(IllegalArgumentException.class, () -> new HSBType("360,85,51")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithIllegalSaturationValue() { - new HSBType("5,-85,51"); + assertThrows(IllegalArgumentException.class, () -> new HSBType("5,-85,51")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithIllegalBrightnessValue() { - new HSBType("5,85,151"); + assertThrows(IllegalArgumentException.class, () -> new HSBType("5,85,151")); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OnOffTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OnOffTypeTest.java index d490a76b3..22a15679f 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OnOffTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OnOffTypeTest.java @@ -12,10 +12,9 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OpenClosedTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OpenClosedTypeTest.java index 8eddbb6c8..0dd640b15 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OpenClosedTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/OpenClosedTypeTest.java @@ -12,10 +12,9 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java index 2c7bb7594..2ab76feee 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.unit.SmartHomeUnits; /** @@ -22,14 +22,14 @@ import org.openhab.core.library.unit.SmartHomeUnits; */ public class PercentTypeTest { - @Test(expected = IllegalArgumentException.class) + @Test public void negativeNumber() { - new PercentType(-3); + assertThrows(IllegalArgumentException.class, () -> new PercentType(-3)); } - @Test(expected = IllegalArgumentException.class) + @Test public void moreThan100() { - new PercentType("100.2"); + assertThrows(IllegalArgumentException.class, () -> new PercentType("100.2")); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PointTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PointTypeTest.java index 83572f1a4..64b3e1854 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PointTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PointTypeTest.java @@ -13,37 +13,34 @@ package org.openhab.core.library.types; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Gaël L'hopital - Initial contribution */ public class PointTypeTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorEmpty() { - @SuppressWarnings("unused") - PointType errorGenerator = new PointType(""); + assertThrows(IllegalArgumentException.class, () -> new PointType("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorBadlyFormated() { - @SuppressWarnings("unused") - PointType errorGenerator = new PointType("2"); + assertThrows(IllegalArgumentException.class, () -> new PointType("2")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorBadlyFormated2() { - @SuppressWarnings("unused") - PointType errorGenerator = new PointType("2,"); + assertThrows(IllegalArgumentException.class, () -> new PointType("2,")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorBadlyFormated3() { - @SuppressWarnings("unused") - PointType errorGenerator = new PointType("2,3,4,5"); + assertThrows(IllegalArgumentException.class, () -> new PointType("2,3,4,5")); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunctionTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunctionTest.java index 9b5670021..1b11b7787 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunctionTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunctionTest.java @@ -12,9 +12,7 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.LinkedHashSet; import java.util.Set; @@ -25,9 +23,11 @@ import javax.measure.quantity.Power; import javax.measure.quantity.Pressure; import javax.measure.quantity.Temperature; -import org.junit.Before; -import org.junit.Test; +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.i18n.UnitProvider; import org.openhab.core.items.GroupFunction; import org.openhab.core.items.GroupItem; @@ -37,25 +37,20 @@ import org.openhab.core.library.items.NumberItem; import org.openhab.core.types.State; import org.openhab.core.types.UnDefType; -import tec.uom.se.unit.Units; - /** * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) public class QuantityTypeArithmeticGroupFunctionTest { private GroupFunction function; private Set items; - @Mock - UnitProvider unitProvider; + private @Mock UnitProvider unitProvider; - @Before + @BeforeEach public void init() { - initMocks(this); items = new LinkedHashSet<>(); - - when(unitProvider.getUnit(Temperature.class)).thenReturn(Units.CELSIUS); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java index 089d7fce4..695a8131d 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java @@ -13,7 +13,8 @@ package org.openhab.core.library.types; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.openhab.core.library.unit.MetricPrefix.CENTI; import java.math.BigDecimal; @@ -27,7 +28,7 @@ import javax.measure.quantity.Speed; import javax.measure.quantity.Temperature; import javax.measure.quantity.Time; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.dimension.DataAmount; import org.openhab.core.library.dimension.DataTransferRate; import org.openhab.core.library.dimension.Density; @@ -60,9 +61,9 @@ public class QuantityTypeTest { assertTrue(dt0.getUnit().getDimension() == QuantityDimension.NONE); } - @Test(expected = IllegalArgumentException.class) - public void testKnownInvalidConstructors() throws Exception { - new QuantityType<>("123 Hello World"); + @Test + public void testKnownInvalidConstructors() { + assertThrows(IllegalArgumentException.class, () -> new QuantityType<>("123 Hello World")); } @Test @@ -250,9 +251,9 @@ public class QuantityTypeTest { assertThat(new QuantityType<>("4 m").divide(new QuantityType<>("2 cm")), is(new QuantityType<>("2 m/cm"))); } - @Test(expected = ArithmeticException.class) + @Test public void testDivideZero() { - new QuantityType<>("4 m").divide(QuantityType.ZERO); + assertThrows(ArithmeticException.class, () -> new QuantityType<>("4 m").divide(QuantityType.ZERO)); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringListTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringListTypeTest.java index caa21af02..47fd92f89 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringListTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringListTypeTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Gaël L'hopital - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringTypeTest.java index e4e85b4c0..7c328cd60 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/StringTypeTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Eichstaedt-Engelen - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/UpDownTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/UpDownTypeTest.java index c17895b3e..bdea58320 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/UpDownTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/UpDownTypeTest.java @@ -12,10 +12,9 @@ */ package org.openhab.core.library.types; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Simon Kaufmann - Initial contribution diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/SmartHomeUnitsTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/SmartHomeUnitsTest.java index c16d54e13..9f96d4cb6 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/SmartHomeUnitsTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/SmartHomeUnitsTest.java @@ -13,8 +13,9 @@ package org.openhab.core.library.unit; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; @@ -27,7 +28,7 @@ import javax.measure.quantity.Pressure; import javax.measure.quantity.Speed; import javax.measure.quantity.Temperature; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.dimension.ArealDensity; import org.openhab.core.library.dimension.Density; import org.openhab.core.library.dimension.Intensity; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/net/HttpServiceUtilTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/net/HttpServiceUtilTest.java index d3cc483ef..5b3a685bb 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/net/HttpServiceUtilTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/net/HttpServiceUtilTest.java @@ -13,16 +13,19 @@ package org.openhab.core.net; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.Arrays; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; +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.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.InvalidSyntaxException; @@ -31,19 +34,18 @@ import org.osgi.framework.ServiceReference; /** * @author Henning Treu - Initial contribution */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.WARN) public class HttpServiceUtilTest { private static final String ORG_OSGI_SERVICE_HTTP_SERVICE = "org.osgi.service.http.HttpService"; private static final String HTTP_PORT = "org.osgi.service.http.port"; private static final String HTTP_PORT_SECURE = "org.osgi.service.http.port.secure"; - @Mock - private BundleContext bundleContext; + private @Mock BundleContext bundleContext; - @Before + @BeforeEach public void setup() throws InvalidSyntaxException { - initMocks(this); - ServiceReference[] httpServiceReferences = getHttpServiceReferences(); ServiceReference[] secureHttpServiceReferences = getSecureHttpServiceReferences(); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java index b13e7ee05..b189e353c 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java @@ -13,9 +13,9 @@ package org.openhab.core.net; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for NetUtil class diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/types/CommandDescriptionBuilderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/types/CommandDescriptionBuilderTest.java index 61f3bbf64..3cec4ea63 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/types/CommandDescriptionBuilderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/types/CommandDescriptionBuilderTest.java @@ -13,14 +13,14 @@ package org.openhab.core.types; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test the {@link CommandDescriptionBuilder}. @@ -31,7 +31,7 @@ public class CommandDescriptionBuilderTest { private CommandDescriptionBuilder builder; - @Before + @BeforeEach public void setup() { builder = CommandDescriptionBuilder.create(); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/types/StateDescriptionFragmentBuilderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/types/StateDescriptionFragmentBuilderTest.java index e1eb4bc4b..1072bbab6 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/types/StateDescriptionFragmentBuilderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/types/StateDescriptionFragmentBuilderTest.java @@ -13,15 +13,15 @@ package org.openhab.core.types; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.math.BigDecimal; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test the {@link StateDescriptionFragmentBuilder}. @@ -32,7 +32,7 @@ public class StateDescriptionFragmentBuilderTest { private StateDescriptionFragmentBuilder builder; - @Before + @BeforeEach public void setup() { builder = StateDescriptionFragmentBuilder.create(); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/types/util/UnitUtilsTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/types/util/UnitUtilsTest.java index e5bffafaf..f86b16178 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/types/util/UnitUtilsTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/types/util/UnitUtilsTest.java @@ -13,8 +13,9 @@ package org.openhab.core.types.util; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.openhab.core.library.unit.MetricPrefix.*; import javax.measure.Quantity; @@ -24,7 +25,8 @@ import javax.measure.quantity.Length; import javax.measure.quantity.Power; import javax.measure.quantity.Temperature; -import org.junit.Test; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.api.Test; import org.openhab.core.library.dimension.Intensity; import org.openhab.core.library.unit.ImperialUnits; import org.openhab.core.library.unit.MetricPrefix; @@ -34,6 +36,7 @@ import org.openhab.core.library.unit.SmartHomeUnits; /** * @author Henning Treu - Initial contribution */ +@NonNullByDefault public class UnitUtilsTest { @Test @@ -107,9 +110,13 @@ public class UnitUtilsTest { Unit unit = UnitUtils.parseUnit("°F"); assertNotNull(unit); - assertThat(UnitUtils.getDimensionName(unit), is(Temperature.class.getSimpleName())); + if (unit != null) { + assertThat(UnitUtils.getDimensionName(unit), is(Temperature.class.getSimpleName())); + } unit = UnitUtils.parseUnit("m"); assertNotNull(unit); - assertThat(UnitUtils.getDimensionName(unit), is(Length.class.getSimpleName())); + if (unit != null) { + assertThat(UnitUtils.getDimensionName(unit), is(Length.class.getSimpleName())); + } } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/HexUtilsTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/HexUtilsTest.java index 358aa1990..45acf28c5 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/HexUtilsTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/HexUtilsTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.util; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for {@link HexUtils}. diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java index 27103831a..5d76d8130 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java @@ -12,11 +12,12 @@ */ package org.openhab.core.util; +import static org.hamcrest.MatcherAssert.assertThat; + import java.util.function.Consumer; import org.hamcrest.core.IsEqual; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.common.AbstractUID; /** @@ -33,7 +34,7 @@ public class UIDUtilsTest { final String decoded = UIDUtils.decode(encoded); System.out.printf("in: %s%n encoded: %s%n decoded: %s%n equals: %b%n", in, encoded, decoded, in.equals(decoded)); - Assert.assertThat(decoded, IsEqual.equalTo(in)); + assertThat(decoded, IsEqual.equalTo(in)); }; test.accept("test"); test.accept("TEST"); diff --git a/itests/itest-include.bndrun b/itests/itest-include.bndrun index 51447a027..e3c6f03fc 100644 --- a/itests/itest-include.bndrun +++ b/itests/itest-include.bndrun @@ -2,10 +2,12 @@ ../../bom/runtime-index/target/index.xml;name="org.openhab.core.bom.runtime-index",\ ../../bom/test-index/target/index.xml;name="org.openhab.core.bom.test-index",\ ../../bom/openhab-core-index/target/local-index.xml;name="org.openhab.core.bom.openhab-core-index",\ - target/index.xml;name="self" + target/index.xml;name="self" -resolve.effective: active +-tester: biz.aQute.tester.junit-platform + # Run all integration tests which are named xyzTest Test-Cases: ${classes;CONCRETE;PUBLIC;NAMED;*Test} @@ -26,3 +28,7 @@ Export-Package: bnd.identity;id='org.apache.servicemix.specs.activation-api-1.1',\ bnd.identity;id='org.apache.servicemix.specs.annotation-api-1.3',\ bnd.identity;id='org.apache.servicemix.specs.jaxb-api-2.2' + +-runrequires.junit: \ + bnd.identity;id='biz.aQute.tester.junit-platform',\ + bnd.identity;id='junit-jupiter-engine' diff --git a/itests/org.openhab.core.auth.oauth2client.tests/itest.bndrun b/itests/org.openhab.core.auth.oauth2client.tests/itest.bndrun index 3e3e2e7ec..94291bfdc 100644 --- a/itests/org.openhab.core.auth.oauth2client.tests/itest.bndrun +++ b/itests/org.openhab.core.auth.oauth2client.tests/itest.bndrun @@ -15,8 +15,6 @@ Fragment-Host: org.openhab.core.auth.oauth2client org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ org.objenesis;version='[2.6.0,2.6.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ @@ -28,9 +26,6 @@ Fragment-Host: org.openhab.core.auth.oauth2client org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ @@ -47,4 +42,15 @@ Fragment-Host: org.openhab.core.auth.oauth2client org.openhab.core.auth.oauth2client.tests;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ - org.openhab.core.test;version='[3.0.0,3.0.1)' + org.openhab.core.test;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/cipher/CipherTest.java b/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/cipher/CipherTest.java index 828c14d8b..a0b9223a8 100644 --- a/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/cipher/CipherTest.java +++ b/itests/org.openhab.core.auth.oauth2client.tests/src/main/java/org/openhab/core/auth/oauth2client/test/internal/cipher/CipherTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.auth.oauth2client.test.internal.cipher; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @@ -22,8 +22,8 @@ import java.security.NoSuchAlgorithmException; import java.util.Dictionary; import java.util.Hashtable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.auth.oauth2client.internal.cipher.SymmetricKeyCipher; import org.osgi.framework.InvalidSyntaxException; import org.osgi.service.cm.Configuration; @@ -40,7 +40,7 @@ public class CipherTest { private SymmetricKeyCipher symmetricKeyCipher; - @Before + @BeforeEach public void setUp() throws IOException, InvalidSyntaxException, NoSuchAlgorithmException { symmetricKeyCipher = new SymmetricKeyCipher(mockConfigurationAdmin()); } @@ -48,12 +48,12 @@ public class CipherTest { @Test public void testEncDec() throws GeneralSecurityException { String cipherText = symmetricKeyCipher.encrypt(PLAIN_TEXT); - assertNotNull("Cipher text should not be null", cipherText); - assertNotEquals("Cipher text should not be the same as plaintext", PLAIN_TEXT, cipherText); + assertNotNull(cipherText, "Cipher text should not be null"); + assertNotEquals(PLAIN_TEXT, cipherText, "Cipher text should not be the same as plaintext"); String decryptedText = symmetricKeyCipher.decrypt(cipherText); - assertNotNull("Decrypted text should not be null", decryptedText); - assertEquals("Decrypted text should be same as before", PLAIN_TEXT, decryptedText); + assertNotNull(decryptedText, "Decrypted text should not be null"); + assertEquals(PLAIN_TEXT, decryptedText, "Decrypted text should be same as before"); } private ConfigurationAdmin mockConfigurationAdmin() throws IOException { diff --git a/itests/org.openhab.core.automation.integration.tests/itest.bndrun b/itests/org.openhab.core.automation.integration.tests/itest.bndrun index 851c1c1d9..10d6727c4 100644 --- a/itests/org.openhab.core.automation.integration.tests/itest.bndrun +++ b/itests/org.openhab.core.automation.integration.tests/itest.bndrun @@ -20,8 +20,6 @@ Bundle-SymbolicName: ${project.artifactId} org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ @@ -40,4 +38,62 @@ Bundle-SymbolicName: ${project.artifactId} org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\ + org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\ + org.apache.xbean.finder;version='[4.12.0,4.12.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.objectweb.asm;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\ + org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)' diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationJsonTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationJsonTest.java index 6762cea6d..615967468 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationJsonTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationJsonTest.java @@ -13,7 +13,8 @@ package org.openhab.core.automation.integration.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; import java.util.Collections; @@ -23,9 +24,9 @@ import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.ManagedRuleProvider; import org.openhab.core.automation.Rule; @@ -84,7 +85,7 @@ public class AutomationIntegrationJsonTest extends JavaOSGiTest { // keep storage rules imported from json files public static final VolatileStorageService VOLATILE_STORAGE_SERVICE = new VolatileStorageService(); - @Before + @BeforeEach public void before() { logger.info("@Before.begin"); @@ -168,7 +169,7 @@ public class AutomationIntegrationJsonTest extends JavaOSGiTest { logger.info("@Before.finish"); } - @After + @AfterEach public void after() { logger.info("@After"); } diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java index 1da91f8da..b403e456a 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java @@ -14,7 +14,8 @@ package org.openhab.core.automation.integration.test; import static java.util.stream.Collectors.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collection; @@ -31,9 +32,9 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Condition; import org.openhab.core.automation.ManagedRuleProvider; @@ -101,7 +102,7 @@ public class AutomationIntegrationTest extends JavaOSGiTest { private @Nullable Event ruleEvent; private @Nullable Event itemEvent; - @Before + @BeforeEach public void before() { logger.info("@Before.begin"); @@ -167,7 +168,7 @@ public class AutomationIntegrationTest extends JavaOSGiTest { logger.info("@Before.finish"); } - @After + @AfterEach public void after() { logger.info("@After"); } diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java index 91ed17a76..156d41b7d 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java @@ -13,15 +13,16 @@ package org.openhab.core.automation.integration.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.Arrays; import java.util.List; import java.util.Locale; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.type.ModuleTypeRegistry; import org.openhab.core.storage.StorageService; import org.openhab.core.test.java.JavaOSGiTest; @@ -92,7 +93,7 @@ public class HostFragmentSupportTest extends JavaOSGiTest { boolean waiting = true; - @Before + @BeforeEach public void before() { logger.info("@Before.begin"); @@ -111,7 +112,7 @@ public class HostFragmentSupportTest extends JavaOSGiTest { logger.info("@Before.finish"); } - @After + @AfterEach public void after() { logger.info("@After"); } diff --git a/itests/org.openhab.core.automation.module.core.tests/itest.bndrun b/itests/org.openhab.core.automation.module.core.tests/itest.bndrun index 0db7a61e0..bc3cfdffa 100644 --- a/itests/org.openhab.core.automation.module.core.tests/itest.bndrun +++ b/itests/org.openhab.core.automation.module.core.tests/itest.bndrun @@ -21,8 +21,6 @@ Fragment-Host: org.openhab.core.automation org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ @@ -41,4 +39,62 @@ Fragment-Host: org.openhab.core.automation org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\ + org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\ + org.apache.xbean.finder;version='[4.12.0,4.12.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.objectweb.asm;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\ + org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)' diff --git a/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java b/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java index 52661b5ae..7f72954e0 100644 --- a/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java +++ b/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RunRuleModuleTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.automation.internal.module; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; @@ -28,9 +28,8 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Rule; import org.openhab.core.automation.RuleManager; import org.openhab.core.automation.RuleRegistry; @@ -68,7 +67,7 @@ public class RunRuleModuleTest extends JavaOSGiTest { private final Logger logger = LoggerFactory.getLogger(RunRuleModuleTest.class); private final VolatileStorageService volatileStorageService = new VolatileStorageService(); - @Before + @BeforeEach public void before() { registerService(new ItemProvider() { @Override @@ -138,7 +137,7 @@ public class RunRuleModuleTest extends JavaOSGiTest { public void sceneActivatedByRule() throws ItemNotFoundException, InterruptedException { final RuleRegistry ruleRegistry = getService(RuleRegistry.class); final RuleManager ruleEngine = getService(RuleManager.class); - Assert.assertNotNull(ruleRegistry); + assertNotNull(ruleRegistry); // Scene rule @@ -148,7 +147,7 @@ public class RunRuleModuleTest extends JavaOSGiTest { ruleRegistry.add(sceneRule); ruleEngine.setEnabled(sceneRule.getUID(), true); waitForAssert(() -> { - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(sceneRule.getUID()).getStatus()); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(sceneRule.getUID()).getStatus()); }); // Outer rule @@ -159,16 +158,16 @@ public class RunRuleModuleTest extends JavaOSGiTest { ruleRegistry.add(outerRule); ruleEngine.setEnabled(outerRule.getUID(), true); waitForAssert(() -> { - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(outerRule.getUID()).getStatus()); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(outerRule.getUID()).getStatus()); }); // Test rule final EventPublisher eventPublisher = getService(EventPublisher.class); - Assert.assertNotNull(eventPublisher); + assertNotNull(eventPublisher); final ItemRegistry itemRegistry = getService(ItemRegistry.class); - Assert.assertNotNull(itemRegistry); + assertNotNull(itemRegistry); final Queue events = new LinkedList<>(); diff --git a/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RuntimeRuleTest.java b/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RuntimeRuleTest.java index 8bd2927e3..8b11e16df 100644 --- a/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RuntimeRuleTest.java +++ b/itests/org.openhab.core.automation.module.core.tests/src/main/java/org/openhab/core/automation/internal/module/RuntimeRuleTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.automation.internal.module; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.AbstractMap.SimpleEntry; import java.util.Arrays; @@ -28,10 +28,9 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Condition; import org.openhab.core.automation.Rule; import org.openhab.core.automation.RuleManager; @@ -75,7 +74,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { private final Logger logger = LoggerFactory.getLogger(RuntimeRuleTest.class); private final VolatileStorageService volatileStorageService = new VolatileStorageService(); - @Before + @BeforeEach public void before() { registerService(new ItemProvider() { @Override @@ -100,7 +99,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { } @Test - @Ignore + @Disabled public void testPredefinedRule() throws ItemNotFoundException, InterruptedException { final EventPublisher eventPublisher = getService(EventPublisher.class); final Queue events = new LinkedList<>(); @@ -157,12 +156,12 @@ public class RuntimeRuleTest extends JavaOSGiTest { ruleEngine.setEnabled(rule.getUID(), true); waitForAssert(() -> { - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(rule.getUID()).getStatus()); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(rule.getUID()).getStatus()); }); // Test rule final EventPublisher eventPublisher = getService(EventPublisher.class); - Assert.assertNotNull(eventPublisher); + assertNotNull(eventPublisher); eventPublisher.post(ItemEventFactory.createStateEvent("myPresenceItem2", OnOffType.ON)); @@ -200,11 +199,11 @@ public class RuntimeRuleTest extends JavaOSGiTest { public void modeTypesRegistration() { final ModuleTypeRegistry mtr = getService(ModuleTypeRegistry.class); waitForAssert(() -> { - Assert.assertNotNull(mtr.get("core.GenericEventTrigger")); - Assert.assertNotNull(mtr.get("core.GenericEventCondition")); - Assert.assertNotNull(mtr.get("core.ItemStateChangeTrigger")); - Assert.assertNotNull(mtr.get("core.ItemStateUpdateTrigger")); - Assert.assertNotNull(mtr.get(CompareConditionHandler.MODULE_TYPE)); + assertNotNull(mtr.get("core.GenericEventTrigger")); + assertNotNull(mtr.get("core.GenericEventCondition")); + assertNotNull(mtr.get("core.ItemStateChangeTrigger")); + assertNotNull(mtr.get("core.ItemStateUpdateTrigger")); + assertNotNull(mtr.get(CompareConditionHandler.MODULE_TYPE)); }); } @@ -225,9 +224,9 @@ public class RuntimeRuleTest extends JavaOSGiTest { final @Nullable Object input) { final boolean is = handler.isSatisfied(Collections.singletonMap("input", input)); if (expected) { - Assert.assertTrue(is); + assertTrue(is); } else { - Assert.assertFalse(is); + assertFalse(is); } } @@ -311,7 +310,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { assertSatisfiedHandlerInput(handler, false, "something matches?"); assertSatisfiedHandlerInput(handler, true, "anything matches?"); - Assert.assertFalse(handler.isSatisfied(Stream.of(new SimpleEntry<>("nothing", "nothing")) + assertFalse(handler.isSatisfied(Stream.of(new SimpleEntry<>("nothing", "nothing")) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())))); condition = ModuleBuilder.createCondition(condition) @@ -375,7 +374,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { // Test rule waitForAssert(() -> { - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(rule.getUID()).getStatus()); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatusInfo(rule.getUID()).getStatus()); }); final Queue events = new LinkedList<>(); @@ -416,7 +415,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { } @Test - @Ignore + @Disabled public void ruleEnableHandlerWorks() throws ItemNotFoundException { final RuleRegistry ruleRegistry = getService(RuleRegistry.class); final RuleManager ruleEngine = getService(RuleManager.class); @@ -456,11 +455,9 @@ public class RuntimeRuleTest extends JavaOSGiTest { TypeParser.parseCommand(myMotionItem.getAcceptedCommandTypes(), "ON"))); waitForAssert(() -> { - Assert.assertEquals(RuleStatusDetail.DISABLED, - ruleEngine.getStatusInfo(firstRuleUID).getStatusDetail()); - Assert.assertEquals(RuleStatusDetail.DISABLED, - ruleEngine.getStatusInfo(secondRuleUID).getStatusDetail()); - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatus(thirdRuleUID)); + assertEquals(RuleStatusDetail.DISABLED, ruleEngine.getStatusInfo(firstRuleUID).getStatusDetail()); + assertEquals(RuleStatusDetail.DISABLED, ruleEngine.getStatusInfo(secondRuleUID).getStatusDetail()); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatus(thirdRuleUID)); }); final Configuration triggerConfig2 = new Configuration( @@ -482,10 +479,9 @@ public class RuntimeRuleTest extends JavaOSGiTest { TypeParser.parseCommand(myMotionItem.getAcceptedCommandTypes(), "OFF"))); waitForAssert(() -> { - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatus(firstRuleUID)); - Assert.assertEquals(RuleStatusDetail.DISABLED, - ruleEngine.getStatusInfo(secondRuleUID).getStatusDetail()); - Assert.assertEquals(RuleStatus.IDLE, ruleEngine.getStatus(thirdRuleUID)); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatus(firstRuleUID)); + assertEquals(RuleStatusDetail.DISABLED, ruleEngine.getStatusInfo(secondRuleUID).getStatusDetail()); + assertEquals(RuleStatus.IDLE, ruleEngine.getStatus(thirdRuleUID)); }); } finally { ruleRegistry.remove(firstRuleUID); diff --git a/itests/org.openhab.core.automation.module.script.tests/itest.bndrun b/itests/org.openhab.core.automation.module.script.tests/itest.bndrun index 3acae4763..b1527563c 100644 --- a/itests/org.openhab.core.automation.module.script.tests/itest.bndrun +++ b/itests/org.openhab.core.automation.module.script.tests/itest.bndrun @@ -21,8 +21,6 @@ Fragment-Host: org.openhab.core.automation.module.script org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ @@ -42,4 +40,61 @@ Fragment-Host: org.openhab.core.automation.module.script org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\ + org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\ + org.apache.xbean.finder;version='[4.12.0,4.12.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.objectweb.asm;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\ + org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)' diff --git a/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/ScriptRuleOSGiTest.java b/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/ScriptRuleOSGiTest.java index d8964cde8..13fac86a3 100644 --- a/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/ScriptRuleOSGiTest.java +++ b/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/ScriptRuleOSGiTest.java @@ -13,7 +13,7 @@ package org.openhab.core.automation.module.script; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Arrays; import java.util.Collection; @@ -22,8 +22,8 @@ import java.util.Optional; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Condition; import org.openhab.core.automation.Rule; @@ -66,7 +66,7 @@ public class ScriptRuleOSGiTest extends JavaOSGiTest { public ScriptRuleOSGiTest() { } - @Before + @BeforeEach public void before() { @NonNullByDefault ItemProvider itemProvider = new ItemProvider() { diff --git a/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptScopeOSGiTest.java b/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptScopeOSGiTest.java index d0fd6fc12..189dc5241 100644 --- a/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptScopeOSGiTest.java +++ b/itests/org.openhab.core.automation.module.script.tests/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/ScriptScopeOSGiTest.java @@ -12,6 +12,8 @@ */ package org.openhab.core.automation.module.script.internal.defaultscope; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; @@ -19,8 +21,8 @@ import java.net.URL; import javax.script.ScriptEngine; import javax.script.ScriptException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.module.script.ScriptEngineContainer; import org.openhab.core.automation.module.script.ScriptEngineManager; import org.openhab.core.test.java.JavaOSGiTest; @@ -38,7 +40,7 @@ public class ScriptScopeOSGiTest extends JavaOSGiTest { private final String workingFile = "scopeWorking.js"; private final String failureFile = "scopeFailure.js"; - @Before + @BeforeEach public void init() { ScriptEngineManager scriptManager = getService(ScriptEngineManager.class); ScriptEngineContainer container = scriptManager.createScriptEngine("js", "myJSEngine"); @@ -51,9 +53,9 @@ public class ScriptScopeOSGiTest extends JavaOSGiTest { engine.eval(new InputStreamReader(url.openStream())); } - @Test(expected = ScriptException.class) + @Test public void testScopeDoesNotDefineFoobar() throws ScriptException, IOException { URL url = bundleContext.getBundle().getResource(path + failureFile); - engine.eval(new InputStreamReader(url.openStream())); + assertThrows(ScriptException.class, () -> engine.eval(new InputStreamReader(url.openStream()))); } } diff --git a/itests/org.openhab.core.automation.module.timer.tests/itest.bndrun b/itests/org.openhab.core.automation.module.timer.tests/itest.bndrun index 072f829ab..0f665bffa 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/itest.bndrun +++ b/itests/org.openhab.core.automation.module.timer.tests/itest.bndrun @@ -14,8 +14,6 @@ Fragment-Host: org.openhab.core.automation org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ com.google.gson;version='[2.8.2,2.8.3)',\ @@ -41,4 +39,62 @@ Fragment-Host: org.openhab.core.automation org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\ + org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\ + org.apache.xbean.finder;version='[4.12.0,4.12.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.objectweb.asm;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\ + org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)' diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java index 3ee1300d0..e70eaf2e5 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java @@ -13,7 +13,7 @@ package org.openhab.core.automation.module.timer.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.ArrayList; import java.util.Collection; @@ -25,8 +25,8 @@ import java.util.Random; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Condition; import org.openhab.core.automation.Rule; @@ -76,7 +76,7 @@ public abstract class BasicConditionHandlerTest extends JavaOSGiTest { * * @Before-annotated methods in sub-classes. */ - @Before + @BeforeEach public void beforeBase() { @NonNullByDefault ItemProvider itemProvider = new ItemProvider() { diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/DayOfWeekConditionHandlerTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/DayOfWeekConditionHandlerTest.java index 60b4974eb..598979088 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/DayOfWeekConditionHandlerTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/DayOfWeekConditionHandlerTest.java @@ -13,7 +13,7 @@ package org.openhab.core.automation.module.timer.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.text.SimpleDateFormat; import java.time.ZonedDateTime; @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.Date; import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Condition; import org.openhab.core.automation.internal.module.handler.DayOfWeekConditionHandler; import org.openhab.core.automation.type.ModuleTypeRegistry; diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java index 561b78b52..3f85ae23b 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/RuntimeRuleTest.java @@ -13,7 +13,7 @@ package org.openhab.core.automation.module.timer.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Collection; import java.util.Collections; @@ -24,8 +24,8 @@ import java.util.Map; import java.util.Random; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Rule; import org.openhab.core.automation.RuleManager; @@ -69,7 +69,7 @@ public class RuntimeRuleTest extends JavaOSGiTest { public RuntimeRuleTest() { } - @Before + @BeforeEach public void before() { ItemProvider itemProvider = new TestItemProvider(Collections.singleton(new SwitchItem("myLampItem"))); registerService(itemProvider); diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java index c5571b24f..7bb15b368 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayConditionHandlerTest.java @@ -13,7 +13,7 @@ package org.openhab.core.automation.module.timer.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.time.Duration; import java.time.LocalTime; @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Condition; import org.openhab.core.automation.internal.module.handler.DayOfWeekConditionHandler; import org.openhab.core.automation.internal.module.handler.TimeOfDayConditionHandler; diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayTriggerHandlerTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayTriggerHandlerTest.java index 55e6e9702..6ec729788 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayTriggerHandlerTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/TimeOfDayTriggerHandlerTest.java @@ -13,10 +13,10 @@ package org.openhab.core.automation.module.timer.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.RuleRegistry; import org.openhab.core.automation.internal.module.handler.TimeOfDayTriggerHandler; import org.openhab.core.automation.type.ModuleTypeRegistry; @@ -36,7 +36,7 @@ public class TimeOfDayTriggerHandlerTest extends JavaOSGiTest { public TimeOfDayTriggerHandlerTest() { } - @Before + @BeforeEach public void before() { registerService(volatileStorageService); waitForAssert(() -> { diff --git a/itests/org.openhab.core.automation.tests/itest.bndrun b/itests/org.openhab.core.automation.tests/itest.bndrun index 63e29e3fc..f3d9fc658 100644 --- a/itests/org.openhab.core.automation.tests/itest.bndrun +++ b/itests/org.openhab.core.automation.tests/itest.bndrun @@ -21,8 +21,6 @@ Fragment-Host: org.openhab.core.automation org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ @@ -41,4 +39,62 @@ Fragment-Host: org.openhab.core.automation org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\ + org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\ + org.apache.xbean.finder;version='[4.12.0,4.12.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.objectweb.asm;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\ + org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)' diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java index 3c04bf9d7..cb013a5d3 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java @@ -13,7 +13,8 @@ package org.openhab.core.automation.event; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.ArrayList; import java.util.Arrays; @@ -29,8 +30,8 @@ import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Rule; import org.openhab.core.automation.RuleManager; @@ -78,7 +79,7 @@ public class RuleEventTest extends JavaOSGiTest { public RuleEventTest() { } - @Before + @BeforeEach public void before() { ItemProvider itemProvider = new ItemProvider() { diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java index 3d3e314ff..334fd63ed 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java @@ -12,6 +12,8 @@ */ package org.openhab.core.automation.internal; +import static org.junit.jupiter.api.Assertions.*; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; @@ -20,10 +22,9 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Action; import org.openhab.core.automation.Condition; import org.openhab.core.automation.Rule; @@ -52,7 +53,7 @@ public class RuleEngineTest extends JavaOSGiTest { private RuleEngineImpl ruleEngine; private RuleRegistry ruleRegistry; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); ruleEngine = (RuleEngineImpl) getService(RuleManager.class); @@ -65,47 +66,47 @@ public class RuleEngineTest extends JavaOSGiTest { * */ @Test - @Ignore + @Disabled public void testAutoMapRuleConnections() { RuleImpl rule = createAutoMapRule(); // check condition connections Map conditionInputs = rule.getConditions().get(0).getInputs(); - Assert.assertEquals("Number of user define condition inputs", 1, conditionInputs.size()); - Assert.assertTrue("Check user define condition connection", - "triggerId.triggerOutput".equals(conditionInputs.get("conditionInput"))); + assertEquals(1, conditionInputs.size(), "Number of user define condition inputs"); + assertEquals("triggerId.triggerOutput", conditionInputs.get("conditionInput"), + "Check user define condition connection"); // check action connections Map actionInputs = rule.getActions().get(0).getInputs(); - Assert.assertEquals("Number of user define action inputs", 2, actionInputs.size()); - Assert.assertTrue("Check user define action connections for input actionInput", - "triggerId.triggerOutput".equals(actionInputs.get("actionInput"))); - Assert.assertTrue("Check user define action connections for input in6", - "triggerId.triggerOutput".equals(actionInputs.get("in6"))); + assertEquals(2, actionInputs.size(), "Number of user define action inputs"); + assertEquals("triggerId.triggerOutput", actionInputs.get("actionInput"), + "Check user define action connections for input actionInput"); + assertEquals("triggerId.triggerOutput", actionInputs.get("in6"), + "Check user define action connections for input in6"); // do connections auto mapping ruleRegistry.add(rule); Rule ruleGet = ruleEngine.getRule("AutoMapRule"); - Assert.assertEquals("Returned rule with wrong UID", "AutoMapRule", ruleGet.getUID()); + assertEquals("AutoMapRule", ruleGet.getUID(), "Returned rule with wrong UID"); // check condition connections conditionInputs = ruleGet.getConditions().get(0).getInputs(); - Assert.assertEquals("Number of user define condition inputs", 2, conditionInputs.size()); - Assert.assertEquals("Check user define condition connection", "triggerId.triggerOutput", - conditionInputs.get("conditionInput")); - Assert.assertEquals("Auto map condition input in2[tagA, tagB] to trigger output out3[tagA, tagB, tagC]", - "triggerId.out3", conditionInputs.get("in2")); + assertEquals(2, conditionInputs.size(), "Number of user define condition inputs"); + assertEquals("triggerId.triggerOutput", conditionInputs.get("conditionInput"), + "Check user define condition connection"); + assertEquals("triggerId.out3", conditionInputs.get("in2"), + "Auto map condition input in2[tagA, tagB] to trigger output out3[tagA, tagB, tagC]"); // check action connections actionInputs = ruleGet.getActions().get(0).getInputs(); - Assert.assertEquals("Number of user define action inputs", 4, actionInputs.size()); - Assert.assertTrue("Check user define action connections for input actionInput", - "triggerId.triggerOutput".equals(actionInputs.get("actionInput"))); - Assert.assertEquals("Check user define action connections for input in6 is not changed by the auto mapping", - "triggerId.triggerOutput", actionInputs.get("in6")); - Assert.assertEquals("Auto map action input in5[tagA, tagB, tagC] to trigger output out3[tagA, tagB, tagC]", - "triggerId.out3", actionInputs.get("in5")); - Assert.assertEquals("Auto map action input in5[tagD, tagE] to action output out5[tagD, tagE]", "actionId.out5", - actionInputs.get("in4")); + assertEquals(4, actionInputs.size(), "Number of user define action inputs"); + assertEquals("triggerId.triggerOutput", actionInputs.get("actionInput"), + "Check user define action connections for input actionInput"); + assertEquals("triggerId.triggerOutput", actionInputs.get("in6"), + "Check user define action connections for input in6 is not changed by the auto mapping"); + assertEquals("triggerId.out3", actionInputs.get("in5"), + "Auto map action input in5[tagA, tagB, tagC] to trigger output out3[tagA, tagB, tagC]"); + assertEquals("actionId.out5", actionInputs.get("in4"), + "Auto map action input in5[tagD, tagE] to action output out5[tagD, tagE]"); } /** @@ -128,14 +129,14 @@ public class RuleEngineTest extends JavaOSGiTest { ruleRegistry.add(rule2); Rule rule1Get = ruleEngine.getRule("ruleWithTag1"); - Assert.assertNotNull("Cannot find rule by UID", rule1Get); - Assert.assertNotNull("rule.getTags is null", rule1Get.getTags()); - Assert.assertEquals("rule.getTags is empty", 1, rule1Get.getTags().size()); + assertNotNull(rule1Get, "Cannot find rule by UID"); + assertNotNull(rule1Get.getTags(), "rule.getTags is null"); + assertEquals(1, rule1Get.getTags().size(), "rule.getTags is empty"); Rule rule2Get = ruleEngine.getRule("ruleWithTags12"); - Assert.assertNotNull("Cannot find rule by UID", rule2Get); - Assert.assertNotNull("rule.getTags is null", rule2Get.getTags()); - Assert.assertEquals("rule.getTags is empty", 2, rule2Get.getTags().size()); + assertNotNull(rule2Get, "Cannot find rule by UID"); + assertNotNull(rule2Get.getTags(), "rule.getTags is null"); + assertEquals(2, rule2Get.getTags().size(), "rule.getTags is empty"); } /** @@ -148,7 +149,7 @@ public class RuleEngineTest extends JavaOSGiTest { .withConditions(createConditions("typeUID")).withActions(createActions("typeUID")).build(); ruleRegistry.add(rule3); Rule rule3Get = ruleEngine.getRule("rule3"); - Assert.assertNotNull("RuleImpl configuration is null", rule3Get.getConfiguration()); + assertNotNull(rule3Get.getConfiguration(), "RuleImpl configuration is null"); } /** @@ -168,19 +169,18 @@ public class RuleEngineTest extends JavaOSGiTest { Rule rule4Get = ruleEngine.getRule("rule4"); Configuration rule4cfg = rule4Get.getConfiguration(); List rule4cfgD = rule4Get.getConfigurationDescriptions(); - Assert.assertNotNull("RuleImpl configuration is null", rule4cfg); - Assert.assertTrue("Missing config property in rule copy", rule4cfg.containsKey("config1")); - Assert.assertEquals("Wrong config value", new BigDecimal(5), rule4cfg.get("config1")); + assertNotNull(rule4cfg, "RuleImpl configuration is null"); + assertTrue(rule4cfg.containsKey("config1"), "Missing config property in rule copy"); + assertEquals(new BigDecimal(5), rule4cfg.get("config1"), "Wrong config value"); - Assert.assertNotNull("RuleImpl configuration description is null", rule4cfgD); - Assert.assertEquals("Missing config description in rule copy", 1, rule4cfgD.size()); + assertNotNull(rule4cfgD, "RuleImpl configuration description is null"); + assertEquals(1, rule4cfgD.size(), "Missing config description in rule copy"); ConfigDescriptionParameter rule4cfgDP = rule4cfgD.iterator().next(); - Assert.assertEquals("Wrong default value in config description", "3", rule4cfgDP.getDefault()); - Assert.assertEquals("Wrong context value in config description", "context1", rule4cfgDP.getContext()); - Assert.assertNotNull("Null options in config description", rule4cfgDP.getOptions()); - Assert.assertEquals("Wrong option value in config description", "1", rule4cfgDP.getOptions().get(0).getValue()); - Assert.assertEquals("Wrong option label in config description", "one", - rule4cfgDP.getOptions().get(0).getLabel()); + assertEquals("3", rule4cfgDP.getDefault(), "Wrong default value in config description"); + assertEquals("context1", rule4cfgDP.getContext(), "Wrong context value in config description"); + assertNotNull(rule4cfgDP.getOptions(), "Null options in config description"); + assertEquals("1", rule4cfgDP.getOptions().get(0).getValue(), "Wrong option value in config description"); + assertEquals("one", rule4cfgDP.getOptions().get(0).getLabel(), "Wrong option label in config description"); } /** @@ -195,27 +195,26 @@ public class RuleEngineTest extends JavaOSGiTest { Rule rule1Get = ruleEngine.getRule("rule1"); List actionsGet = rule1Get.getActions(); - Assert.assertNotNull("Null actions list", actionsGet); - Assert.assertEquals("Empty actions list", 1, actionsGet.size()); - Assert.assertEquals("Returned actions list should not be a copy", actionsGet, rule1Get.getActions()); + assertNotNull(actionsGet, "Null actions list"); + assertEquals(1, actionsGet.size(), "Empty actions list"); + assertEquals(actionsGet, rule1Get.getActions(), "Returned actions list should not be a copy"); actions.add(ModuleBuilder.createAction().withId("actionId2").withTypeUID("typeUID2").build()); rule1.setActions(actions); ruleEngine.addRule(rule1); rule1Get = ruleEngine.getRule("rule1"); List actionsGet2 = rule1Get.getActions(); - Assert.assertNotNull("Null actions list", actionsGet2); - Assert.assertEquals("Action was not added to the rule's list of actions", 2, actionsGet2.size()); - Assert.assertNotNull("RuleImpl action with wrong id is returned", rule1Get.getModule("actionId2")); + assertNotNull(actionsGet2, "Null actions list"); + assertEquals(2, actionsGet2.size(), "Action was not added to the rule's list of actions"); + assertNotNull(rule1Get.getModule("actionId2"), "RuleImpl action with wrong id is returned"); actions.add(ModuleBuilder.createAction().withId("actionId3").withTypeUID("typeUID3").build()); ruleEngine.addRule(rule1); // ruleEngine.update will update the RuleImpl2.moduleMap with the new module rule1Get = ruleEngine.getRule("rule1"); List actionsGet3 = rule1Get.getActions(); - Assert.assertNotNull("Null actions list", actionsGet3); - Assert.assertEquals("Action was not added to the rule's list of actions", 3, actionsGet3.size()); - Assert.assertNotNull("RuleImpl modules map was not updated", - ruleEngine.getRule("rule1").getModule("actionId3")); + assertNotNull(actionsGet3, "Null actions list"); + assertEquals(3, actionsGet3.size(), "Action was not added to the rule's list of actions"); + assertNotNull(ruleEngine.getRule("rule1").getModule("actionId3"), "RuleImpl modules map was not updated"); } /** @@ -229,9 +228,9 @@ public class RuleEngineTest extends JavaOSGiTest { ruleRegistry.add(rule1); Rule rule1Get = ruleEngine.getRule("rule1"); List triggersGet = rule1Get.getTriggers(); - Assert.assertNotNull("Null triggers list", triggersGet); - Assert.assertEquals("Empty triggers list", 1, triggersGet.size()); - Assert.assertEquals("Returned triggers list should not be a copy", triggersGet, rule1Get.getTriggers()); + assertNotNull(triggersGet, "Null triggers list"); + assertEquals(1, triggersGet.size(), "Empty triggers list"); + assertEquals(triggersGet, rule1Get.getTriggers(), "Returned triggers list should not be a copy"); triggers.add(ModuleBuilder.createTrigger().withId("triggerId2").withTypeUID("typeUID2").build()); rule1.setTriggers(triggers); @@ -240,11 +239,10 @@ public class RuleEngineTest extends JavaOSGiTest { // module Rule rule2Get = ruleEngine.getRule("rule1"); List triggersGet2 = rule2Get.getTriggers(); - Assert.assertNotNull("Null triggers list", triggersGet2); - Assert.assertEquals("Trigger was not added to the rule's list of triggers", 2, triggersGet2.size()); - Assert.assertEquals("Returned triggers list should not be a copy", triggersGet2, rule2Get.getTriggers()); - Assert.assertNotNull("RuleImpl trigger with wrong id is returned: " + triggersGet2, - rule2Get.getModule("triggerId2")); + assertNotNull(triggersGet2, "Null triggers list"); + assertEquals(2, triggersGet2.size(), "Trigger was not added to the rule's list of triggers"); + assertEquals(triggersGet2, rule2Get.getTriggers(), "Returned triggers list should not be a copy"); + assertNotNull(rule2Get.getModule("triggerId2"), "RuleImpl trigger with wrong id is returned: " + triggersGet2); } /** @@ -257,20 +255,20 @@ public class RuleEngineTest extends JavaOSGiTest { ruleRegistry.add(rule1); Rule rule1Get = ruleEngine.getRule("rule1"); List conditionsGet = rule1Get.getConditions(); - Assert.assertNotNull("Null conditions list", conditionsGet); - Assert.assertEquals("Empty conditions list", 1, conditionsGet.size()); - Assert.assertEquals("Returned conditions list should not be a copy", conditionsGet, rule1Get.getConditions()); + assertNotNull(conditionsGet, "Null conditions list"); + assertEquals(1, conditionsGet.size(), "Empty conditions list"); + assertEquals(conditionsGet, rule1Get.getConditions(), "Returned conditions list should not be a copy"); conditions.add(ModuleBuilder.createCondition().withId("conditionId2").withTypeUID("typeUID2").build()); rule1.setConditions(conditions); ruleEngine.addRule(rule1); // ruleEngine.update will update the RuleImpl2.moduleMap with the new module Rule rule2Get = ruleEngine.getRule("rule1"); List conditionsGet2 = rule2Get.getConditions(); - Assert.assertNotNull("Null conditions list", conditionsGet2); - Assert.assertEquals("Condition was not added to the rule's list of conditions", 2, conditionsGet2.size()); - Assert.assertEquals("Returned conditions list should not be a copy", conditionsGet2, rule2Get.getConditions()); - Assert.assertNotNull("RuleImpl condition with wrong id is returned: " + conditionsGet2, - rule2Get.getModule("conditionId2")); + assertNotNull(conditionsGet2, "Null conditions list"); + assertEquals(2, conditionsGet2.size(), "Condition was not added to the rule's list of conditions"); + assertEquals(conditionsGet2, rule2Get.getConditions(), "Returned conditions list should not be a copy"); + assertNotNull(rule2Get.getModule("conditionId2"), + "RuleImpl condition with wrong id is returned: " + conditionsGet2); } private RuleImpl createRule() { diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java index e30831c01..b4da3d5c3 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java @@ -12,6 +12,7 @@ */ package org.openhab.core.automation.internal; +import static org.junit.jupiter.api.Assertions.*; import static org.openhab.core.automation.RulePredicates.*; import java.util.Collection; @@ -20,9 +21,8 @@ import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Rule; import org.openhab.core.automation.RuleRegistry; import org.openhab.core.test.java.JavaOSGiTest; @@ -36,7 +36,7 @@ public class RuleRegistryTest extends JavaOSGiTest { private RuleRegistry ruleRegistry; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); ruleRegistry = getService(RuleRegistry.class); @@ -60,7 +60,7 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking RuleRegistry //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 0, ruleRegistry.getAll().size()); + assertEquals(0, ruleRegistry.getAll().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule without tag @@ -70,23 +70,23 @@ public class RuleRegistryTest extends JavaOSGiTest { final RuleImpl ruleWithoutTag = new RuleImpl(name); addedRule = ruleRegistry.add(ruleWithoutTag); - Assert.assertNotNull("RuleImpl for:" + name, addedRule); + assertNotNull(addedRule, "RuleImpl for:" + name); getRule = ruleRegistry.get(name); - Assert.assertNotNull("RuleImpl for:" + name, getRule); + assertNotNull(getRule, "RuleImpl for:" + name); - Assert.assertEquals("RuleImpl list size", 1, ruleRegistry.getAll().size()); + assertEquals(1, ruleRegistry.getAll().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 1, ruleRegistry.stream().collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), + "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule with 1 tag @@ -100,36 +100,36 @@ public class RuleRegistryTest extends JavaOSGiTest { ruleWithTag1.setTags(tags); addedRule = ruleRegistry.add(ruleWithTag1); - Assert.assertNotNull("RuleImpl for:" + name, addedRule); + assertNotNull(addedRule, "RuleImpl for:" + name); getRule = ruleRegistry.get(name); - Assert.assertNotNull("RuleImpl for:" + name, getRule); + assertNotNull(getRule, "RuleImpl for:" + name); - Assert.assertEquals("RuleImpl list size", 2, ruleRegistry.getAll().size()); + assertEquals(2, ruleRegistry.getAll().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 2, ruleRegistry.stream().collect(Collectors.toList()).size()); + assertEquals(2, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); Collection rulesWithTag1 = ruleRegistry.getByTags(tag1); - Assert.assertEquals("RuleImpl list size", 1, rulesWithTag1.size()); + assertEquals(1, rulesWithTag1.size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(), + "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule with 2 tags @@ -144,58 +144,58 @@ public class RuleRegistryTest extends JavaOSGiTest { ruleWithTag1Tag2.setTags(tags); addedRule = ruleRegistry.add(ruleWithTag1Tag2); - Assert.assertNotNull("RuleImpl for:" + name, addedRule); + assertNotNull(addedRule, "RuleImpl for:" + name); getRule = ruleRegistry.get(name); - Assert.assertNotNull("RuleImpl for:" + name, getRule); + assertNotNull(getRule, "RuleImpl for:" + name); - Assert.assertEquals("RuleImpl list size", 3, ruleRegistry.getAll().size()); + assertEquals(3, ruleRegistry.getAll().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 3, ruleRegistry.stream().collect(Collectors.toList()).size()); + assertEquals(3, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); rulesWithTag1 = ruleRegistry.getByTags(tag1); - Assert.assertEquals("RuleImpl list size", 2, rulesWithTag1.size()); + assertEquals(2, rulesWithTag1.size(), "RuleImpl list size"); Collection rulesWithTag2 = ruleRegistry.getByTags(tag2); - Assert.assertEquals("RuleImpl list size", 1, rulesWithTag2.size()); + assertEquals(1, rulesWithTag2.size(), "RuleImpl list size"); Collection rulesWithAllOfTag1Tag2 = ruleRegistry.getByTags(tag1, tag2); - Assert.assertEquals("RuleImpl list size", 1, rulesWithAllOfTag1Tag2.size()); + assertEquals(1, rulesWithAllOfTag1Tag2.size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size()); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, ruleRegistry.stream() - .filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))) + .collect(Collectors.toList()).size(), "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size()); + assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, ruleRegistry.stream() - .filter(hasAllTags(tag1).and(hasAllTags(tag2))).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1).and(hasAllTags(tag2))) + .collect(Collectors.toList()).size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule with 3 tags @@ -211,78 +211,79 @@ public class RuleRegistryTest extends JavaOSGiTest { ruleWithTag1Tag2Tag3.setTags(tags); addedRule = ruleRegistry.add(ruleWithTag1Tag2Tag3); - Assert.assertNotNull("RuleImpl for:" + name, addedRule); + assertNotNull(addedRule, "RuleImpl for:" + name); getRule = ruleRegistry.get(name); - Assert.assertNotNull("RuleImpl for:" + name, getRule); + assertNotNull(getRule, "RuleImpl for:" + name); - Assert.assertEquals("RuleImpl list size", 4, ruleRegistry.getAll().size()); + assertEquals(4, ruleRegistry.getAll().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 4, ruleRegistry.stream().collect(Collectors.toList()).size()); + assertEquals(4, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); rulesWithTag1 = ruleRegistry.getByTags(tag1); - Assert.assertEquals("RuleImpl list size", 3, rulesWithTag1.size()); + assertEquals(3, rulesWithTag1.size(), "RuleImpl list size"); rulesWithTag2 = ruleRegistry.getByTags(tag2); - Assert.assertEquals("RuleImpl list size", 2, rulesWithTag2.size()); + assertEquals(2, rulesWithTag2.size(), "RuleImpl list size"); Collection rulesWithTag3 = ruleRegistry.getByTags(tag3); - Assert.assertEquals("RuleImpl list size", 1, rulesWithTag3.size()); + assertEquals(1, rulesWithTag3.size(), "RuleImpl list size"); rulesWithAllOfTag1Tag2 = ruleRegistry.getByTags(tag1, tag2); - Assert.assertEquals("RuleImpl list size", 2, rulesWithAllOfTag1Tag2.size()); + assertEquals(2, rulesWithAllOfTag1Tag2.size(), "RuleImpl list size"); Collection rulesWithAllTag1Tag3 = ruleRegistry.getByTags(tag1, tag3); - Assert.assertEquals("RuleImpl list size", 1, rulesWithAllTag1Tag3.size()); + assertEquals(1, rulesWithAllTag1Tag3.size(), "RuleImpl list size"); Collection rulesWithAllOfTag1Tag2Tag3 = ruleRegistry.getByTags(tag1, tag2, tag3); - Assert.assertEquals("RuleImpl list size", 1, rulesWithAllOfTag1Tag2Tag3.size()); + assertEquals(1, rulesWithAllOfTag1Tag2Tag3.size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 3, - ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 3, - ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 3, - ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 3, - ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2, tag3)).collect(Collectors.toList()).size()); + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(3, + ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2, tag3)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAnyOfTags(tag2, tag3)).collect(Collectors.toList()).size()); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2, tag3)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 2, ruleRegistry.stream() - .filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))).collect(Collectors.toList()).size()); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))) + .collect(Collectors.toList()).size(), "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, ruleRegistry.stream() - .filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag3))).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 1, ruleRegistry.stream() - .filter(hasAnyOfTags(tag2).and(hasAnyOfTags(tag3))).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag3))) + .collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2).and(hasAnyOfTags(tag3))) + .collect(Collectors.toList()).size(), "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAnyOfTags(tag3)).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag3)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 3, - ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size()); + assertEquals(3, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 2, - ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size()); + assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size(), + "RuleImpl list size"); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size()); - Assert.assertEquals("RuleImpl list size", 1, - ruleRegistry.stream().filter(hasAllTags(tag1, tag2, tag3)).collect(Collectors.toList()).size()); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(), + "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2, tag3)).collect(Collectors.toList()).size(), + "RuleImpl list size"); } } diff --git a/itests/org.openhab.core.binding.xml.tests/itest.bndrun b/itests/org.openhab.core.binding.xml.tests/itest.bndrun index e70308757..a24471a2a 100644 --- a/itests/org.openhab.core.binding.xml.tests/itest.bndrun +++ b/itests/org.openhab.core.binding.xml.tests/itest.bndrun @@ -15,8 +15,6 @@ Fragment-Host: org.openhab.core.binding.xml org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ @@ -39,4 +37,12 @@ Fragment-Host: org.openhab.core.binding.xml org.openhab.core.binding.xml.tests;version='[3.0.0,3.0.1)',\ org.openhab.core.config.core;version='[3.0.0,3.0.1)',\ org.openhab.core.config.xml;version='[3.0.0,3.0.1)',\ - org.openhab.core.test;version='[3.0.0,3.0.1)' + org.openhab.core.test;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoI18nTest.java b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoI18nTest.java index 6b69045ad..cc26bd5a4 100644 --- a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoI18nTest.java +++ b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoI18nTest.java @@ -13,15 +13,15 @@ package org.openhab.core.binding.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Dictionary; import java.util.Hashtable; import java.util.Locale; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.binding.BindingInfo; import org.openhab.core.binding.BindingInfoRegistry; import org.openhab.core.i18n.LocaleProvider; @@ -40,7 +40,7 @@ public class BindingInfoI18nTest extends JavaOSGiTest { private BindingInfoRegistry bindingInfoRegistry; private BindingInstaller bindingInstaller; - @Before + @BeforeEach public void setUp() { bindingInfoRegistry = getService(BindingInfoRegistry.class); assertThat(bindingInfoRegistry, is(notNullValue())); diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoTest.java b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoTest.java index 9289059be..36325dccd 100644 --- a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoTest.java +++ b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInfoTest.java @@ -13,15 +13,15 @@ package org.openhab.core.binding.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.net.URI; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.binding.BindingInfo; import org.openhab.core.binding.BindingInfoRegistry; import org.openhab.core.config.core.ConfigDescription; @@ -42,7 +42,7 @@ public class BindingInfoTest extends JavaOSGiTest { private ConfigDescriptionRegistry configDescriptionRegistry; private BindingInstaller bindingInstaller; - @Before + @BeforeEach public void setUp() { bindingInfoRegistry = getService(BindingInfoRegistry.class); assertThat(bindingInfoRegistry, is(notNullValue())); diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInstaller.java b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInstaller.java index 4047e557c..f9836d2bd 100644 --- a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInstaller.java +++ b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/openhab/core/binding/xml/test/BindingInstaller.java @@ -13,7 +13,7 @@ package org.openhab.core.binding.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.function.Consumer; diff --git a/itests/org.openhab.core.config.core.tests/itest.bndrun b/itests/org.openhab.core.config.core.tests/itest.bndrun index 2453e12bb..c37f2077a 100644 --- a/itests/org.openhab.core.config.core.tests/itest.bndrun +++ b/itests/org.openhab.core.config.core.tests/itest.bndrun @@ -16,8 +16,6 @@ Fragment-Host: org.openhab.core.config.core org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -28,9 +26,6 @@ Fragment-Host: org.openhab.core.config.core org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\ @@ -40,4 +35,15 @@ Fragment-Host: org.openhab.core.config.core org.openhab.core;version='[3.0.0,3.0.1)',\ org.openhab.core.config.core;version='[3.0.0,3.0.1)',\ org.openhab.core.config.core.tests;version='[3.0.0,3.0.1)',\ - org.openhab.core.test;version='[3.0.0,3.0.1)' + org.openhab.core.test;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java index 238f29e22..3c09d19c9 100644 --- a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java +++ b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java @@ -13,8 +13,8 @@ package org.openhab.core.config.core; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -24,8 +24,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; /** @@ -41,7 +41,7 @@ public class ConfigOptionRegistryOSGiTest extends JavaOSGiTest { private ConfigOptionProvider configOptionsProviderMock; private URI dummyURI; - @Before + @BeforeEach public void setUp() throws URISyntaxException { // Register config registry configDescriptionRegistry = getService(ConfigDescriptionRegistry.class); diff --git a/itests/org.openhab.core.config.discovery.mdns.tests/itest.bndrun b/itests/org.openhab.core.config.discovery.mdns.tests/itest.bndrun index 3576ec793..1cfc190f7 100644 --- a/itests/org.openhab.core.config.discovery.mdns.tests/itest.bndrun +++ b/itests/org.openhab.core.config.discovery.mdns.tests/itest.bndrun @@ -15,8 +15,6 @@ Fragment-Host: org.openhab.core.config.discovery.mdns org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ javax.jmdns;version='[3.5.5,3.5.6)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ @@ -42,4 +40,12 @@ Fragment-Host: org.openhab.core.config.discovery.mdns org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.io.transport.mdns;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.config.discovery.mdns.tests/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryServiceOSGiTest.java b/itests/org.openhab.core.config.discovery.mdns.tests/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryServiceOSGiTest.java index dfb990eca..082697021 100644 --- a/itests/org.openhab.core.config.discovery.mdns.tests/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryServiceOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.mdns.tests/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryServiceOSGiTest.java @@ -13,14 +13,14 @@ package org.openhab.core.config.discovery.mdns.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.openhab.core.config.discovery.DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY; import java.io.IOException; import java.util.Hashtable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.discovery.DiscoveryService; import org.openhab.core.test.java.JavaOSGiTest; import org.osgi.service.cm.Configuration; @@ -35,7 +35,7 @@ public class MDNSDiscoveryServiceOSGiTest extends JavaOSGiTest { private MDNSDiscoveryService mdnsDiscoveryService; - @Before + @BeforeEach public void setup() { mdnsDiscoveryService = getService(DiscoveryService.class, MDNSDiscoveryService.class); assertThat(mdnsDiscoveryService, is(notNullValue())); diff --git a/itests/org.openhab.core.config.discovery.tests/itest.bndrun b/itests/org.openhab.core.config.discovery.tests/itest.bndrun index 11a5ce474..25d6a3280 100644 --- a/itests/org.openhab.core.config.discovery.tests/itest.bndrun +++ b/itests/org.openhab.core.config.discovery.tests/itest.bndrun @@ -19,8 +19,6 @@ Fragment-Host: org.openhab.core.config.discovery org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -31,9 +29,6 @@ Fragment-Host: org.openhab.core.config.discovery org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\ @@ -48,4 +43,15 @@ Fragment-Host: org.openhab.core.config.discovery org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ org.openhab.core.thing;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing.xml;version='[3.0.0,3.0.1)' + org.openhab.core.thing.xml;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java index f23f75a7f..90151e217 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/DiscoveryServiceRegistryOSGiTest.java @@ -13,17 +13,18 @@ package org.openhab.core.config.discovery; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.config.discovery.inbox.Inbox; import org.openhab.core.test.java.JavaOSGiTest; @@ -80,12 +81,14 @@ public class DiscoveryServiceRegistryOSGiTest extends JavaOSGiTest { private ThingRegistry thingRegistry; private Inbox inbox; - @Mock - private DiscoveryListener mockDiscoveryListener; + private AutoCloseable mocksCloseable; + + private @Mock DiscoveryListener mockDiscoveryListener; + + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); - @Before - public void setUp() { - initMocks(this); registerVolatileStorageService(); thingRegistry = getService(ThingRegistry.class); @@ -121,8 +124,10 @@ public class DiscoveryServiceRegistryOSGiTest extends JavaOSGiTest { discoveryServiceRegistry = getService(DiscoveryServiceRegistry.class); } - @After - public void cleanUp() { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + discoveryServiceFaultyMock.abortScan(); discoveryServiceMockForBinding1.abortScan(); discoveryServiceMockForBinding2.abortScan(); diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java index 1e560bb79..4f240ed2d 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java @@ -12,14 +12,14 @@ */ package org.openhab.core.config.discovery.inbox; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultBuilder; @@ -78,7 +78,7 @@ public class DynamicThingUpdateOSGiTest extends JavaOSGiTest { private volatile @NonNullByDefault({}) ThingHandlerCallback callback; - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java index 1a5132ca8..cf87bd37a 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java @@ -15,7 +15,8 @@ package org.openhab.core.config.discovery.internal; import static java.util.Collections.singleton; import static java.util.stream.Collectors.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import static org.openhab.core.config.discovery.inbox.InboxPredicates.*; @@ -37,9 +38,9 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionBuilder; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -170,7 +171,7 @@ public class InboxOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) ManagedThingProvider managedThingProvider; private @NonNullByDefault({}) ThingRegistry registry; - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); @@ -192,7 +193,7 @@ public class InboxOSGiTest extends JavaOSGiTest { inbox.addThingHandlerFactory(new DummyThingHandlerFactory(componentContextMock)); } - @After + @AfterEach public void cleanUp() { discoveryResults.forEach((thingUID, discoveryResult) -> inbox.remove(thingUID)); inboxListeners.forEach(listener -> inbox.removeInboxListener(listener)); @@ -851,9 +852,9 @@ public class InboxOSGiTest extends JavaOSGiTest { }); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatApproveThrowsIllegalArgumentExceptionIfNoDiscoveryResultForGivenThingUIDisAvailable() { - inbox.approve(new ThingUID("1234"), "label"); + assertThrows(IllegalArgumentException.class, () -> inbox.approve(new ThingUID("1234"), "label")); } @Test diff --git a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/itest.bndrun b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/itest.bndrun index 2d6eb67e4..872a0087f 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/itest.bndrun +++ b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/itest.bndrun @@ -22,14 +22,9 @@ Fragment-Host: org.openhab.core.config.discovery.usbserial.linuxsysfs org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ @@ -45,5 +40,16 @@ Fragment-Host: org.openhab.core.config.discovery.usbserial.linuxsysfs org.openhab.core.config.discovery.usbserial.linuxsysfs.tests;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/DeltaUsbSerialScannerTest.java b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/DeltaUsbSerialScannerTest.java index ca2b0014b..177b7e443 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/DeltaUsbSerialScannerTest.java +++ b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/DeltaUsbSerialScannerTest.java @@ -15,17 +15,17 @@ package org.openhab.core.config.discovery.usbserial.linuxsysfs.internal; import static java.util.Arrays.asList; import static java.util.Collections.emptySet; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.*; import java.io.IOException; import java.util.HashSet; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.discovery.usbserial.UsbSerialDeviceInformation; import org.openhab.core.config.discovery.usbserial.linuxsysfs.internal.DeltaUsbSerialScanner.Delta; import org.openhab.core.config.discovery.usbserial.linuxsysfs.testutil.UsbSerialDeviceInformationGenerator; @@ -42,7 +42,7 @@ public class DeltaUsbSerialScannerTest { private UsbSerialScanner usbSerialScanner; private DeltaUsbSerialScanner deltaUsbSerialScanner; - @Before + @BeforeEach public void setup() { usbSerialScanner = mock(UsbSerialScanner.class); deltaUsbSerialScanner = new DeltaUsbSerialScanner(usbSerialScanner); diff --git a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/PollingUsbSerialScannerTest.java b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/PollingUsbSerialScannerTest.java index c8b1ebc3a..0a17c2fde 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/PollingUsbSerialScannerTest.java +++ b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/PollingUsbSerialScannerTest.java @@ -15,7 +15,7 @@ package org.openhab.core.config.discovery.usbserial.linuxsysfs.internal; import static java.util.Arrays.asList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.openhab.core.config.discovery.usbserial.linuxsysfs.internal.PollingUsbSerialScanner.PAUSE_BETWEEN_SCANS_IN_SECONDS_ATTRIBUTE; import java.io.IOException; @@ -23,8 +23,9 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.config.discovery.usbserial.UsbSerialDeviceInformation; import org.openhab.core.config.discovery.usbserial.UsbSerialDiscoveryListener; @@ -40,12 +41,15 @@ public class PollingUsbSerialScannerTest { private UsbSerialDeviceInformationGenerator usbDeviceInfoGenerator = new UsbSerialDeviceInformationGenerator(); private PollingUsbSerialScanner pollingScanner; + + private AutoCloseable mocksCloseable; + private @Mock UsbSerialDiscoveryListener discoveryListenerMock; private @Mock UsbSerialScanner usbSerialScannerMock; - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); Map config = new HashMap<>(); config.put(PAUSE_BETWEEN_SCANS_IN_SECONDS_ATTRIBUTE, "1"); @@ -55,6 +59,11 @@ public class PollingUsbSerialScannerTest { pollingScanner.registerDiscoveryListener(discoveryListenerMock); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void testNoScansWithoutBackgroundDiscovery() throws IOException, InterruptedException { // Wait a little more than one second to give background scanning a chance to kick in. diff --git a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java index b0e7ab174..a8cd6e313 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java +++ b/itests/org.openhab.core.config.discovery.usbserial.linuxsysfs.tests/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysFsUsbSerialScannerTest.java @@ -17,12 +17,14 @@ import static java.nio.file.Files.*; import static java.nio.file.attribute.PosixFilePermission.*; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.junit.Assert.assertThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.openhab.core.config.discovery.usbserial.linuxsysfs.internal.SysfsUsbSerialScanner.*; +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; @@ -31,10 +33,9 @@ import java.util.HashSet; import java.util.Map; import org.hamcrest.Matcher; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.openhab.core.config.discovery.usbserial.UsbSerialDeviceInformation; /** @@ -44,8 +45,7 @@ import org.openhab.core.config.discovery.usbserial.UsbSerialDeviceInformation; */ public class SysFsUsbSerialScannerTest { - @Rule - public final TemporaryFolder rootFolder = new TemporaryFolder(); + public @TempDir File rootFolder; private static final String SYSFS_TTY_DEVICES_DIR = "sys/class/tty"; private static final String DEV_DIR = "dev"; @@ -60,12 +60,12 @@ public class SysFsUsbSerialScannerTest { private int deviceIndexCounter = 0; - @Before + @BeforeEach public void setup() throws IOException { // only run the tests on systems that support symbolic links assumeTrue(systemSupportsSymLinks()); - rootPath = rootFolder.getRoot().toPath(); + rootPath = rootFolder.toPath(); devPath = rootPath.resolve(DEV_DIR); createDirectories(devPath); @@ -84,10 +84,10 @@ public class SysFsUsbSerialScannerTest { scanner.modified(config); } - @Test(expected = IOException.class) + @Test public void testIOExceptionIfSysfsTtyDoesNotExist() throws IOException { delete(sysfsTtyPath); - scanner.scan(); + assertThrows(IOException.class, () -> scanner.scan()); } @Test @@ -234,7 +234,7 @@ public class SysFsUsbSerialScannerTest { private boolean systemSupportsSymLinks() throws IOException { try { - createSymbolicLink(rootFolder.getRoot().toPath().resolve("aSymbolicLink"), rootFolder.getRoot().toPath()); + createSymbolicLink(rootFolder.toPath().resolve("aSymbolicLink"), rootFolder.toPath()); return true; } catch (UnsupportedOperationException e) { return false; diff --git a/itests/org.openhab.core.config.discovery.usbserial.tests/itest.bndrun b/itests/org.openhab.core.config.discovery.usbserial.tests/itest.bndrun index 933f289ca..98be2870b 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.tests/itest.bndrun +++ b/itests/org.openhab.core.config.discovery.usbserial.tests/itest.bndrun @@ -33,14 +33,9 @@ Provide-Capability: \ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\ @@ -54,4 +49,15 @@ Provide-Capability: \ org.openhab.core.config.discovery.usbserial.tests;version='[3.0.0,3.0.1)',\ org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing;version='[3.0.0,3.0.1)' + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.config.discovery.usbserial.tests/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryServiceTest.java b/itests/org.openhab.core.config.discovery.usbserial.tests/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryServiceTest.java index e1df99311..40cef291b 100644 --- a/itests/org.openhab.core.config.discovery.usbserial.tests/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryServiceTest.java +++ b/itests/org.openhab.core.config.discovery.usbserial.tests/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryServiceTest.java @@ -14,9 +14,9 @@ package org.openhab.core.config.discovery.usbserial.internal; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static org.openhab.core.config.discovery.DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY; @@ -27,8 +27,8 @@ import java.util.HashSet; import java.util.Hashtable; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.config.discovery.DiscoveryListener; import org.openhab.core.config.discovery.DiscoveryResult; @@ -54,7 +54,7 @@ public class UsbSerialDiscoveryServiceTest extends JavaOSGiTest { private final UsbSerialDeviceInformationGenerator usbSerialDeviceInformationGenerator = new UsbSerialDeviceInformationGenerator(); - @Before + @BeforeEach public void setup() { usbSerialDiscovery = mock(UsbSerialDiscovery.class); registerService(usbSerialDiscovery); diff --git a/itests/org.openhab.core.config.dispatch.tests/itest.bndrun b/itests/org.openhab.core.config.dispatch.tests/itest.bndrun index 480057ea9..b39563a16 100644 --- a/itests/org.openhab.core.config.dispatch.tests/itest.bndrun +++ b/itests/org.openhab.core.config.dispatch.tests/itest.bndrun @@ -15,8 +15,6 @@ Fragment-Host: org.openhab.core.config.dispatch org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ com.google.gson;version='[2.8.2,2.8.3)',\ @@ -37,4 +35,67 @@ Fragment-Host: org.openhab.core.config.dispatch org.openhab.core.config.core;version='[3.0.0,3.0.1)',\ org.openhab.core.config.dispatch;version='[3.0.0,3.0.1)',\ org.openhab.core.config.dispatch.tests;version='[3.0.0,3.0.1)',\ - org.openhab.core.test;version='[3.0.0,3.0.1)' + org.openhab.core.test;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + jollyday;version='[0.5.8,0.5.9)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\ + org.apache.xbean.finder;version='[4.12.0,4.12.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.objectweb.asm;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\ + org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.console;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\ + org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\ + org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)',\ + org.threeten.extra;version='[1.4.0,1.4.1)' diff --git a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java index 792eef74e..ab1f91ded 100644 --- a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java +++ b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java @@ -13,7 +13,7 @@ package org.openhab.core.config.dispatch.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.File; import java.io.IOException; @@ -32,15 +32,14 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer.Alphanumeric; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.io.TempDir; import org.openhab.core.config.core.ConfigConstants; import org.openhab.core.test.java.JavaOSGiTest; import org.osgi.framework.InvalidSyntaxException; @@ -50,11 +49,10 @@ import org.osgi.service.cm.ConfigurationAdmin; /** * @author Petar Valchev - Initial contribution */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(Alphanumeric.class) public class ConfigDispatcherOSGiTest extends JavaOSGiTest { - @Rule - public TemporaryFolder tmpBaseFolder = new TemporaryFolder(); + public @TempDir File tmpBaseFolder; private ConfigurationAdmin configAdmin; @@ -68,15 +66,15 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest { private Configuration configuration; private static String configBaseDirectory; - @BeforeClass + @BeforeAll public static void setUpClass() { // Store the default values in order to restore them after all the tests are finished. defaultConfigFile = System.getProperty(ConfigDispatcher.SERVICECFG_PROG_ARGUMENT); } - @Before + @BeforeEach public void setUp() throws IOException { - configBaseDirectory = tmpBaseFolder.getRoot().getAbsolutePath(); + configBaseDirectory = tmpBaseFolder.getAbsolutePath(); final Path source = Paths.get(CONFIGURATION_BASE_DIR); Files.walkFileTree(source, new CopyDirectoryRecursive(source, Paths.get(configBaseDirectory))); @@ -114,7 +112,7 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest { } } - @After + @AfterEach public void tearDown() throws Exception { // Clear the configuration with the current pid from the persistent store. if (configuration != null) { @@ -122,7 +120,7 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest { } } - @AfterClass + @AfterAll public static void tearDownClass() { // Set the system properties to their initial values. setSystemProperty(ConfigDispatcher.SERVICECFG_PROG_ARGUMENT, defaultConfigFile); diff --git a/itests/org.openhab.core.config.xml.tests/itest.bndrun b/itests/org.openhab.core.config.xml.tests/itest.bndrun index 3b2d7847c..00c7b48e4 100644 --- a/itests/org.openhab.core.config.xml.tests/itest.bndrun +++ b/itests/org.openhab.core.config.xml.tests/itest.bndrun @@ -14,8 +14,6 @@ Fragment-Host: org.openhab.core.config.xml org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ @@ -37,4 +35,12 @@ Fragment-Host: org.openhab.core.config.xml org.openhab.core.config.core;version='[3.0.0,3.0.1)',\ org.openhab.core.config.xml;version='[3.0.0,3.0.1)',\ org.openhab.core.config.xml.tests;version='[3.0.0,3.0.1)',\ - org.openhab.core.test;version='[3.0.0,3.0.1)' + org.openhab.core.test;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/BindingInstaller.java b/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/BindingInstaller.java index 27a3bc5ed..3dbdea166 100644 --- a/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/BindingInstaller.java +++ b/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/BindingInstaller.java @@ -13,7 +13,7 @@ package org.openhab.core.config.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.function.Consumer; diff --git a/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionI18nTest.java b/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionI18nTest.java index 27f0fb800..3d2fe66ae 100644 --- a/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionI18nTest.java +++ b/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionI18nTest.java @@ -13,7 +13,8 @@ package org.openhab.core.config.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URI; import java.net.URISyntaxException; @@ -21,8 +22,8 @@ import java.util.Collection; import java.util.Locale; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameterGroup; @@ -43,7 +44,7 @@ public class ConfigDescriptionI18nTest extends JavaOSGiTest { private ConfigDescriptionProvider configDescriptionProvider; - @Before + @BeforeEach public void setUp() { configDescriptionProvider = getService(ConfigDescriptionProvider.class, serviceReference -> "core.xml.config".equals(serviceReference.getProperty("esh.scope"))); diff --git a/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionsTest.java b/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionsTest.java index e190bebad..e0b2556b5 100644 --- a/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionsTest.java +++ b/itests/org.openhab.core.config.xml.tests/src/main/java/org/openhab/core/config/xml/test/ConfigDescriptionsTest.java @@ -14,7 +14,7 @@ package org.openhab.core.config.xml.test; import static java.util.stream.Collectors.joining; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.math.BigDecimal; import java.net.URI; @@ -24,8 +24,8 @@ import java.util.List; import java.util.Locale; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -51,7 +51,7 @@ public class ConfigDescriptionsTest extends JavaOSGiTest { private ConfigDescriptionRegistry configDescriptionRegistry; private BindingInstaller bindingInstaller; - @Before + @BeforeEach public void setUp() { configDescriptionRegistry = getService(ConfigDescriptionRegistry.class); assertThat(configDescriptionRegistry, is(notNullValue())); diff --git a/itests/org.openhab.core.ephemeris.tests/itest.bndrun b/itests/org.openhab.core.ephemeris.tests/itest.bndrun index 245cfb1bb..8c75f7e8d 100644 --- a/itests/org.openhab.core.ephemeris.tests/itest.bndrun +++ b/itests/org.openhab.core.ephemeris.tests/itest.bndrun @@ -25,8 +25,6 @@ feature.openhab-config: \ org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -54,4 +52,12 @@ feature.openhab-config: \ org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ org.openhab.core.ephemeris.tests;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.apache.felix.logback;version='[1.0.2,1.0.3)' + org.apache.felix.logback;version='[1.0.2,1.0.3)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java b/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java index 623ac6972..da45204d3 100644 --- a/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java +++ b/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java @@ -12,7 +12,8 @@ */ package org.openhab.core.ephemeris.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.openhab.core.ephemeris.internal.EphemerisManagerImpl.*; import java.net.URI; @@ -31,10 +32,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.hamcrest.CoreMatchers; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ParameterOption; import org.openhab.core.ephemeris.EphemerisManager; import org.openhab.core.test.java.JavaOSGiTest; @@ -59,10 +58,10 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) EphemerisManagerImpl ephemerisManager; - @Before + @BeforeEach public void setUp() { // TODO: Tests currently fail on Java 11 due to Jollyday requiring JAXB 2.3 - Assume.assumeThat(System.getProperty("java.version"), CoreMatchers.startsWith("1.8")); + assumeTrue(System.getProperty("java.version").startsWith("1.8")); ephemerisManager = getService(EphemerisManager.class, EphemerisManagerImpl.class); assertNotNull(ephemerisManager); @@ -83,9 +82,10 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest { assertFalse(ephemerisManager.cities.isEmpty()); } - @Test(expected = java.lang.IllegalArgumentException.class) + @Test public void testConfigurtationDaysetWeekendFailed() { - ephemerisManager.modified(Collections.singletonMap(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, "Foo,Bar")); + assertThrows(IllegalArgumentException.class, () -> ephemerisManager + .modified(Collections.singletonMap(CONFIG_DAYSET_PREFIX + CONFIG_DAYSET_WEEKEND, "Foo,Bar"))); } @Test @@ -106,9 +106,9 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest { ephemerisManager.daysets.get(CONFIG_DAYSET_WEEKEND)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParsePropertyFailed() { - ephemerisManager.parseProperty("", ""); + assertThrows(IllegalArgumentException.class, () -> ephemerisManager.parseProperty("", "")); } @Test diff --git a/itests/org.openhab.core.io.rest.core.tests/itest.bndrun b/itests/org.openhab.core.io.rest.core.tests/itest.bndrun index f37070409..57ecf67ce 100644 --- a/itests/org.openhab.core.io.rest.core.tests/itest.bndrun +++ b/itests/org.openhab.core.io.rest.core.tests/itest.bndrun @@ -20,8 +20,6 @@ Fragment-Host: org.openhab.core.io.rest.core org.objectweb.asm;version='[5.0.4,5.0.5)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -33,9 +31,6 @@ Fragment-Host: org.openhab.core.io.rest.core org.apache.servicemix.specs.activation-api-1.1;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\ @@ -71,4 +66,55 @@ Fragment-Host: org.openhab.core.io.rest.core org.openhab.core.transform;version='[3.0.0,3.0.1)',\ javax.xml.soap-api;version='[1.3.5,1.3.6)',\ org.apache.servicemix.specs.jaxws-api-2.2;version='[2.9.0,2.9.1)',\ - jakarta.xml.bind-api;version='[2.3.2,2.3.3)' + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + jaxb-api;version='[2.2.11,2.2.12)',\ + jollyday;version='[0.5.8,0.5.9)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.openhab.core.audio;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.http;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.voice;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.threeten.extra;version='[1.4.0,1.4.1)' diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResourceOSGITest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResourceOSGITest.java index 17420f751..9a9499447 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResourceOSGITest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResourceOSGITest.java @@ -12,16 +12,17 @@ */ package org.openhab.core.io.rest.core.internal.discovery; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.config.core.ConfigDescriptionRegistry; import org.openhab.core.config.discovery.inbox.Inbox; @@ -43,11 +44,13 @@ public class InboxResourceOSGITest extends JavaOSGiTest { private final Thing testThing = ThingBuilder.create(testTypeUID, testUID).build(); private final String testThingLabel = "dummy_thing"; + private AutoCloseable mocksCloseable; + private @Mock Inbox inbox; - @Before - public void setup() throws Exception { - initMocks(this); + @BeforeEach + public void beforeEach() throws Exception { + mocksCloseable = openMocks(this); ConfigDescriptionRegistry configDescRegistry = getService(ConfigDescriptionRegistry.class); assertNotNull(configDescRegistry); @@ -57,6 +60,11 @@ public class InboxResourceOSGITest extends JavaOSGiTest { assertNotNull(resource); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void assertThatApproveApprovesThingsWhichAreInTheInbox() { when(inbox.approve(any(), any())).thenReturn(testThing); diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java index 78ca523a1..c2667e81c 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java @@ -13,12 +13,13 @@ package org.openhab.core.io.rest.core.internal.item; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.core.IsCollectionContaining.hasItems; -import static org.junit.Assert.*; +import static org.hamcrest.core.IsIterableContaining.hasItems; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.IOException; import java.io.InputStream; @@ -35,8 +36,9 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.io.rest.RESTResource; import org.openhab.core.items.GenericItem; @@ -73,6 +75,8 @@ public class ItemResourceOSGiTest extends JavaOSGiTest { private GenericItem item3; private GenericItem item4; + private AutoCloseable mocksCloseable; + private @Mock ItemProvider itemProvider; private UriInfo uriInfo; @@ -81,9 +85,9 @@ public class ItemResourceOSGiTest extends JavaOSGiTest { private ItemResource itemResource; private ManagedItemProvider managedItemProvider; - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); registerService(new VolatileStorageService()); @@ -110,6 +114,11 @@ public class ItemResourceOSGiTest extends JavaOSGiTest { when(httpHeaders.getHeaderString(anyString())).thenReturn(null); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void shouldReturnUnicodeItems() throws IOException { item4.setLabel(ITEM_LABEL4); diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java index 6edd1e156..0204d1a0f 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java @@ -12,18 +12,19 @@ */ package org.openhab.core.io.rest.core.internal.persistence; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.time.ZoneId; import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.io.rest.LocaleService; @@ -48,14 +49,16 @@ public class PersistenceResourceTest { private PersistenceResource pResource; private List items; + private AutoCloseable mocksCloseable; + private @Mock ItemRegistry itemRegistry; private @Mock LocaleService localeService; private @Mock PersistenceServiceRegistry persistenceServiceRegistry; private @Mock TimeZoneProvider timeZoneProvider; - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); pResource = new PersistenceResource(itemRegistry, localeService, persistenceServiceRegistry, timeZoneProvider); @@ -93,6 +96,11 @@ public class PersistenceResourceTest { when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault()); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void testGetPersistenceItemData() { ItemHistoryDTO dto = pResource.createDTO(PERSISTENCE_SERVICE_ID, "testItem", null, null, 1, 5, false); diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java index d867c4999..c18611201 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java @@ -13,18 +13,19 @@ package org.openhab.core.io.rest.core.internal.profile; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.io.rest.LocaleService; import org.openhab.core.test.java.JavaTest; @@ -70,13 +71,15 @@ public class ProfileTypeResourceTest extends JavaTest { private final ChannelType otherTriggerChannelType = ChannelTypeBuilder .trigger(otherTriggerChannelTypeUID, "channel1").build(); + private AutoCloseable mocksCloseable; + private @Mock ChannelTypeRegistry channelTypeRegistry; private @Mock LocaleService localeService; private @Mock ProfileTypeRegistry profileTypeRegistry; - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); resource = new ProfileTypeResource(channelTypeRegistry, localeService, profileTypeRegistry); @@ -101,6 +104,11 @@ public class ProfileTypeResourceTest extends JavaTest { when(channelTypeRegistry.getChannelType(otherTriggerChannelTypeUID, null)).thenReturn(otherTriggerChannelType); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void testGetAll() { Stream result = resource.getProfileTypes(null, null, null); diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResourceOSGiTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResourceOSGiTest.java index 0e8dad023..e3a9fe500 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResourceOSGiTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResourceOSGiTest.java @@ -13,7 +13,7 @@ package org.openhab.core.io.rest.core.internal.service; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; @@ -27,8 +27,8 @@ import java.util.Optional; import javax.ws.rs.core.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.io.rest.core.service.ConfigurableServiceDTO; import org.openhab.core.test.AsyncResultWrapper; import org.openhab.core.test.java.JavaOSGiTest; @@ -49,7 +49,7 @@ public class ConfigurableServiceResourceOSGiTest extends JavaOSGiTest { private ConfigurableServiceResource configurableServiceResource; private final AsyncResultWrapper> propertiesWrapper = new AsyncResultWrapper<>(); - @Before + @BeforeEach @SuppressWarnings("unchecked") public void setUp() throws Exception { Configuration configuration = mock(Configuration.class); diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java index 4eda2d520..d74da0de1 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java @@ -13,14 +13,15 @@ package org.openhab.core.io.rest.core.item; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.math.BigDecimal; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.library.items.NumberItem; import org.openhab.core.library.types.DecimalType; @@ -37,12 +38,13 @@ public class EnrichedItemDTOMapperWithTransformOSGiTest extends JavaOSGiTest { private static final String ITEM_NAME = "Item1"; - @Mock - private StateDescriptionService stateDescriptionService; + private AutoCloseable mocksCloseable; - @Before - public void setup() { - initMocks(this); + private @Mock StateDescriptionService stateDescriptionService; + + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); StateDescription stateDescription = StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO) .withMaximum(BigDecimal.valueOf(100)).withStep(BigDecimal.TEN).withPattern("%d °C").withReadOnly(true) @@ -50,6 +52,11 @@ public class EnrichedItemDTOMapperWithTransformOSGiTest extends JavaOSGiTest { when(stateDescriptionService.getStateDescription(ITEM_NAME, null)).thenReturn(stateDescription); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void shouldConsiderTraformationWhenPresent() { NumberItem item1 = new NumberItem("Item1"); diff --git a/itests/org.openhab.core.model.core.tests/itest.bndrun b/itests/org.openhab.core.model.core.tests/itest.bndrun index 18a5c0456..8e9702fcf 100644 --- a/itests/org.openhab.core.model.core.tests/itest.bndrun +++ b/itests/org.openhab.core.model.core.tests/itest.bndrun @@ -21,8 +21,6 @@ Fragment-Host: org.openhab.core.model.core org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ com.google.gson;version='[2.8.2,2.8.3)',\ @@ -36,9 +34,6 @@ Fragment-Host: org.openhab.core.model.core org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ com.google.guava;version='[27.1.0,27.1.1)',\ com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ @@ -96,4 +91,14 @@ Fragment-Host: org.openhab.core.model.core org.openhab.core.voice;version='[3.0.0,3.0.1)',\ org.openhab.core.automation;version='[3.0.0,3.0.1)',\ org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ - org.openhab.core.model.thing.runtime;version='[3.0.0,3.0.1)' + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.model.core.tests/src/main/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java b/itests/org.openhab.core.model.core.tests/src/main/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java index 77ce26bae..fb5a6168b 100644 --- a/itests/org.openhab.core.model.core.tests/src/main/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java +++ b/itests/org.openhab.core.model.core.tests/src/main/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java @@ -13,9 +13,9 @@ package org.openhab.core.model.core.internal.folder; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.io.IOException; @@ -35,9 +35,9 @@ import java.util.stream.Stream; import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.OpenHAB; import org.openhab.core.model.core.ModelParser; @@ -84,24 +84,20 @@ public class FolderObserverTest extends JavaOSGiTest { private static final String INITIAL_FILE_CONTENT = "Initial content"; + private Dictionary configProps; + private String defaultWatchedDir; private FolderObserver folderObserver; private ModelRepoDummy modelRepo; - @Mock - private ModelParser modelParser; + private AutoCloseable mocksCloseable; - @Mock - private ReadyService readyService; + private @Mock ModelParser modelParser; + private @Mock ReadyService readyService; + private @Mock ComponentContext context; - @Mock - private ComponentContext context; - private Dictionary configProps; - - private String defaultWatchedDir; - - @Before - public void setUp() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); configProps = new Hashtable<>(); @@ -109,6 +105,11 @@ public class FolderObserverTest extends JavaOSGiTest { setUpServices(); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + /** * The main configuration folder's path is saved in the defaultWatchedDir variable * in order to be restored after all the tests are finished. @@ -138,7 +139,7 @@ public class FolderObserverTest extends JavaOSGiTest { * * @throws Exception */ - @After + @AfterEach public void tearDown() throws Exception { folderObserver.deactivate(); try (Stream walk = Files.walk(WATCHED_DIRECTORY.toPath())) { diff --git a/itests/org.openhab.core.model.item.tests/itest.bndrun b/itests/org.openhab.core.model.item.tests/itest.bndrun index e8a36acc7..1d540d021 100644 --- a/itests/org.openhab.core.model.item.tests/itest.bndrun +++ b/itests/org.openhab.core.model.item.tests/itest.bndrun @@ -31,8 +31,6 @@ Fragment-Host: org.openhab.core.model.item org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ @@ -95,4 +93,11 @@ Fragment-Host: org.openhab.core.model.item org.openhab.core.voice;version='[3.0.0,3.0.1)',\ org.openhab.core.automation;version='[3.0.0,3.0.1)',\ org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ - org.openhab.core.model.thing.runtime;version='[3.0.0,3.0.1)' + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java index 6f26e5b4a..a06549957 100644 --- a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java +++ b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java @@ -14,8 +14,8 @@ package org.openhab.core.model.item.internal; import static java.util.stream.Collectors.*; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import java.io.ByteArrayInputStream; import java.math.BigDecimal; @@ -31,9 +31,9 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.events.EventFilter; import org.openhab.core.events.EventSubscriber; @@ -87,7 +87,7 @@ public class GenericItemProviderTest extends JavaOSGiTest { private MetadataRegistry metadataRegistry; private ModelRepository modelRepository; - @Before + @BeforeEach public void setUp() { itemRegistry = getService(ItemRegistry.class); assertThat(itemRegistry, is(notNullValue())); @@ -105,7 +105,7 @@ public class GenericItemProviderTest extends JavaOSGiTest { /** * Make sure the models and items are removed and the removal events have been processed. */ - @After + @AfterEach public void tearDown() { Collection itemsToRemove = itemRegistry.getAll(); List modelNamesToRemove = TESTMODEL_NAMES.stream() diff --git a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericMetadataProviderTest.java b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericMetadataProviderTest.java index eda3fa305..573960153 100644 --- a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericMetadataProviderTest.java +++ b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericMetadataProviderTest.java @@ -12,11 +12,11 @@ */ package org.openhab.core.model.item.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collection; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.items.Metadata; /** diff --git a/itests/org.openhab.core.model.persistence.tests/itest.bndrun b/itests/org.openhab.core.model.persistence.tests/itest.bndrun index 9aa1fbe3e..d6e898d4e 100644 --- a/itests/org.openhab.core.model.persistence.tests/itest.bndrun +++ b/itests/org.openhab.core.model.persistence.tests/itest.bndrun @@ -22,8 +22,6 @@ Fragment-Host: org.openhab.core.model.persistence org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ com.google.gson;version='[2.8.2,2.8.3)',\ @@ -111,4 +109,11 @@ Fragment-Host: org.openhab.core.model.persistence org.openhab.core.voice;version='[3.0.0,3.0.1)',\ org.openhab.core.automation;version='[3.0.0,3.0.1)',\ org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ - org.openhab.core.model.thing.runtime;version='[3.0.0,3.0.1)' + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.model.persistence.tests/src/main/java/org/openhab/core/model/persistence/extensions/PersistenceExtensionsTest.java b/itests/org.openhab.core.model.persistence.tests/src/main/java/org/openhab/core/model/persistence/extensions/PersistenceExtensionsTest.java index b057f20f6..a069e6ea0 100644 --- a/itests/org.openhab.core.model.persistence.tests/src/main/java/org/openhab/core/model/persistence/extensions/PersistenceExtensionsTest.java +++ b/itests/org.openhab.core.model.persistence.tests/src/main/java/org/openhab/core/model/persistence/extensions/PersistenceExtensionsTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.model.persistence.extensions; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.time.Instant; import java.time.ZoneId; @@ -23,9 +23,9 @@ import java.util.List; import java.util.Set; import java.util.stream.IntStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.items.GenericItem; import org.openhab.core.library.types.DecimalType; @@ -82,7 +82,7 @@ public class PersistenceExtensionsTest { private PersistenceExtensions ext; private GenericItem item; - @Before + @BeforeEach public void setUp() { ext = new PersistenceExtensions(); ext.setPersistenceServiceRegistry(registry); @@ -100,7 +100,7 @@ public class PersistenceExtensionsTest { }; } - @After + @AfterEach public void tearDown() { ext.unsetPersistenceServiceRegistry(registry); } diff --git a/itests/org.openhab.core.model.rule.tests/itest.bndrun b/itests/org.openhab.core.model.rule.tests/itest.bndrun index b5ea50c13..bc9ede3d9 100644 --- a/itests/org.openhab.core.model.rule.tests/itest.bndrun +++ b/itests/org.openhab.core.model.rule.tests/itest.bndrun @@ -22,8 +22,6 @@ Fragment-Host: org.openhab.core.model.rule.runtime org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ com.google.gson;version='[2.8.2,2.8.3)',\ @@ -110,5 +108,13 @@ Fragment-Host: org.openhab.core.model.rule.runtime org.openhab.core.automation;version='[3.0.0,3.0.1)',\ org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ org.openhab.core.model.rule.runtime;version='[3.0.0,3.0.1)',\ - org.openhab.core.model.rule.tests;version='[3.0.0,3.0.1)' --runblacklist: bnd.identity;id='jakarta.activation-api' \ No newline at end of file + org.openhab.core.model.rule.tests;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' +-runblacklist: bnd.identity;id='jakarta.activation-api' diff --git a/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java b/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java index 315a4d00b..b69f47222 100644 --- a/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java +++ b/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java @@ -13,7 +13,8 @@ package org.openhab.core.model.rule.runtime; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.ByteArrayInputStream; import java.math.BigDecimal; @@ -24,9 +25,9 @@ import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.xtext.naming.QualifiedName; import org.eclipse.xtext.xbase.interpreter.IEvaluationContext; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.automation.Rule; import org.openhab.core.automation.RuleProvider; import org.openhab.core.automation.internal.module.handler.ChannelEventTriggerHandler; @@ -61,7 +62,7 @@ public class DSLRuleProviderTest extends JavaOSGiTest { private @NonNullByDefault({}) DSLRuleProvider dslRuleProvider; private @NonNullByDefault({}) ReadyService readyService; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); @@ -84,7 +85,7 @@ public class DSLRuleProviderTest extends JavaOSGiTest { } } - @After + @AfterEach public void tearDown() { modelRepository.removeModel(TESTMODEL_NAME); } diff --git a/itests/org.openhab.core.model.script.tests/itest.bndrun b/itests/org.openhab.core.model.script.tests/itest.bndrun index 4276aaeeb..73c12a326 100644 --- a/itests/org.openhab.core.model.script.tests/itest.bndrun +++ b/itests/org.openhab.core.model.script.tests/itest.bndrun @@ -23,8 +23,6 @@ Fragment-Host: org.openhab.core.model.script org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ com.google.gson;version='[2.8.2,2.8.3)',\ @@ -94,5 +92,12 @@ Fragment-Host: org.openhab.core.model.script org.openhab.core.voice;version='[3.0.0,3.0.1)',\ org.openhab.core.automation;version='[3.0.0,3.0.1)',\ org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ - org.openhab.core.model.thing.runtime;version='[3.0.0,3.0.1)' - \ No newline at end of file + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' + diff --git a/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/engine/ScriptEngineOSGiTest.java b/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/engine/ScriptEngineOSGiTest.java index 3abcb711a..53a863436 100644 --- a/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/engine/ScriptEngineOSGiTest.java +++ b/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/engine/ScriptEngineOSGiTest.java @@ -13,7 +13,8 @@ package org.openhab.core.model.script.engine; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.Collection; @@ -22,9 +23,9 @@ import javax.measure.quantity.Length; import javax.measure.quantity.Temperature; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.common.registry.ProviderChangeListener; import org.openhab.core.events.EventPublisher; import org.openhab.core.items.Item; @@ -58,7 +59,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) ItemRegistry itemRegistry; private @NonNullByDefault({}) ScriptEngine scriptEngine; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); @@ -95,7 +96,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { scriptEngine = ScriptServiceUtil.getScriptEngine(); } - @After + @AfterEach public void tearDown() { unregisterService(itemProvider); } @@ -126,13 +127,13 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE); ((NumberItem) numberItem).setState(new QuantityType<>("20 °C")); - assertTrue(runScript("NumberA.state > 20|°F")); + assertTrue((boolean) runScript("NumberA.state > 20|°F")); } @Test public void testSpacesDoNotMatter() throws ScriptExecutionException, ScriptParsingException { - assertTrue(runScript("20|°C == 20 | °C")); - assertTrue(runScript("20|\"°C\" == 20 | \"°C\"")); + assertTrue((boolean) runScript("20|°C == 20 | °C")); + assertTrue((boolean) runScript("20|\"°C\" == 20 | \"°C\"")); } @SuppressWarnings("null") @@ -141,7 +142,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE); ((NumberItem) numberItem).setState(new QuantityType<>("20 °C")); - assertTrue(runScript("NumberA.state >= 20|°C")); + assertTrue((boolean) runScript("NumberA.state >= 20|°C")); } @SuppressWarnings("null") @@ -150,7 +151,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE); ((NumberItem) numberItem).setState(new QuantityType<>("20 °F")); - assertTrue(runScript("NumberA.state < 20|°C")); + assertTrue((boolean) runScript("NumberA.state < 20|°C")); } @SuppressWarnings("null") @@ -159,7 +160,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE); ((NumberItem) numberItem).setState(new QuantityType<>("19 °F")); - assertTrue(runScript("NumberA.state <= 20|°F")); + assertTrue((boolean) runScript("NumberA.state <= 20|°F")); } @SuppressWarnings("null") @@ -168,7 +169,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE); ((NumberItem) numberItem).setState(new QuantityType<>("20 °C")); - assertTrue(runScript("NumberA.state == 20|°C")); + assertTrue((boolean) runScript("NumberA.state == 20|°C")); } @SuppressWarnings("null") @@ -177,7 +178,7 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE); ((NumberItem) numberItem).setState(new QuantityType<>("20 °C")); - assertTrue(runScript("NumberA.state != 10|°C")); + assertTrue((boolean) runScript("NumberA.state != 10|°C")); } @SuppressWarnings("null") @@ -186,37 +187,37 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { Item numberItem = itemRegistry.get(NUMBER_ITEM_DECIMAL); ((NumberItem) numberItem).setState(new DecimalType(20)); - assertTrue(runScript("NumberB.state > new DecimalType(19)")); + assertTrue((boolean) runScript("NumberB.state > new DecimalType(19)")); } @Test public void testCompareGreaterThanQuantityType() throws ScriptParsingException, ScriptExecutionException { - assertTrue(runScript("20.0|°C > 20|°F")); + assertTrue((boolean) runScript("20.0|°C > 20|°F")); } @Test public void testCompareGreaterThanQuantityTypeFalse() throws ScriptParsingException, ScriptExecutionException { - assertFalse(runScript("20.0|°F > 20|°C")); + assertFalse((boolean) runScript("20.0|°F > 20|°C")); } @Test public void testCompareGreaterEqualsThanQuantityType() throws ScriptParsingException, ScriptExecutionException { - assertTrue(runScript("1|m >= 100|cm")); + assertTrue((boolean) runScript("1|m >= 100|cm")); } @Test public void testCompareLessThanQuantityTypeFalse() throws ScriptParsingException, ScriptExecutionException { - assertFalse(runScript("20.0|°C < 20|°F")); + assertFalse((boolean) runScript("20.0|°C < 20|°F")); } @Test public void testCompareLessThanQuantityType() throws ScriptParsingException, ScriptExecutionException { - assertTrue(runScript("20.0|°F < 20|°C")); + assertTrue((boolean) runScript("20.0|°F < 20|°C")); } @Test public void testCompareLessEqualsThanQuantityType() throws ScriptParsingException, ScriptExecutionException { - assertTrue(runScript("100|cm <= 1|m")); + assertTrue((boolean) runScript("100|cm <= 1|m")); } @Test @@ -227,7 +228,8 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { @Test public void testAssignAndCompareQuantityType() throws ScriptParsingException, ScriptExecutionException { - assertFalse(runScript("NumberA.state = 20.0|°C as org.openhab.core.types.State; NumberA.state < 20|°F")); + assertFalse( + (boolean) runScript("NumberA.state = 20.0|°C as org.openhab.core.types.State; NumberA.state < 20|°F")); } @Test @@ -319,23 +321,23 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest { @Test public void testCompareQuantityTypeOneNumber() throws ScriptParsingException, ScriptExecutionException { - assertThat(runScript("1 == 1|one"), is(true)); - assertThat(runScript("1|one == 1"), is(true)); + assertThat((boolean) runScript("1 == 1|one"), is(true)); + assertThat((boolean) runScript("1|one == 1"), is(true)); - assertThat(runScript("1 != 2|one"), is(true)); - assertThat(runScript("2|one != 1"), is(true)); + assertThat((boolean) runScript("1 != 2|one"), is(true)); + assertThat((boolean) runScript("2|one != 1"), is(true)); - assertThat(runScript("1 < 2|one"), is(true)); - assertThat(runScript("1|one < 2"), is(true)); + assertThat((boolean) runScript("1 < 2|one"), is(true)); + assertThat((boolean) runScript("1|one < 2"), is(true)); - assertThat(runScript("1 <= 1|one"), is(true)); - assertThat(runScript("1|one <= 1"), is(true)); + assertThat((boolean) runScript("1 <= 1|one"), is(true)); + assertThat((boolean) runScript("1|one <= 1"), is(true)); - assertThat(runScript("2 > 1|one"), is(true)); - assertThat(runScript("2|one > 1"), is(true)); + assertThat((boolean) runScript("2 > 1|one"), is(true)); + assertThat((boolean) runScript("2|one > 1"), is(true)); - assertThat(runScript("1 >= 1|one"), is(true)); - assertThat(runScript("1|one >= 1"), is(true)); + assertThat((boolean) runScript("1 >= 1|one"), is(true)); + assertThat((boolean) runScript("1|one >= 1"), is(true)); } @Test diff --git a/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/lib/NumberExtensionsTest.java b/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/lib/NumberExtensionsTest.java index 343f36acd..cd5320dd2 100644 --- a/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/lib/NumberExtensionsTest.java +++ b/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/lib/NumberExtensionsTest.java @@ -13,7 +13,8 @@ package org.openhab.core.model.script.lib; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; @@ -21,7 +22,7 @@ import javax.measure.quantity.Dimensionless; import javax.measure.quantity.Length; import javax.measure.quantity.Temperature; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SmartHomeUnits; diff --git a/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/tests/lib/NumberExtensionsTest.java b/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/tests/lib/NumberExtensionsTest.java index 7da558566..8c2ec8a54 100644 --- a/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/tests/lib/NumberExtensionsTest.java +++ b/itests/org.openhab.core.model.script.tests/src/main/java/org/openhab/core/model/script/tests/lib/NumberExtensionsTest.java @@ -14,11 +14,12 @@ */ package org.openhab.core.model.script.tests.lib; +import static org.junit.jupiter.api.Assertions.*; + import java.math.BigDecimal; import java.math.RoundingMode; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.library.types.DecimalType; import org.openhab.core.model.script.lib.NumberExtensions; import org.openhab.core.types.Type; @@ -40,8 +41,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_plus(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(9)); + assertNotNull(result); + assertEquals(result, new BigDecimal(9)); } /** @@ -54,8 +55,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_plus(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(5)); + assertNotNull(result); + assertEquals(result, new BigDecimal(5)); } /** @@ -68,8 +69,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_plus(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(10)); + assertNotNull(result); + assertEquals(result, new BigDecimal(10)); } /** @@ -81,8 +82,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_minus(x); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(-2)); + assertNotNull(result); + assertEquals(result, new BigDecimal(-2)); } /** @@ -94,7 +95,7 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_minus(x); - Assert.assertNull(result); + assertNull(result); } /** @@ -107,8 +108,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_minus(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(10 - 100)); + assertNotNull(result); + assertEquals(result, new BigDecimal(10 - 100)); } /** @@ -121,8 +122,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_minus(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(-100)); + assertNotNull(result); + assertEquals(result, new BigDecimal(-100)); } /** @@ -135,8 +136,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_minus(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(10)); + assertNotNull(result); + assertEquals(result, new BigDecimal(10)); } /** @@ -149,8 +150,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_multiply(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(20 * 30)); + assertNotNull(result); + assertEquals(result, new BigDecimal(20 * 30)); } /** @@ -163,8 +164,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_multiply(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(0)); + assertNotNull(result); + assertEquals(result, new BigDecimal(0)); } /** @@ -177,8 +178,8 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_multiply(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(0)); + assertNotNull(result); + assertEquals(result, new BigDecimal(0)); } /** @@ -191,33 +192,30 @@ public class NumberExtensionsTest { BigDecimal result = NumberExtensions.operator_divide(x, y); - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(12).divide(new BigDecimal(4), 8, RoundingMode.HALF_UP)); + assertNotNull(result); + assertEquals(result, new BigDecimal(12).divide(new BigDecimal(4), 8, RoundingMode.HALF_UP)); } /** * Test method for {@link NumberExtensions#operator_divide(java.lang.Number, java.lang.Number)} */ - @Test(expected = NullPointerException.class) + @Test public void testOperatorDivideNullLeft() { Number x = null; Number y = 4; - BigDecimal result = NumberExtensions.operator_divide(x, y); - - Assert.assertNotNull(result); - Assert.assertEquals(result, new BigDecimal(0).divide(new BigDecimal(4), 8, RoundingMode.HALF_UP)); + assertThrows(NullPointerException.class, () -> NumberExtensions.operator_divide(x, y)); } /** * Test method for {@link NumberExtensions#operator_divide(java.lang.Number, java.lang.Number)} */ - @Test(expected = NullPointerException.class) + @Test public void testOperatorDivideNullRight() { Number x = 12; Number y = null; - NumberExtensions.operator_divide(x, y); + assertThrows(NullPointerException.class, () -> NumberExtensions.operator_divide(x, y)); } /** @@ -229,13 +227,13 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_equals(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); x = 123; y = 321; resutl = NumberExtensions.operator_equals(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -247,7 +245,7 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_equals(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -259,7 +257,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_equals(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -271,7 +269,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_equals(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -283,13 +281,13 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_notEquals(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); x = 123; y = 321; resutl = NumberExtensions.operator_notEquals(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -301,7 +299,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_notEquals(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -313,7 +311,7 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_notEquals(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -325,13 +323,13 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_lessThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); x = 90; y = 2; resutl = NumberExtensions.operator_lessThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -343,7 +341,7 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_lessThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -355,7 +353,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_lessThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -367,13 +365,13 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_greaterThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); x = 90; y = 2; resutl = NumberExtensions.operator_greaterThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -385,7 +383,7 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_greaterThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -397,7 +395,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_greaterThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -409,19 +407,19 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_lessEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); x = 90; y = 2; resutl = NumberExtensions.operator_lessEqualsThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); x = 3; y = 3; resutl = NumberExtensions.operator_lessEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -433,7 +431,7 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_lessEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -445,7 +443,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_lessEqualsThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -457,7 +455,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_lessEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -469,19 +467,19 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_greaterEqualsThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); x = 90; y = 2; resutl = NumberExtensions.operator_greaterEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); x = 3; y = 3; resutl = NumberExtensions.operator_greaterEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -493,7 +491,7 @@ public class NumberExtensionsTest { Number y = 123; boolean resutl = NumberExtensions.operator_greaterEqualsThan(x, y); - Assert.assertFalse(resutl); + assertFalse(resutl); } /** @@ -505,7 +503,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_greaterEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -517,7 +515,7 @@ public class NumberExtensionsTest { Number y = null; boolean resutl = NumberExtensions.operator_greaterEqualsThan(x, y); - Assert.assertTrue(resutl); + assertTrue(resutl); } /** @@ -530,13 +528,13 @@ public class NumberExtensionsTest { boolean result = NumberExtensions.operator_equals((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); x = 1; result = NumberExtensions.operator_equals((Type) type, x); - Assert.assertFalse(result); + assertFalse(result); } /** @@ -550,13 +548,13 @@ public class NumberExtensionsTest { boolean result = NumberExtensions.operator_notEquals((Type) type, x); - Assert.assertFalse(result); + assertFalse(result); x = 1; result = NumberExtensions.operator_notEquals((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); } /** @@ -570,13 +568,13 @@ public class NumberExtensionsTest { boolean result = NumberExtensions.operator_greaterThan((Type) type, x); - Assert.assertFalse(result); + assertFalse(result); x = 2; result = NumberExtensions.operator_greaterThan((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); } /** @@ -590,19 +588,19 @@ public class NumberExtensionsTest { boolean result = NumberExtensions.operator_greaterEqualsThan((Type) type, x); - Assert.assertFalse(result); + assertFalse(result); x = 2; result = NumberExtensions.operator_greaterEqualsThan((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); x = 10; result = NumberExtensions.operator_greaterEqualsThan((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); } /** @@ -616,13 +614,13 @@ public class NumberExtensionsTest { boolean result = NumberExtensions.operator_lessThan((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); x = 2; result = NumberExtensions.operator_lessThan((Type) type, x); - Assert.assertFalse(result); + assertFalse(result); } /** @@ -636,18 +634,18 @@ public class NumberExtensionsTest { boolean result = NumberExtensions.operator_lessEqualsThan((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); x = 2; result = NumberExtensions.operator_lessEqualsThan((Type) type, x); - Assert.assertFalse(result); + assertFalse(result); x = 10; result = NumberExtensions.operator_lessEqualsThan((Type) type, x); - Assert.assertTrue(result); + assertTrue(result); } } diff --git a/itests/org.openhab.core.model.thing.tests/itest.bndrun b/itests/org.openhab.core.model.thing.tests/itest.bndrun index f9a41c7e4..6309d2a14 100644 --- a/itests/org.openhab.core.model.thing.tests/itest.bndrun +++ b/itests/org.openhab.core.model.thing.tests/itest.bndrun @@ -27,8 +27,6 @@ Fragment-Host: org.openhab.core.model.thing org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -43,9 +41,6 @@ Fragment-Host: org.openhab.core.model.thing org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ com.google.guava;version='[27.1.0,27.1.1)',\ com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ io.github.classgraph;version='[4.8.35,4.8.36)',\ @@ -105,5 +100,17 @@ Fragment-Host: org.openhab.core.model.thing org.openhab.core.transform;version='[3.0.0,3.0.1)',\ org.openhab.core.voice;version='[3.0.0,3.0.1)',\ org.openhab.core.automation;version='[3.0.0,3.0.1)',\ - org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)' + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-jupiter-params;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/GenericItemChannelLinkProviderJavaTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/GenericItemChannelLinkProviderJavaTest.java index 18785a0b0..68397ab42 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/GenericItemChannelLinkProviderJavaTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/GenericItemChannelLinkProviderJavaTest.java @@ -13,10 +13,11 @@ package org.openhab.core.model.thing.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.math.BigDecimal; @@ -24,9 +25,9 @@ import java.util.Collection; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.common.registry.ProviderChangeListener; import org.openhab.core.config.core.Configuration; @@ -55,6 +56,8 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest { private static final String CHANNEL = "test:test:test:test"; private static final String LINK = ITEM + " -> " + CHANNEL; + private @NonNullByDefault({}) AutoCloseable mocksCloseable; + private @Mock @Nullable ProviderChangeListener listenerMock; private @NonNullByDefault({}) ModelRepository modelRepository; @@ -63,11 +66,11 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest { private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry; private @NonNullByDefault({}) ItemChannelLinkProvider itemChannelLinkProvider; - @Before - public void setUp() { - registerVolatileStorageService(); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); - initMocks(this); + registerVolatileStorageService(); thingRegistry = getService(ThingRegistry.class); assertThat(thingRegistry, is(notNullValue())); @@ -83,8 +86,10 @@ public class GenericItemChannelLinkProviderJavaTest extends JavaOSGiTest { modelRepository.removeModel(ITEMS_TESTMODEL_NAME); } - @After - public void tearDown() { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + modelRepository.removeModel(THINGS_TESTMODEL_NAME); modelRepository.removeModel(ITEMS_TESTMODEL_NAME); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java index cbac2ff9b..c763c5658 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java @@ -13,16 +13,16 @@ package org.openhab.core.model.thing.test.hue; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.Item; import org.openhab.core.items.ItemRegistry; import org.openhab.core.model.core.ModelRepository; @@ -47,7 +47,7 @@ public class GenericItemChannelLinkProviderTest extends JavaOSGiTest { private ItemChannelLinkRegistry itemChannelLinkRegistry; private ItemChannelLinkProvider itemChannelLinkProvider; - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); @@ -65,7 +65,7 @@ public class GenericItemChannelLinkProviderTest extends JavaOSGiTest { modelRepository.removeModel(ITEMS_TESTMODEL_NAME); } - @After + @AfterEach public void tearDown() { modelRepository.removeModel(THINGS_TESTMODEL_NAME); modelRepository.removeModel(ITEMS_TESTMODEL_NAME); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java index 7bd7a36aa..298128215 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java @@ -14,8 +14,9 @@ package org.openhab.core.model.thing.test.hue; import static java.util.stream.Collectors.toSet; import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.core.IsCollectionContaining.hasItems; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsIterableContaining.hasItems; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.ByteArrayInputStream; import java.util.ArrayList; @@ -26,9 +27,9 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.events.EventFilter; import org.openhab.core.events.EventSubscriber; @@ -55,7 +56,7 @@ public class GenericThingProviderTest extends JavaOSGiTest { private ModelRepository modelRepository; private ThingRegistry thingRegistry; - @Before + @BeforeEach public void setUp() { thingRegistry = getService(ThingRegistry.class); assertThat(thingRegistry, is(notNullValue())); @@ -64,7 +65,7 @@ public class GenericThingProviderTest extends JavaOSGiTest { modelRepository.removeModel(TESTMODEL_NAME); } - @After + @AfterEach public void tearDown() { modelRepository.removeModel(TESTMODEL_NAME); } diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java index 8d6ff1594..73c938057 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest2.java @@ -13,15 +13,15 @@ package org.openhab.core.model.thing.test.hue; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; import java.io.ByteArrayInputStream; import java.util.Collection; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.model.core.ModelRepository; import org.openhab.core.model.thing.testsupport.hue.TestHueThingHandlerFactoryX; import org.openhab.core.test.java.JavaOSGiTest; @@ -40,7 +40,7 @@ public class GenericThingProviderTest2 extends JavaOSGiTest { private ModelRepository modelRepository; private ThingRegistry thingRegistry; - @Before + @BeforeEach public void setUp() { thingRegistry = getService(ThingRegistry.class); assertThat(thingRegistry, is(notNullValue())); @@ -49,7 +49,7 @@ public class GenericThingProviderTest2 extends JavaOSGiTest { modelRepository.removeModel(TESTMODEL_NAME); } - @After + @AfterEach public void tearDown() { modelRepository.removeModel(TESTMODEL_NAME); } diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java index 5e8f90e98..65d154e5e 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java @@ -14,7 +14,7 @@ package org.openhab.core.model.thing.test.hue; import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; @@ -25,9 +25,9 @@ import java.util.Collection; import java.util.Locale; import java.util.stream.Stream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionBuilder; import org.openhab.core.config.core.ConfigDescriptionParameter; @@ -59,7 +59,7 @@ public class GenericThingProviderTest3 extends JavaOSGiTest { private ModelRepository modelRepository; private ThingRegistry thingRegistry; - @Before + @BeforeEach public void setUp() throws Exception { thingRegistry = getService(ThingRegistry.class); assertThat(thingRegistry, is(notNullValue())); @@ -104,7 +104,7 @@ public class GenericThingProviderTest3 extends JavaOSGiTest { registerService(configDescriptionProvider); } - @After + @AfterEach public void tearDown() { unregisterService(dumbThingHandlerFactory); modelRepository.removeModel(TESTMODEL_NAME); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java index b568da733..7866c981e 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest4.java @@ -13,17 +13,17 @@ package org.openhab.core.model.thing.test.hue; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; import java.io.ByteArrayInputStream; +import java.util.stream.Stream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.openhab.core.model.core.ModelRepository; import org.openhab.core.model.thing.testsupport.hue.TestHueThingHandlerFactoryX; import org.openhab.core.model.thing.testsupport.hue.TestHueThingTypeProvider; @@ -53,7 +53,6 @@ import org.osgi.service.component.ComponentContext; * * @author Simon Kaufmann - Initial contribution and API. */ -@RunWith(Parameterized.class) public class GenericThingProviderTest4 extends JavaOSGiTest { private TestHueThingTypeProvider thingTypeProvider; private ReadyService readyService; @@ -62,20 +61,15 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { private boolean finished; private int bridgeInitializeCounter; private int thingInitializeCounter; - final boolean slowInit; + boolean slowInit; private static final String TESTMODEL_NAME = "testModelX.things"; ModelRepository modelRepository; ThingRegistry thingRegistry; - @Parameters(name = "{index}: slowInit={0}") - public static Object[] data() { - return new Object[] { false, true }; - } - - public GenericThingProviderTest4(boolean slowInit) { - this.slowInit = slowInit; + public static Stream data() { + return Stream.of(Arguments.of(false), Arguments.of(true)); } class TestBridgeHandler extends BaseBridgeHandler { @@ -106,7 +100,7 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { } } - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); @@ -156,7 +150,7 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { }); } - @After + @AfterEach public void tearDown() { modelRepository.removeModel(TESTMODEL_NAME); if (thingTypeProvider != null) { @@ -215,8 +209,10 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { }); } - @Test - public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithUpdateFactoryLoaded() { + @ParameterizedTest + @MethodSource("data") + public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithUpdateFactoryLoaded(boolean slowInit) { + this.slowInit = slowInit; assertThat(thingRegistry.getAll().size(), is(0)); updateModel(); assertThat(thingRegistry.getAll().size(), is(0)); @@ -227,8 +223,10 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { assertThatAllIsGood(); } - @Test - public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithFactoryUpdateLoaded() { + @ParameterizedTest + @MethodSource("data") + public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithFactoryUpdateLoaded(boolean slowInit) { + this.slowInit = slowInit; assertThat(thingRegistry.getAll().size(), is(0)); registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName()); assertThat(thingRegistry.getAll().size(), is(0)); @@ -239,8 +237,10 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { assertThatAllIsGood(); } - @Test - public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithLoadedFactoryUpdate() { + @ParameterizedTest + @MethodSource("data") + public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithLoadedFactoryUpdate(boolean slowInit) { + this.slowInit = slowInit; assertThat(thingRegistry.getAll().size(), is(0)); registerThingTypeProvider(); finishLoading(); @@ -251,8 +251,10 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { assertThatAllIsGood(); } - @Test - public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithLoadedUpdateFactory() { + @ParameterizedTest + @MethodSource("data") + public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithLoadedUpdateFactory(boolean slowInit) { + this.slowInit = slowInit; assertThat(thingRegistry.getAll().size(), is(0)); registerThingTypeProvider(); finishLoading(); @@ -263,8 +265,10 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { assertThatAllIsGood(); } - @Test - public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithFactoryLoadedUpdate() { + @ParameterizedTest + @MethodSource("data") + public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithFactoryLoadedUpdate(boolean slowInit) { + this.slowInit = slowInit; assertThat(thingRegistry.getAll().size(), is(0)); registerService(hueThingHandlerFactory, ThingHandlerFactory.class.getName()); assertThat(thingRegistry.getAll().size(), is(0)); @@ -275,8 +279,10 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { assertThatAllIsGood(); } - @Test - public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithUpdateLoadedFactory() { + @ParameterizedTest + @MethodSource("data") + public void assertThatThingsAreCreatedOnlyOnceTheBundleFinishedLoadingWithUpdateLoadedFactory(boolean slowInit) { + this.slowInit = slowInit; assertThat(thingRegistry.getAll().size(), is(0)); updateModel(); assertThat(thingRegistry.getAll().size(), is(0)); @@ -287,9 +293,11 @@ public class GenericThingProviderTest4 extends JavaOSGiTest { assertThatAllIsGood(); } - @Test + @ParameterizedTest + @MethodSource("data") @SuppressWarnings("null") - public void assertThatThingHandlersAreManagedCorrectlyOnUpdateWithFactoryLoaded() { + public void assertThatThingHandlersAreManagedCorrectlyOnUpdateWithFactoryLoaded(boolean slowInit) { + this.slowInit = slowInit; prepareThingWithShutDownBundle(); bridgeInitializeCounter = 0; diff --git a/itests/org.openhab.core.storage.json.tests/itest.bndrun b/itests/org.openhab.core.storage.json.tests/itest.bndrun index 5e68f9f42..79baf88cb 100644 --- a/itests/org.openhab.core.storage.json.tests/itest.bndrun +++ b/itests/org.openhab.core.storage.json.tests/itest.bndrun @@ -14,8 +14,6 @@ Fragment-Host: org.openhab.core.storage.json org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ @@ -36,4 +34,12 @@ Fragment-Host: org.openhab.core.storage.json org.openhab.core.config.core;version='[3.0.0,3.0.1)',\ org.openhab.core.storage.json;version='[3.0.0,3.0.1)',\ org.openhab.core.storage.json.tests;version='[3.0.0,3.0.1)',\ - org.openhab.core.test;version='[3.0.0,3.0.1)' + org.openhab.core.test;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java index 774aa437b..f78e850d2 100644 --- a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java +++ b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java @@ -13,7 +13,8 @@ package org.openhab.core.storage.json.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.IOException; @@ -27,10 +28,10 @@ import java.util.List; import java.util.UUID; import java.util.stream.Stream; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigConstants; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.CoreItemFactory; @@ -49,18 +50,18 @@ public class JsonStorageServiceOSGiTest extends JavaOSGiTest { private StorageService storageService; private Storage storage; - @Before + @BeforeEach public void setUp() { storageService = getService(StorageService.class); storage = storageService.getStorage(UUID.randomUUID().toString(), this.getClass().getClassLoader()); } - @After + @AfterEach public void tearDown() throws IOException { unregisterService(storageService); } - @AfterClass + @AfterAll public static void afterClass() throws IOException { // clean up database files ... final Path userData = Paths.get(ConfigConstants.getUserDataFolder()); diff --git a/itests/org.openhab.core.tests/itest.bndrun b/itests/org.openhab.core.tests/itest.bndrun index f41072517..4fcb61148 100644 --- a/itests/org.openhab.core.tests/itest.bndrun +++ b/itests/org.openhab.core.tests/itest.bndrun @@ -15,8 +15,6 @@ Fragment-Host: org.openhab.core org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -27,9 +25,6 @@ Fragment-Host: org.openhab.core org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\ @@ -38,4 +33,15 @@ Fragment-Host: org.openhab.core org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\ org.openhab.core;version='[3.0.0,3.0.1)',\ org.openhab.core.test;version='[3.0.0,3.0.1)',\ - org.openhab.core.tests;version='[3.0.0,3.0.1)' + org.openhab.core.tests;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)' diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/cache/ExpiringCacheAsyncTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/cache/ExpiringCacheAsyncTest.java index 1aa7468a5..07fb7fe01 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/cache/ExpiringCacheAsyncTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/cache/ExpiringCacheAsyncTest.java @@ -12,14 +12,14 @@ */ package org.openhab.core.cache; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Supplier; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaTest; /** @@ -31,10 +31,10 @@ public class ExpiringCacheAsyncTest extends JavaTest { private double theValue = 0; - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWrongCacheTime() { // Fail if cache time is <= 0 - new ExpiringCacheAsync<>(0); + assertThrows(IllegalArgumentException.class, () -> new ExpiringCacheAsync<>(0)); } @Test diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/common/SafeCallerImplTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/common/SafeCallerImplTest.java index 227e07da8..c54fc4207 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/common/SafeCallerImplTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/common/SafeCallerImplTest.java @@ -13,10 +13,11 @@ package org.openhab.core.internal.common; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.lang.Thread.State; import java.lang.management.ManagementFactory; @@ -36,11 +37,10 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Function; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.mockito.Mock; import org.openhab.core.common.QueueingThreadPoolExecutor; import org.openhab.core.test.java.JavaTest; @@ -66,17 +66,17 @@ public class SafeCallerImplTest extends JavaTest { private final Logger logger = LoggerFactory.getLogger(SafeCallerImplTest.class); - public @Rule TestName name = new TestName(); + private SafeCallerImpl safeCaller; + private QueueingThreadPoolExecutor scheduler; + private TestInfo testInfo; + private final List threads = new LinkedList<>(); + + private AutoCloseable mocksCloseable; private @Mock Runnable mockRunnable; private @Mock Runnable mockTimeoutHandler; private @Mock Consumer mockErrorHandler; - private QueueingThreadPoolExecutor scheduler; - private final List threads = new LinkedList<>(); - - private SafeCallerImpl safeCaller; - public static interface ITarget { public String method(); } @@ -91,10 +91,14 @@ public class SafeCallerImplTest extends JavaTest { public static class DerivedTarget extends Target implements ITarget { } - @Before - public void setup() { - initMocks(this); - scheduler = QueueingThreadPoolExecutor.createInstance(name.getMethodName(), THREAD_POOL_SIZE); + @BeforeEach + public void setup(TestInfo testInfo) { + this.testInfo = testInfo; + + mocksCloseable = openMocks(this); + + scheduler = QueueingThreadPoolExecutor.createInstance(testInfo.getTestMethod().get().getName(), + THREAD_POOL_SIZE); safeCaller = new SafeCallerImpl(null) { @Override protected ExecutorService getScheduler() { @@ -106,8 +110,10 @@ public class SafeCallerImplTest extends JavaTest { assertTrue(GRACE < TIMEOUT); } - @After - public void tearDown() throws Exception { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + // ensure all "inner" assertion errors are heard joinAll(); @@ -544,15 +550,15 @@ public class SafeCallerImplTest extends JavaTest { long durationMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos); try { if (low > -1) { - assertTrue(MessageFormat.format("Duration should have been above {0} but was {1}", low, - durationMillis), durationMillis >= low); + assertTrue(durationMillis >= low, MessageFormat + .format("Duration should have been above {0} but was {1}", low, durationMillis)); } if (high > -1) { - assertTrue(MessageFormat.format("Duration should have been below {0} but was {1}", high, - durationMillis), durationMillis < high); + assertTrue(durationMillis < high, MessageFormat + .format("Duration should have been below {0} but was {1}", high, durationMillis)); } } catch (AssertionError e) { - logger.debug("{}", createThreadDump(name.getMethodName())); + logger.debug("{}", createThreadDump(testInfo.getTestMethod().get().getName())); throw e; } } diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/events/OSGiEventManagerOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/events/OSGiEventManagerOSGiTest.java index 6888681be..0d5381ed3 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/events/OSGiEventManagerOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/events/OSGiEventManagerOSGiTest.java @@ -12,10 +12,10 @@ */ package org.openhab.core.internal.events; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.Collections; @@ -23,9 +23,9 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.openhab.core.events.Event; @@ -62,6 +62,8 @@ public class OSGiEventManagerOSGiTest extends JavaOSGiTest { private EventPublisher eventPublisher; + private AutoCloseable mocksCloseable; + private @Mock EventSubscriber subscriber1; private @Mock EventSubscriber subscriber2; private @Mock EventSubscriber subscriber3; @@ -69,9 +71,10 @@ public class OSGiEventManagerOSGiTest extends JavaOSGiTest { private @Mock EventFactory eventTypeFactoryAB; private @Mock EventFactory eventTypeFactoryC; - @Before - public void setUp() throws Exception { - initMocks(this); + @BeforeEach + public void beforeEach() throws Exception { + mocksCloseable = openMocks(this); + eventPublisher = getService(EventPublisher.class); assertNotNull(eventPublisher); @@ -102,8 +105,9 @@ public class OSGiEventManagerOSGiTest extends JavaOSGiTest { internalRegisterService(ALL_EVENT_TYPES_SUBSCRIBER_4, EventSubscriber.class, subscriber4); } - @After - public void cleanUp() { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); for (ServiceRegistration service : serviceRegistrations.values()) { service.unregister(); } diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java index 3b2da9392..070732408 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java @@ -13,14 +13,14 @@ package org.openhab.core.internal.i18n; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.i18n.LocaleProvider; import org.openhab.core.i18n.TranslationProvider; import org.openhab.core.test.java.JavaOSGiTest; @@ -56,7 +56,7 @@ public class TranslationProviderOSGiTest extends JavaOSGiTest { TranslationProvider translationProvider; - @Before + @BeforeEach public void setup() { translationProvider = getService(TranslationProvider.class); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java index 2af7054f9..64f8dcb47 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java @@ -12,7 +12,7 @@ */ package org.openhab.core.internal.items; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collections; import java.util.Set; @@ -20,8 +20,8 @@ import java.util.concurrent.ConcurrentLinkedQueue; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.events.EventFilter; import org.openhab.core.events.EventPublisher; @@ -48,7 +48,7 @@ public class ItemUpdaterOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) ItemRegistry itemRegistry; private final ConcurrentLinkedQueue receivedEvents = new ConcurrentLinkedQueue<>(); - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); eventPublisher = getService(EventPublisher.class); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java index 6e72d799f..5156bf93a 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java @@ -13,10 +13,11 @@ package org.openhab.core.items; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.HashSet; import java.util.LinkedList; @@ -29,9 +30,10 @@ import javax.measure.quantity.Dimensionless; import javax.measure.quantity.Pressure; import javax.measure.quantity.Temperature; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.events.Event; import org.openhab.core.events.EventFilter; @@ -78,15 +80,17 @@ public class GroupItemOSGiTest extends JavaOSGiTest { private ItemRegistry itemRegistry; - @Mock - private UnitProvider unitProvider; + private AutoCloseable mocksCloseable; + + private @Mock UnitProvider unitProvider; private final GroupFunctionHelper groupFunctionHelper = new GroupFunctionHelper(); private ItemStateConverter itemStateConverter; - @Before - public void setUp() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); + registerVolatileStorageService(); publisher = event -> events.add(event); @@ -118,7 +122,12 @@ public class GroupItemOSGiTest extends JavaOSGiTest { itemStateConverter = new ItemStateConverterImpl(unitProvider); } - @Ignore + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + + @Disabled @Test public void testItemUpdateWithItemRegistry() { GroupItem item = new GroupItem("mySimpleGroupItem"); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java index 38dea42cf..325ed064b 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java @@ -14,19 +14,21 @@ package org.openhab.core.items; import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.core.IsCollectionContaining.hasItem; -import static org.junit.Assert.*; +import static org.hamcrest.core.IsIterableContaining.hasItem; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.InOrder; import org.mockito.Mock; @@ -70,12 +72,13 @@ public class ItemRegistryImplTest extends JavaTest { private ItemRegistry itemRegistry; private ManagedItemProvider itemProvider; - @Mock - private EventPublisher eventPublisher; + private AutoCloseable mocksCloseable; - @Before - public void setUp() { - initMocks(this); + private @Mock EventPublisher eventPublisher; + + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); ItemFactory coreItemFactory = new CoreItemFactory(); @@ -115,6 +118,11 @@ public class ItemRegistryImplTest extends JavaTest { }; } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void assertGetItemsReturnsItemFromRegisteredItemProvider() { List items = new ArrayList<>(itemRegistry.getItems()); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ManagedItemProviderOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ManagedItemProviderOSGiTest.java index f0a924363..109c2e0be 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ManagedItemProviderOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ManagedItemProviderOSGiTest.java @@ -13,15 +13,16 @@ package org.openhab.core.items; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collection; import java.util.Collections; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.items.ManagedItemProvider.PersistedItem; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.library.items.NumberItem; @@ -51,14 +52,14 @@ public class ManagedItemProviderOSGiTest extends JavaOSGiTest { private ManagedItemProvider itemProvider; private ItemRegistry itemRegistry; - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); itemProvider = getService(ManagedItemProvider.class); itemRegistry = getService(ItemRegistry.class); } - @After + @AfterEach public void tearDown() { for (Item item : itemProvider.getAll()) { itemProvider.remove(item.getName()); @@ -143,12 +144,12 @@ public class ManagedItemProviderOSGiTest extends JavaOSGiTest { assertThat(itemProvider.getAll().size(), is(0)); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertTwoItemsWithSameNameCanNotBeAdded() { assertThat(itemProvider.getAll().size(), is(0)); itemProvider.add(new StringItem("Item")); - itemProvider.add(new StringItem("Item")); + assertThrows(IllegalArgumentException.class, () -> itemProvider.add(new StringItem("Item"))); } @Test diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/events/AbstractItemEventSubscriberOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/events/AbstractItemEventSubscriberOSGiTest.java index c828cecc8..cd5a5a69e 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/events/AbstractItemEventSubscriberOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/events/AbstractItemEventSubscriberOSGiTest.java @@ -12,15 +12,16 @@ */ package org.openhab.core.items.events; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Collections; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.events.Event; import org.openhab.core.events.EventFactory; @@ -44,14 +45,17 @@ public class AbstractItemEventSubscriberOSGiTest extends JavaOSGiTest { private static final String ITEM_NAME = "SomeItem"; private EventPublisher eventPublisher; - private @Mock ItemProvider itemProvider; private ItemCommandEvent commandEvent; private ItemStateEvent updateEvent; + + private AutoCloseable mocksCloseable; + + private @Mock ItemProvider itemProvider; private @Mock MetadataProvider mockMetadataProvider; - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); eventPublisher = getService(EventPublisher.class); assertNotNull(eventPublisher); @@ -77,6 +81,11 @@ public class AbstractItemEventSubscriberOSGiTest extends JavaOSGiTest { registerService(mockMetadataProvider); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void testReceive() { eventPublisher.post(ItemEventFactory.createCommandEvent(ITEM_NAME, OnOffType.ON)); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/service/AbstractWatchServiceTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/service/AbstractWatchServiceTest.java index 9abfd70d8..cdeffb70c 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/service/AbstractWatchServiceTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/service/AbstractWatchServiceTest.java @@ -14,7 +14,7 @@ package org.openhab.core.service; import static java.nio.file.StandardWatchEventKinds.*; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.File; import java.nio.file.Files; @@ -28,10 +28,10 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Stream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaTest; /** @@ -51,7 +51,7 @@ public class AbstractWatchServiceTest extends JavaTest { private RelativeWatchService watchService; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { // set the NO_EVENT_TIMEOUT_IN_SECONDS according to the operating system used if (System.getProperty("os.name").startsWith("Mac OS X")) { @@ -61,13 +61,13 @@ public class AbstractWatchServiceTest extends JavaTest { } } - @Before + @BeforeEach public void setup() { File watchDir = new File(WATCHED_DIRECTORY); watchDir.mkdirs(); } - @After + @AfterEach public void tearDown() throws Exception { watchService.deactivate(); final Path watchedDirectory = Paths.get(WATCHED_DIRECTORY); diff --git a/itests/org.openhab.core.thing.tests/itest.bndrun b/itests/org.openhab.core.thing.tests/itest.bndrun index 280d6c7de..68ba38714 100644 --- a/itests/org.openhab.core.thing.tests/itest.bndrun +++ b/itests/org.openhab.core.thing.tests/itest.bndrun @@ -19,8 +19,6 @@ Fragment-Host: org.openhab.core.thing org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.objenesis;version='[2.6.0,2.6.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ @@ -32,9 +30,6 @@ Fragment-Host: org.openhab.core.thing org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\ tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\ tec.uom.se;version='[1.0.10,1.0.11)',\ - net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\ - net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\ - org.mockito.mockito-core;version='[3.1.0,3.1.1)',\ org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\ org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\ @@ -48,4 +43,15 @@ Fragment-Host: org.openhab.core.thing org.openhab.core.test;version='[3.0.0,3.0.1)',\ org.openhab.core.thing;version='[3.0.0,3.0.1)',\ org.openhab.core.thing.tests;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing.xml;version='[3.0.0,3.0.1)' + org.openhab.core.thing.xml;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\ + net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.mockito.mockito-core;version='[3.4.6,3.4.7)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java index f2a05d661..3783f7ed1 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/SystemWideChannelTypesTest.java @@ -12,15 +12,15 @@ */ package org.openhab.core.thing; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.openhab.core.thing.DefaultSystemChannelTypeProvider.BINDING_ID; import java.util.Collection; import java.util.List; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.type.ChannelType; import org.openhab.core.thing.type.ChannelTypeProvider; @@ -68,7 +68,7 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { private ChannelTypeProvider systemChannelTypeProvider; - @Before + @BeforeEach public void setUp() { ChannelTypeProvider provider = getService(ChannelTypeProvider.class, DefaultSystemChannelTypeProvider.class); assertTrue(provider instanceof DefaultSystemChannelTypeProvider); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingPropertiesTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingPropertiesTest.java index 7b2641d28..916be57b3 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingPropertiesTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingPropertiesTest.java @@ -12,13 +12,13 @@ */ package org.openhab.core.thing; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.Configuration; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.binding.ThingFactory; @@ -42,7 +42,7 @@ public class ThingPropertiesTest extends JavaOSGiTest { private Thing thing; private final String nullString = null; // trick the null-annotation tooling - @Before + @BeforeEach public void setup() { ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("bindingId", "thingTypeId"), "label") .withProperties(properties).build(); @@ -85,13 +85,13 @@ public class ThingPropertiesTest extends JavaOSGiTest { assertEquals("value2", thing.getProperties().get("key2")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testSetPropertyNullKey() { - thing.setProperty(nullString, ""); + assertThrows(IllegalArgumentException.class, () -> thing.setProperty(nullString, "")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testSetPropertyEmptyName() { - thing.setProperty("", ""); + assertThrows(IllegalArgumentException.class, () -> thing.setProperty("", "")); } } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java index 9ba04b5e4..bfb0c8dea 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java @@ -14,9 +14,11 @@ package org.openhab.core.thing.binding; import static java.util.Collections.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; +import static org.mockito.MockitoAnnotations.openMocks; import java.lang.reflect.Field; import java.net.URI; @@ -31,16 +33,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.hamcrest.CoreMatchers; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; import org.mockito.stubbing.Answer; import org.openhab.core.common.registry.RegistryChangeListener; import org.openhab.core.config.core.ConfigDescription; @@ -99,12 +98,14 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { private ManagedThingProvider managedThingProvider; private ThingRegistry thingRegistry; + private AutoCloseable mocksCloseable; + private @Mock ComponentContext componentContext; - public @Rule MockitoRule rule = MockitoJUnit.rule(); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); - @Before - public void setup() { registerVolatileStorageService(); managedThingProvider = getService(ManagedThingProvider.class); assertThat(managedThingProvider, is(notNullValue())); @@ -113,8 +114,10 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { when(componentContext.getBundleContext()).thenReturn(bundleContext); } - @After - public void teardown() { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + managedThingProvider.getAll().forEach(t -> managedThingProvider.remove(t.getUID())); } @@ -570,7 +573,7 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { } } - @Test(expected = ConfigValidationException.class) + @Test public void assertConfigurationParametersAreValidated() { SimpleThingHandlerFactory thingHandlerFactory = new SimpleThingHandlerFactory(); thingHandlerFactory.activate(componentContext); @@ -589,7 +592,8 @@ public class BindingBaseClassesOSGiTest extends JavaOSGiTest { Map configuration = new HashMap<>(); configuration.put("parameter", null); - thingRegistry.updateConfiguration(thingUID, singletonMap("parameter", configuration)); + assertThrows(ConfigValidationException.class, + () -> thingRegistry.updateConfiguration(thingUID, singletonMap("parameter", configuration))); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java index 885704350..4d96df1f2 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java @@ -13,7 +13,7 @@ package org.openhab.core.thing.binding; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -27,8 +27,8 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionBuilder; import org.openhab.core.config.core.ConfigDescriptionParameter; @@ -111,7 +111,7 @@ public class ChangeThingTypeOSGiTest extends JavaOSGiTest { private int genericInits = 0; private int unregisterHandlerDelay = 0; - @Before + @BeforeEach public void setup() throws URISyntaxException { registerVolatileStorageService(); managedThingProvider = getService(ManagedThingProvider.class); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java index c7fcadb70..8a4d0e4bc 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java @@ -15,7 +15,7 @@ package org.openhab.core.thing.binding; import static java.util.Collections.*; import static java.util.stream.Collectors.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; @@ -31,7 +31,7 @@ import java.util.Map; import java.util.stream.Stream; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.openhab.core.config.core.ConfigDescription; diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java index edcb5b9ae..1589fb7a2 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java @@ -13,7 +13,8 @@ package org.openhab.core.thing.binding.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.io.BufferedInputStream; import java.io.IOException; @@ -23,7 +24,7 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -116,11 +117,12 @@ public class FirmwareTest extends JavaOSGiTest { assertThat(firmware.getFirmwareRestriction(), is(restrictionFunction)); } - @Test(expected = IllegalArgumentException.class) + @Test public void modelRestrictedWithoutModel() { ThingTypeUID sampleThingTypeUID = new ThingTypeUID("binding", "sampleThingType"); String version = "1.0.0"; - FirmwareBuilder.create(sampleThingTypeUID, version).withModelRestricted(true).build(); + assertThrows(IllegalArgumentException.class, + () -> FirmwareBuilder.create(sampleThingTypeUID, version).withModelRestricted(true).build()); } @Test @@ -281,12 +283,12 @@ public class FirmwareTest extends JavaOSGiTest { assertThat(bytes, is(notNullValue())); } - @Test(expected = IllegalStateException.class) + @Test public void assertThatFirmwareWithInvalidMD5HashValueThrowsExceptionForGetBytes() throws IOException { Firmware firmware = FirmwareBuilder.create(THING_TYPE_UID, "1") .withInputStream(bundleContext.getBundle().getResource(FILE_NAME).openStream()) .withMd5Hash("78805a221a988e79ef3f42d7c5bfd419").build(); - firmware.getBytes(); + assertThrows(IllegalStateException.class, () -> firmware.getBytes()); } @Test @@ -353,19 +355,19 @@ public class FirmwareTest extends JavaOSGiTest { assertThat(firmware1.hashCode(), is(firmware2.hashCode())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullThingTypeOnCreation() { - FirmwareBuilder.create(giveNull(), "1"); + assertThrows(IllegalArgumentException.class, () -> FirmwareBuilder.create(giveNull(), "1")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullFirmwareVersionOnCreation() { - FirmwareBuilder.create(THING_TYPE_UID, giveNull()); + assertThrows(IllegalArgumentException.class, () -> FirmwareBuilder.create(THING_TYPE_UID, giveNull())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyVersionOnCreation() { - FirmwareBuilder.create(THING_TYPE_UID, ""); + assertThrows(IllegalArgumentException.class, () -> FirmwareBuilder.create(THING_TYPE_UID, "")); } private Firmware firmwareWithVersion(String version) { diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/events/ThingEventFactoryTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/events/ThingEventFactoryTest.java index 3745b78c6..e42c6be66 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/events/ThingEventFactoryTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/events/ThingEventFactoryTest.java @@ -13,9 +13,10 @@ package org.openhab.core.thing.events; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.ChannelUID; diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/factory/ManagedThingProviderOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/factory/ManagedThingProviderOSGiTest.java index fe851d7be..c4c344c06 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/factory/ManagedThingProviderOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/factory/ManagedThingProviderOSGiTest.java @@ -13,15 +13,16 @@ package org.openhab.core.thing.factory; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collection; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.common.registry.Provider; import org.openhab.core.common.registry.ProviderChangeListener; import org.openhab.core.test.AsyncResultWrapper; @@ -49,7 +50,7 @@ public class ManagedThingProviderOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) ManagedThingProvider managedThingProvider; private @NonNullByDefault({}) ProviderChangeListener<@NonNull Thing> thingChangeListener; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); managedThingProvider = getService(ManagedThingProvider.class); @@ -57,7 +58,7 @@ public class ManagedThingProviderOSGiTest extends JavaOSGiTest { unregisterCurrentThingsChangeListener(); } - @After + @AfterEach public void teardown() { unregisterCurrentThingsChangeListener(); managedThingProvider.getAll().forEach(t -> managedThingProvider.remove(t.getUID())); @@ -92,12 +93,12 @@ public class ManagedThingProviderOSGiTest extends JavaOSGiTest { assertTrue(things.contains(thing2)); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatTwiceAddedThingThrowsException() { Thing thing1 = ThingBuilder.create(THING_TYPE_UID, THING1_ID).build(); Thing thing2 = ThingBuilder.create(THING_TYPE_UID, THING1_ID).build(); managedThingProvider.add(thing1); - managedThingProvider.add(thing2); + assertThrows(IllegalArgumentException.class, () -> managedThingProvider.add(thing2)); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServiceFirmwareRestrictionTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServiceFirmwareRestrictionTest.java index 2881224f8..7622a0098 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServiceFirmwareRestrictionTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServiceFirmwareRestrictionTest.java @@ -13,7 +13,7 @@ package org.openhab.core.thing.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -23,9 +23,9 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -56,12 +56,12 @@ public class FirmwareUpdateServiceFirmwareRestrictionTest extends JavaOSGiTest { private FirmwareProvider lambdaFirmwareProvider; - @Before + @BeforeEach public void setup() { thingTypeUID = new ThingTypeUID("customBinding:type"); } - @After + @AfterEach public void tearDown() { unregisterSingleFirmwareProvider(); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServicePrerequisiteVersionTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServicePrerequisiteVersionTest.java index 3b77b9914..e56bff9ef 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServicePrerequisiteVersionTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/FirmwareUpdateServicePrerequisiteVersionTest.java @@ -13,7 +13,7 @@ package org.openhab.core.thing.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -24,8 +24,8 @@ import java.util.HashSet; import java.util.Locale; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -50,7 +50,7 @@ public class FirmwareUpdateServicePrerequisiteVersionTest extends JavaOSGiTest { private Thing thingWithFirmwareV1; private Thing thingWithFirmwareV2; - @Before + @BeforeEach public void setup() { thingTypeUID = new ThingTypeUID("binding:thingtype"); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/ModelRestrictedFirmwareUpdateServiceOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/ModelRestrictedFirmwareUpdateServiceOSGiTest.java index 5e254c79e..fa059bef6 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/ModelRestrictedFirmwareUpdateServiceOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/ModelRestrictedFirmwareUpdateServiceOSGiTest.java @@ -13,7 +13,7 @@ package org.openhab.core.thing.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.openhab.core.thing.Thing.*; import static org.openhab.core.thing.firmware.FirmwareStatus.*; @@ -23,8 +23,8 @@ import java.util.HashSet; import java.util.Locale; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.ManagedThingProvider; import org.openhab.core.thing.Thing; @@ -67,7 +67,7 @@ public class ModelRestrictedFirmwareUpdateServiceOSGiTest extends JavaOSGiTest { private FirmwareUpdateService firmwareUpdateService; private ManagedThingProvider managedThingProvider; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.java index 8d05f8cbf..d64bdda07 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.java @@ -13,15 +13,16 @@ package org.openhab.core.thing.i18n; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; import java.io.IOException; import java.util.Locale; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.i18n.LocaleProvider; import org.openhab.core.test.SyntheticBundleInstaller; import org.openhab.core.test.java.JavaOSGiTest; @@ -183,9 +184,10 @@ public class ThingStatusInfoI18nLocalizationServiceOSGiTest extends JavaOSGiTest assertThat(info, is(ThingStatusInfoBuilder.create(ThingStatus.UNINITIALIZED, ThingStatusDetail.NONE).build())); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullThingIsRejected() { - thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(null, null); + assertThrows(IllegalArgumentException.class, + () -> thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(null, null)); } @Test @@ -213,7 +215,7 @@ public class ThingStatusInfoI18nLocalizationServiceOSGiTest extends JavaOSGiTest "Some test text with params: some other text - 60"))); } - @Before + @BeforeEach public void setup() throws Exception { LocaleProvider localeProvider = getService(LocaleProvider.class); assertThat(localeProvider, is(notNullValue())); @@ -248,7 +250,7 @@ public class ThingStatusInfoI18nLocalizationServiceOSGiTest extends JavaOSGiTest thingStatusInfoI18nLocalizationService.setBundleResolver(new BundleResolverImpl()); } - @After + @AfterEach public void tearDown() throws IOException, BundleException { testBundle.uninstall(); managedThingProvider.remove(thing.getUID()); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java index e039d5851..55d62a679 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java @@ -13,8 +13,9 @@ package org.openhab.core.thing.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.MockitoAnnotations.openMocks; import java.math.BigDecimal; import java.util.ArrayList; @@ -25,9 +26,9 @@ import java.util.Locale; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.openhab.core.common.registry.ProviderChangeListener; @@ -73,7 +74,6 @@ import org.openhab.core.types.StateDescriptionFragmentBuilder; import org.openhab.core.types.StateOption; import org.openhab.core.util.BundleResolver; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; import org.osgi.framework.FrameworkUtil; import org.osgi.service.component.ComponentContext; @@ -88,6 +88,8 @@ public class ChannelCommandDescriptionProviderOSGiTest extends JavaOSGiTest { private static final String TEST_BUNDLE_NAME = "thingStatusInfoI18nTest.bundle"; private static final ChannelTypeUID CHANNEL_TYPE_UID = new ChannelTypeUID("hue:dynamic"); + private @NonNullByDefault({}) AutoCloseable mocksCloseable; + private @Mock @NonNullByDefault({}) ComponentContext componentContextMock; private @NonNullByDefault({}) ItemRegistry itemRegistry; @@ -95,9 +97,9 @@ public class ChannelCommandDescriptionProviderOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) Bundle testBundle; private @NonNullByDefault({}) ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService; - @Before - public void setup() throws Exception { - initMocks(this); + @BeforeEach + public void beforeEach() throws Exception { + mocksCloseable = openMocks(this); Mockito.when(componentContextMock.getBundleContext()).thenReturn(bundleContext); @@ -173,8 +175,9 @@ public class ChannelCommandDescriptionProviderOSGiTest extends JavaOSGiTest { linkRegistry = getService(ItemChannelLinkRegistry.class); } - @After - public void teardown() throws BundleException { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); testBundle.uninstall(); ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class); assertNotNull(managedThingProvider); @@ -210,7 +213,12 @@ public class ChannelCommandDescriptionProviderOSGiTest extends JavaOSGiTest { Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration()); + assertNotNull(thing); + if (thing == null) { + throw new IllegalStateException("thing is null"); + } + managedThingProvider.add(thing); ItemChannelLink link = new ItemChannelLink("TestItem1", getChannel(thing, "1").getUID()); linkRegistry.add(link); @@ -278,6 +286,10 @@ public class ChannelCommandDescriptionProviderOSGiTest extends JavaOSGiTest { Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration()); assertNotNull(thing); + if (thing == null) { + throw new IllegalStateException("thing is null"); + } + managedThingProvider.add(thing); ItemChannelLink link = new ItemChannelLink("TestItem7_2", getChannel(thing, "7_2").getUID()); linkRegistry.add(link); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java index 366409bb7..f4ba6314b 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java @@ -13,8 +13,9 @@ package org.openhab.core.thing.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.MockitoAnnotations.openMocks; import java.math.BigDecimal; import java.util.ArrayList; @@ -26,9 +27,9 @@ import java.util.Locale; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.openhab.core.common.registry.ProviderChangeListener; @@ -74,7 +75,6 @@ import org.openhab.core.types.StateDescriptionFragmentBuilder; import org.openhab.core.types.StateOption; import org.openhab.core.util.BundleResolver; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; import org.osgi.framework.FrameworkUtil; import org.osgi.service.component.ComponentContext; @@ -91,6 +91,8 @@ 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 @NonNullByDefault({}) AutoCloseable mocksCloseable; + private @Mock @NonNullByDefault({}) ComponentContext componentContext; private @NonNullByDefault({}) ItemRegistry itemRegistry; @@ -98,9 +100,9 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { private @NonNullByDefault({}) Bundle testBundle; private @NonNullByDefault({}) ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService; - @Before - public void setup() throws Exception { - initMocks(this); + @BeforeEach + public void beforeEach() throws Exception { + mocksCloseable = openMocks(this); Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext); @@ -196,8 +198,9 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { linkRegistry = getService(ItemChannelLinkRegistry.class); } - @After - public void teardown() throws BundleException { + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); testBundle.uninstall(); ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class); assertNotNull(managedThingProvider); @@ -233,7 +236,12 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration()); + assertNotNull(thing); + if (thing == null) { + throw new IllegalStateException("thing is null"); + } + managedThingProvider.add(thing); ItemChannelLink link = new ItemChannelLink("TestItem", getChannel(thing, "1").getUID()); linkRegistry.add(link); @@ -375,7 +383,12 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration()); + assertNotNull(thing); + if (thing == null) { + throw new IllegalStateException("thing is null"); + } + managedThingProvider.add(thing); ItemChannelLink link = new ItemChannelLink("TestItem7_2", getChannel(thing, "7_2").getUID()); linkRegistry.add(link); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java index f99808616..873d2ecb1 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java @@ -12,10 +12,10 @@ */ package org.openhab.core.thing.internal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.Collection; @@ -25,8 +25,9 @@ import java.util.stream.Stream; import javax.measure.quantity.Temperature; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.openhab.core.common.SafeCaller; @@ -133,6 +134,8 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest { ChannelBuilder.create(TRIGGER_CHANNEL_UID_1).withKind(ChannelKind.TRIGGER).build(), ChannelBuilder.create(TRIGGER_CHANNEL_UID_2).withKind(ChannelKind.TRIGGER).build()).build(); + private @NonNullByDefault({}) AutoCloseable mocksCloseable; + private @Mock @NonNullByDefault({}) AutoUpdateManager autoUpdateManagerMock; private @Mock @NonNullByDefault({}) ChannelTypeRegistry channelTypeRegistryMock; private @Mock @NonNullByDefault({}) EventPublisher eventPublisherMock; @@ -151,15 +154,19 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest { private ItemChannelLinkRegistryAdvanced iclRegistry = new ItemChannelLinkRegistryAdvanced(thingRegistryMock, itemRegistryMock); - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); safeCaller = getService(SafeCaller.class); assertNotNull(safeCaller); SystemProfileFactory profileFactory = getService(ProfileTypeProvider.class, SystemProfileFactory.class); + assertNotNull(profileFactory); + if (profileFactory == null) { + throw new IllegalStateException("thing is null"); + } manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry, itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock); @@ -227,6 +234,11 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest { ITEM_4.setUnitProvider(unitProvider); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void testStateUpdatedSingleLink() { manager.stateUpdated(STATE_CHANNEL_UID_1, OnOffType.ON); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java index ed7cc3799..f43b7e69f 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java @@ -13,7 +13,8 @@ package org.openhab.core.thing.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -28,9 +29,9 @@ import java.util.function.Function; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.openhab.core.common.SafeCaller; import org.openhab.core.config.core.ConfigDescriptionBuilder; @@ -129,7 +130,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { private @NonNullByDefault({}) URI configDescriptionThing; private @NonNullByDefault({}) Thing thing; - @Before + @BeforeEach public void setUp() throws Exception { configDescriptionChannel = new URI("test:channel"); configDescriptionThing = new URI("test:test"); @@ -180,7 +181,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { }); } - @After + @AfterEach public void teardown() throws Exception { managedThingProvider.getAll().forEach(it -> { managedThingProvider.remove(it.getUID()); @@ -247,11 +248,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { assertTrue(thc.get().isChannelLinked(CHANNEL_UID)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateChannelBuilderThrowsIllegalArgumentException() throws Exception { AtomicReference thc = initializeThingHandlerCallback(); - thc.get().createChannelBuilder(CHANNEL_UID, new ChannelTypeUID(BINDING_ID, "invalid-channel")); + assertThrows(IllegalArgumentException.class, + () -> thc.get().createChannelBuilder(CHANNEL_UID, new ChannelTypeUID(BINDING_ID, "invalid-channel"))); } @Test @@ -263,11 +265,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { validateChannel(channelBuilder.build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEditChannelBuilderThrowsIllegalArgumentException() throws Exception { AtomicReference thc = initializeThingHandlerCallback(); - thc.get().editChannel(thing, new ChannelUID(THING_UID, "invalid-channel")); + assertThrows(IllegalArgumentException.class, + () -> thc.get().editChannel(thing, new ChannelUID(THING_UID, "invalid-channel"))); } @Test @@ -279,12 +282,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { validateChannel(channelBuilder.build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCreateChannelGroupBuilderThrowsIllegalArgumentException() throws Exception { AtomicReference thc = initializeThingHandlerCallback(); - thc.get().createChannelBuilders(CHANNEL_GROUP_UID, - new ChannelGroupTypeUID(BINDING_ID, "invalid-channel-group")); + assertThrows(IllegalArgumentException.class, () -> thc.get().createChannelBuilders(CHANNEL_GROUP_UID, + new ChannelGroupTypeUID(BINDING_ID, "invalid-channel-group"))); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java index b7a489b13..eeae65df9 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java @@ -14,7 +14,8 @@ package org.openhab.core.thing.internal; import static java.util.Collections.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; @@ -32,9 +33,9 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.openhab.core.common.registry.RegistryChangeListener; @@ -129,7 +130,7 @@ public class ThingManagerOSGiTest extends JavaOSGiTest { private ReadyService readyService; private Thing thing; - @Before + @BeforeEach @SuppressWarnings("null") public void setUp() { thing = ThingBuilder.create(THING_TYPE_UID, THING_UID) @@ -187,7 +188,7 @@ public class ThingManagerOSGiTest extends JavaOSGiTest { thingManager.setBundleResolver(bundleResolver); } - @After + @AfterEach public void teardown() { managedThingProvider.getAll().forEach(t -> managedThingProvider.remove(t.getUID())); ComponentContext componentContext = mock(ComponentContext.class); @@ -215,7 +216,7 @@ public class ThingManagerOSGiTest extends JavaOSGiTest { ThingTypeUID newThingTypeUID = new ThingTypeUID("binding:type2"); ThingTypeMigrationService migrator = getService(ThingTypeMigrationService.class); - assertThat(migrator, is(not(nullValue()))); + assertThat(migrator, is(notNullValue())); migrator.migrateThingType(thing, newThingTypeUID, thing.getConfiguration()); @@ -283,7 +284,7 @@ public class ThingManagerOSGiTest extends JavaOSGiTest { assertThat(state.raceCondition, is(false)); } - @Test(expected = RuntimeException.class) + @Test @SuppressWarnings("null") public void thingManagerDoesNotChangeTheThingTypeWhenNewThingTypeIsNotRegistered() { ThingHandler thingHandler = mock(ThingHandler.class); @@ -302,9 +303,10 @@ public class ThingManagerOSGiTest extends JavaOSGiTest { ThingTypeUID newThingTypeUID = new ThingTypeUID("binding:type2"); ThingTypeMigrationService migrator = getService(ThingTypeMigrationService.class); - assertThat(migrator, is(not(null))); + assertThat(migrator, is(notNullValue())); - migrator.migrateThingType(thing, newThingTypeUID, thing.getConfiguration()); + assertThrows(RuntimeException.class, + () -> migrator.migrateThingType(thing, newThingTypeUID, thing.getConfiguration())); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java index 7fa4862d9..84bd226b4 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java @@ -13,7 +13,8 @@ package org.openhab.core.thing.internal; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collection; import java.util.Collections; @@ -25,9 +26,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.common.registry.ProviderChangeListener; import org.openhab.core.config.core.Configuration; import org.openhab.core.events.Event; @@ -73,14 +74,14 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { private @Nullable Map changedParameters = null; private @Nullable Event receivedEvent = null; - @Before + @BeforeEach public void setUp() { registerVolatileStorageService(); managedThingProvider = getService(ManagedThingProvider.class); unregisterCurrentThingHandlerFactory(); } - @After + @AfterEach public void teardown() { unregisterCurrentThingHandlerFactory(); managedThingProvider.getAll().stream().forEach(it -> managedThingProvider.remove(it.getUID())); @@ -183,13 +184,13 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { assertThat(changedParameters.entrySet(), is(equalTo(parameters.entrySet()))); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertThatThingRegistryThrowsExceptionForConfigUpdateOfNonExistingThing() { ThingRegistry thingRegistry = getService(ThingRegistry.class); - ThingUID thingUID = new ThingUID(THING_TYPE_UID, "binding:type:thing"); + ThingUID thingUID = new ThingUID(THING_TYPE_UID, "thing"); Map parameters = new HashMap<>(); parameters.put("param", "value1"); - thingRegistry.updateConfiguration(thingUID, parameters); + assertThrows(IllegalArgumentException.class, () -> thingRegistry.updateConfiguration(thingUID, parameters)); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryOSGiTest.java index 78674de20..cbf2d7af5 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryOSGiTest.java @@ -13,7 +13,7 @@ package org.openhab.core.thing.internal.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.openhab.core.thing.firmware.Constants.*; import java.io.IOException; @@ -28,9 +28,9 @@ import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.i18n.LocaleProvider; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.Thing; @@ -193,7 +193,7 @@ public class FirmwareRegistryOSGiTest extends JavaOSGiTest { private Thing thing2; private Thing thing3; - @Before + @BeforeEach public void setup() throws IOException { LocaleProvider localeProvider = getService(LocaleProvider.class); assertThat(localeProvider, is(notNullValue())); @@ -212,7 +212,7 @@ public class FirmwareRegistryOSGiTest extends JavaOSGiTest { thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).build(); } - @After + @AfterEach public void teardown() throws IOException { new DefaultLocaleSetter(getService(ConfigurationAdmin.class)).setDefaultLocale(defaultLocale); waitForAssert(() -> assertThat(getService(LocaleProvider.class).getLocale(), is(defaultLocale))); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java index a4a34395f..fac2588f0 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java @@ -13,11 +13,12 @@ package org.openhab.core.thing.internal.firmware; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.openhab.core.thing.firmware.Constants.*; import static org.openhab.core.thing.firmware.FirmwareStatusInfo.*; @@ -38,11 +39,9 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.stubbing.Answer; @@ -84,45 +83,27 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { public static final ProgressStep[] SEQUENCE = new ProgressStep[] { ProgressStep.REBOOTING, ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING, ProgressStep.UPDATING }; - @Rule - public ExpectedException thrown = ExpectedException.none(); - private Thing thing1; private Thing thing2; private Thing thing3; private FirmwareUpdateServiceImpl firmwareUpdateService; - @Mock - private FirmwareRegistry mockFirmwareRegistry; + private AutoCloseable mocksCloseable; - @Mock - private FirmwareUpdateHandler handler1; + private @Mock FirmwareRegistry mockFirmwareRegistry; + private @Mock FirmwareUpdateHandler handler1; + private @Mock FirmwareUpdateHandler handler2; + private @Mock FirmwareUpdateHandler handler3; + private @Mock EventPublisher mockPublisher; + private @Mock LocaleProvider mockLocaleProvider; + private @Mock TranslationProvider mockTranslationProvider; + private @Mock ConfigDescriptionValidator mockConfigDescriptionValidator; + private @Mock BundleResolver bundleResolver; - @Mock - private FirmwareUpdateHandler handler2; - - @Mock - private FirmwareUpdateHandler handler3; - - @Mock - private EventPublisher mockPublisher; - - @Mock - private LocaleProvider mockLocaleProvider; - - @Mock - private TranslationProvider mockTranslationProvider; - - @Mock - private ConfigDescriptionValidator mockConfigDescriptionValidator; - - @Mock - private BundleResolver bundleResolver; - - @Before - public void setup() { - initMocks(this); + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); Map props1 = new HashMap<>(); props1.put(Thing.PROPERTY_FIRMWARE_VERSION, V111); @@ -143,7 +124,11 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).withProperties(props3).build(); SafeCaller safeCaller = getService(SafeCaller.class); + assertNotNull(safeCaller); + if (safeCaller == null) { + throw new IllegalStateException("safeCaller is null"); + } firmwareUpdateService = new FirmwareUpdateServiceImpl(bundleResolver, mockConfigDescriptionValidator, mockPublisher, mockFirmwareRegistry, mockTranslationProvider, mockLocaleProvider, safeCaller); @@ -159,6 +144,11 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { when(bundleResolver.resolveBundle(any())).thenReturn(mock(Bundle.class)); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + private void initialFirmwareRegistryMocking() { when(mockFirmwareRegistry.getFirmware(eq(thing1), eq(V009))).thenReturn(FW009_EN); @@ -188,7 +178,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { when(mockFirmwareRegistry.getFirmwares(any(Thing.class), any())).then(firmwaresAnswer); } - @After + @AfterEach public void tearDown() { firmwareUpdateService.deactivate(); } @@ -392,19 +382,20 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { assertThat(isUpdateFinished.get(), is(false)); } - @Test(expected = IllegalArgumentException.class) + @Test public void cancelFirmwareUpdateNoFirmwareUpdateHandler() { - firmwareUpdateService.cancelFirmwareUpdate(new ThingUID("dummy:thing:withoutHandler")); + assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.cancelFirmwareUpdate(new ThingUID("dummy:thing:withoutHandler"))); } - @Test(expected = IllegalArgumentException.class) + @Test public void cancelFirmwareUpdateThingIdIdNull() { - firmwareUpdateService.cancelFirmwareUpdate(giveNull()); + assertThrows(IllegalArgumentException.class, () -> firmwareUpdateService.cancelFirmwareUpdate(giveNull())); } - @Test(expected = IllegalStateException.class) + @Test public void cancelFirmwareUpdateUpdateNotStarted() { - firmwareUpdateService.cancelFirmwareUpdate(THING3_UID); + assertThrows(IllegalStateException.class, () -> firmwareUpdateService.cancelFirmwareUpdate(THING3_UID)); } @Test @@ -487,19 +478,21 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw112); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetFirmwareStatusInfoNull() { - firmwareUpdateService.getFirmwareStatusInfo(giveNull()); + assertThrows(IllegalArgumentException.class, () -> firmwareUpdateService.getFirmwareStatusInfo(giveNull())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetFirmwareStatusInfoNull2() { - firmwareUpdateService.updateFirmware(giveNull(), V009, null); + assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.updateFirmware(giveNull(), V009, null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetFirmwareStatusInfoNull3() { - firmwareUpdateService.updateFirmware(THING1_UID, giveNull(), null); + assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.updateFirmware(THING1_UID, giveNull(), null)); } @Test @@ -509,33 +502,34 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { @Test public void testUpdateFirmwareUnknownFirmware() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(equalTo(String.format("Firmware with version %s for thing with UID %s was not found.", - UNKNOWN_FIRMWARE_VERSION, THING1_UID))); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.updateFirmware(THING1_UID, UNKNOWN_FIRMWARE_VERSION, null)); - firmwareUpdateService.updateFirmware(THING1_UID, UNKNOWN_FIRMWARE_VERSION, null); + assertThat(exception.getMessage(), + is(String.format("Firmware with version %s for thing with UID %s was not found.", + UNKNOWN_FIRMWARE_VERSION, THING1_UID))); } @Test public void testUpdateFirmwareNoFirmwareUpdateHandler() { Thing thing4 = ThingBuilder.create(THING_TYPE_UID_WITHOUT_FW, THING5_ID).build(); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - equalTo(String.format("There is no firmware update handler for thing with UID %s.", thing4.getUID()))); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.updateFirmware(thing4.getUID(), V009, null)); - firmwareUpdateService.updateFirmware(thing4.getUID(), V009, null); + assertThat(exception.getMessage(), + is(String.format("There is no firmware update handler for thing with UID %s.", thing4.getUID()))); } @Test public void testUpdateFirmwareNotExecutable() { doReturn(false).when(handler1).isUpdateExecutable(); - thrown.expect(IllegalStateException.class); - thrown.expectMessage( - equalTo(String.format("The firmware update of thing with UID %s is not executable.", THING1_UID))); + IllegalStateException exception = assertThrows(IllegalStateException.class, + () -> firmwareUpdateService.updateFirmware(THING1_UID, V112, null)); - firmwareUpdateService.updateFirmware(THING1_UID, V112, null); + assertThat(exception.getMessage(), + is(String.format("The firmware update of thing with UID %s is not executable.", THING1_UID))); } @Test @@ -568,11 +562,10 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { final FirmwareStatusInfo updateExecutableInfoFw113 = createUpdateExecutableInfo(thing1.getUID(), V113); assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113)); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - equalTo(String.format("Firmware %s is not suitable for thing with UID %s.", FW113_EN, THING1_UID))); - - firmwareUpdateService.updateFirmware(THING1_UID, V113, null); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.updateFirmware(THING1_UID, V113, null)); + assertThat(exception.getMessage(), + is(String.format("Firmware %s is not suitable for thing with UID %s.", FW113_EN, THING1_UID))); } @Test @@ -678,11 +671,11 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { thing1.setProperties(props1); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(equalTo( - String.format("Firmware with version %s for thing with UID %s was not found.", VALPHA, THING1_UID))); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> firmwareUpdateService.updateFirmware(THING1_UID, VALPHA, null)); - firmwareUpdateService.updateFirmware(THING1_UID, VALPHA, null); + assertThat(exception.getMessage(), + is(String.format("Firmware with version %s for thing with UID %s was not found.", VALPHA, THING1_UID))); } @Test @@ -814,11 +807,11 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { int originalDelay = firmwareUpdateService.getFirmwareStatusInfoJobDelay(); TimeUnit originalTimeUnit = firmwareUpdateService.getFirmwareStatusInfoJobTimeUnit(); - thrown.expect(IllegalArgumentException.class); - - updateInvalidConfigAndAssert(0, 0, TimeUnit.SECONDS, originalPeriod, originalDelay, originalTimeUnit); - updateInvalidConfigAndAssert(1, -1, TimeUnit.SECONDS, originalPeriod, originalDelay, originalTimeUnit); - updateInvalidConfigAndAssert(1, 0, TimeUnit.NANOSECONDS, originalPeriod, originalDelay, originalTimeUnit); + assertThrows(IllegalArgumentException.class, () -> { + updateInvalidConfigAndAssert(0, 0, TimeUnit.SECONDS, originalPeriod, originalDelay, originalTimeUnit); + updateInvalidConfigAndAssert(1, -1, TimeUnit.SECONDS, originalPeriod, originalDelay, originalTimeUnit); + updateInvalidConfigAndAssert(1, 0, TimeUnit.NANOSECONDS, originalPeriod, originalDelay, originalTimeUnit); + }); } private volatile AtomicBoolean updateExecutable = new AtomicBoolean(false); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java index 6763bdaa8..98ca0d101 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java @@ -13,16 +13,19 @@ package org.openhab.core.thing.internal.profiles; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; import java.math.BigDecimal; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.CoreItemFactory; @@ -54,23 +57,26 @@ public class SystemProfileFactoryOSGiTest extends JavaOSGiTest { private SystemProfileFactory profileFactory; - @Mock - private ProfileCallback mockCallback; + private AutoCloseable mocksCloseable; - @Mock - private ProfileContext mockContext; + private @Mock ProfileCallback mockCallback; + private @Mock ProfileContext mockContext; + + @BeforeEach + public void beforeEach() { + mocksCloseable = openMocks(this); - @Before - public void setUp() { profileFactory = getService(ProfileTypeProvider.class, SystemProfileFactory.class); assertNotNull(profileFactory); - mockCallback = mock(ProfileCallback.class); - - mockContext = mock(ProfileContext.class); when(mockContext.getConfiguration()).thenReturn(new Configuration(properties)); } + @AfterEach + public void afterEach() throws Exception { + mocksCloseable.close(); + } + @Test public void systemProfileTypesAndUidsShouldBeAvailable() { Collection systemProfileTypeUIDs = profileFactory.getSupportedProfileTypeUIDs(); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java index 5c525146a..ccd9805fa 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java @@ -12,15 +12,15 @@ */ package org.openhab.core.thing.link; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.util.Hashtable; import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.ChannelUID; @@ -50,7 +50,7 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest { private ItemChannelLinkRegistry itemChannelLinkRegistry; private ManagedThingProvider managedThingProvider; - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); managedThingProvider = getService(ManagedThingProvider.class); @@ -61,7 +61,7 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest { assertNotNull(managedItemChannelLinkProvider); } - @After + @AfterEach public void teardown() { managedItemChannelLinkProvider.getAll().forEach(it -> managedItemChannelLinkProvider.remove(it.getUID())); managedThingProvider.getAll().forEach(it -> managedThingProvider.remove(it.getUID())); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/LinkEventOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/LinkEventOSGiTest.java index 2df1498c1..027d157e5 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/LinkEventOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/LinkEventOSGiTest.java @@ -13,15 +13,15 @@ package org.openhab.core.thing.link; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.events.Event; import org.openhab.core.events.EventFilter; import org.openhab.core.events.EventSubscriber; @@ -66,7 +66,7 @@ public class LinkEventOSGiTest extends JavaOSGiTest { } } - @Before + @BeforeEach public void setup() { registerVolatileStorageService(); itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/profiles/i18n/SystemProfileI18nOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/profiles/i18n/SystemProfileI18nOSGiTest.java index ccceb4298..f0c846e21 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/profiles/i18n/SystemProfileI18nOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/profiles/i18n/SystemProfileI18nOSGiTest.java @@ -12,15 +12,15 @@ */ package org.openhab.core.thing.profiles.i18n; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.openhab.core.thing.profiles.SystemProfiles.*; import java.util.Collection; import java.util.Locale; import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.internal.profiles.SystemProfileFactory; import org.openhab.core.thing.profiles.ProfileType; @@ -35,7 +35,7 @@ public class SystemProfileI18nOSGiTest extends JavaOSGiTest { private ProfileTypeProvider systemProfileTypeProvider; - @Before + @BeforeEach public void setUp() { ProfileTypeProvider provider = getService(ProfileTypeProvider.class, SystemProfileFactory.class); assertTrue(provider instanceof SystemProfileFactory); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/testutil/i18n/DefaultLocaleSetter.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/testutil/i18n/DefaultLocaleSetter.java index 81ed0aeba..7f7f42eec 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/testutil/i18n/DefaultLocaleSetter.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/testutil/i18n/DefaultLocaleSetter.java @@ -14,7 +14,7 @@ package org.openhab.core.thing.testutil.i18n; import static java.util.Objects.requireNonNull; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Dictionary; diff --git a/itests/org.openhab.core.thing.xml.tests/itest.bndrun b/itests/org.openhab.core.thing.xml.tests/itest.bndrun index b8fbb4132..906995e37 100644 --- a/itests/org.openhab.core.thing.xml.tests/itest.bndrun +++ b/itests/org.openhab.core.thing.xml.tests/itest.bndrun @@ -17,8 +17,6 @@ Fragment-Host: org.openhab.core.thing.xml org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -43,4 +41,12 @@ Fragment-Host: org.openhab.core.thing.xml org.openhab.core.test;version='[3.0.0,3.0.1)',\ org.openhab.core.thing;version='[3.0.0,3.0.1)',\ org.openhab.core.thing.xml;version='[3.0.0,3.0.1)',\ - org.openhab.core.thing.xml.tests;version='[3.0.0,3.0.1)' + org.openhab.core.thing.xml.tests;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)' diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java index 539e5bb40..7e7b18670 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java @@ -13,14 +13,14 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; import java.util.Optional; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.BundleCloseable; import org.openhab.core.test.SyntheticBundleInstaller; import org.openhab.core.test.java.JavaOSGiTest; @@ -46,7 +46,7 @@ public class ChannelTypesI18nTest extends JavaOSGiTest { private ChannelGroupTypeProvider channelGroupTypeProvider; private ThingTypeProvider thingTypeProvider; - @Before + @BeforeEach public void setUp() { // get ONLY the XMLChannelTypeProvider channelTypeProvider = getService(ChannelTypeProvider.class, @@ -99,7 +99,7 @@ public class ChannelTypesI18nTest extends JavaOSGiTest { ThingType thingType = waitForAssert(() -> { Optional thingTypeOpt = thingTypeProvider.getThingTypes(null).stream() .filter(it -> "somebinding:something".equals(it.getUID().toString())).findFirst(); - Assert.assertTrue(thingTypeOpt.isPresent()); + assertTrue(thingTypeOpt.isPresent()); final ThingType thingTypeTmp = thingTypeOpt.get(); // assertThat(thingTypeTmp, is(notNullValue())); assertThat(thingTypeTmp.getChannelDefinitions().size(), is(2)); diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesTest.java index 9ea47df41..284041c97 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesTest.java @@ -13,12 +13,12 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Collection; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.BundleCloseable; import org.openhab.core.test.SyntheticBundleInstaller; import org.openhab.core.test.java.JavaOSGiTest; @@ -40,7 +40,7 @@ public class ChannelTypesTest extends JavaOSGiTest { private ChannelTypeProvider channelTypeProvider; private ChannelGroupTypeProvider channelGroupTypeProvider; - @Before + @BeforeEach public void setUp() { // get ONLY the XMLChannelTypeProvider channelTypeProvider = getService(ChannelTypeProvider.class, diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ConfigDescriptionsTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ConfigDescriptionsTest.java index 8bd54498e..022aeae1e 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ConfigDescriptionsTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ConfigDescriptionsTest.java @@ -13,13 +13,13 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.net.URI; import java.util.Collection; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.config.core.ConfigDescription; import org.openhab.core.config.core.ConfigDescriptionParameter; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -40,7 +40,7 @@ public class ConfigDescriptionsTest extends JavaOSGiTest { private ConfigDescriptionRegistry configDescriptionRegistry; - @Before + @BeforeEach public void before() { configDescriptionRegistry = getService(ConfigDescriptionRegistry.class); assertThat(configDescriptionRegistry, is(notNullValue())); diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/LoadedTestBundle.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/LoadedTestBundle.java index 2c70e6e6e..a81464750 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/LoadedTestBundle.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/LoadedTestBundle.java @@ -13,7 +13,7 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.config.core.ConfigDescriptionRegistry; diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java index 0d432805d..b98d522cc 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java @@ -13,13 +13,13 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.binding.ThingTypeProvider; import org.openhab.core.thing.type.ChannelDefinition; @@ -44,7 +44,7 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest { private ChannelTypeRegistry channelTypeRegistry; private ChannelGroupTypeRegistry channelGroupTypeRegistry; - @Before + @BeforeEach public void setUp() { thingTypeProvider = getService(ThingTypeProvider.class); assertThat(thingTypeProvider, is(notNullValue())); diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemWideChannelTypesTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemWideChannelTypesTest.java index 1f73d56a7..a9dd7ae2c 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemWideChannelTypesTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/SystemWideChannelTypesTest.java @@ -13,14 +13,15 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collection; import java.util.List; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.DefaultSystemChannelTypeProvider; import org.openhab.core.thing.binding.ThingTypeProvider; @@ -55,7 +56,7 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest { private ChannelTypeRegistry channelTypeRegistry; private ChannelTypeProvider systemChannelTypeProvider; - @Before + @BeforeEach public void setUp() { thingTypeProvider = getService(ThingTypeProvider.class); assertThat(thingTypeProvider, is(notNullValue())); diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java index ca46a552e..e07b7c8af 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java @@ -13,13 +13,14 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collection; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.binding.ThingTypeProvider; import org.openhab.core.thing.type.ChannelDefinition; @@ -45,7 +46,7 @@ public class ThingTypeI18nTest extends JavaOSGiTest { private ChannelTypeRegistry channelTypeRegistry; private ChannelGroupTypeRegistry channelGroupTypeRegistry; - @Before + @BeforeEach public void setUp() { thingTypeProvider = getService(ThingTypeProvider.class); assertNotNull(thingTypeProvider); diff --git a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java index cc007316e..4a1dab5d2 100644 --- a/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java +++ b/itests/org.openhab.core.thing.xml.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java @@ -13,16 +13,16 @@ package org.openhab.core.thing.xml.test; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertThat; import java.math.BigDecimal; import java.util.Collection; import java.util.List; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.test.java.JavaOSGiTest; import org.openhab.core.thing.binding.ThingTypeProvider; import org.openhab.core.thing.type.BridgeType; @@ -50,7 +50,7 @@ public class ThingTypesTest extends JavaOSGiTest { private ChannelTypeRegistry channelTypeRegistry; private ChannelGroupTypeRegistry channelGroupTypeRegistry; - @Before + @BeforeEach public void setUp() { thingTypeProvider = getService(ThingTypeProvider.class); assertThat(thingTypeProvider, is(notNullValue())); diff --git a/itests/org.openhab.core.voice.tests/itest.bndrun b/itests/org.openhab.core.voice.tests/itest.bndrun index 490552012..72abc04f6 100644 --- a/itests/org.openhab.core.voice.tests/itest.bndrun +++ b/itests/org.openhab.core.voice.tests/itest.bndrun @@ -15,8 +15,6 @@ Fragment-Host: org.openhab.core.voice org.apache.felix.scr;version='[2.1.10,2.1.11)',\ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\ - osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ - osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ ch.qos.logback.core;version='[1.2.3,1.2.4)',\ slf4j.api;version='[1.7.25,1.7.26)',\ ch.qos.logback.classic;version='[1.2.3,1.2.4)',\ @@ -52,4 +50,52 @@ Fragment-Host: org.openhab.core.voice org.openhab.core.test;version='[3.0.0,3.0.1)',\ org.openhab.core.thing;version='[3.0.0,3.0.1)',\ org.openhab.core.voice;version='[3.0.0,3.0.1)',\ - org.openhab.core.voice.tests;version='[3.0.0,3.0.1)' + org.openhab.core.voice.tests;version='[3.0.0,3.0.1)',\ + biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\ + com.google.guava;version='[27.1.0,27.1.1)',\ + com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ + com.google.inject;version='[3.0.0,3.0.1)',\ + io.github.classgraph;version='[4.8.35,4.8.36)',\ + jollyday;version='[0.5.8,0.5.9)',\ + junit-jupiter-api;version='[5.6.2,5.6.3)',\ + junit-jupiter-engine;version='[5.6.2,5.6.3)',\ + junit-jupiter-params;version='[5.6.2,5.6.3)',\ + junit-platform-commons;version='[1.6.2,1.6.3)',\ + junit-platform-engine;version='[1.6.2,1.6.3)',\ + junit-platform-launcher;version='[1.6.2,1.6.3)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.antlr.runtime;version='[3.2.0,3.2.1)',\ + org.eclipse.emf.common;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\ + org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\ + org.eclipse.equinox.common;version='[3.10.400,3.10.401)',\ + org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\ + org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\ + org.eclipse.xtend.lib;version='[2.19.0,2.19.1)',\ + org.eclipse.xtend.lib.macro;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.common.types;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.util;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase;version='[2.19.0,2.19.1)',\ + org.eclipse.xtext.xbase.lib;version='[2.19.0,2.19.1)',\ + org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.openhab.core.automation;version='[3.0.0,3.0.1)',\ + org.openhab.core.automation.module.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.ephemeris;version='[3.0.0,3.0.1)',\ + org.openhab.core.io.net;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.core;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.item;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.rule;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.script.runtime;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.sitemap;version='[3.0.0,3.0.1)',\ + org.openhab.core.model.thing;version='[3.0.0,3.0.1)',\ + org.openhab.core.persistence;version='[3.0.0,3.0.1)',\ + org.openhab.core.transform;version='[3.0.0,3.0.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + org.threeten.extra;version='[1.4.0,1.4.1)' diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceManagerImplTest.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceManagerImplTest.java index c9fddf0a3..66a90554b 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceManagerImplTest.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/internal/VoiceManagerImplTest.java @@ -13,7 +13,8 @@ package org.openhab.core.voice.internal; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.net.URI; @@ -23,10 +24,8 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.Locale; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.audio.AudioManager; import org.openhab.core.config.core.ParameterOption; import org.openhab.core.test.java.JavaOSGiTest; @@ -60,10 +59,7 @@ public class VoiceManagerImplTest extends JavaOSGiTest { private AudioManager audioManager; - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Before + @BeforeEach public void setUp() throws IOException { voiceManager = getService(VoiceManager.class, VoiceManagerImpl.class); assertNotNull(voiceManager); @@ -133,11 +129,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest { @Test public void interpretSomethingWithGivenHliIdEhenTheHliIsNotARegisteredService() throws InterpretationException { hliStub = new HumanLanguageInterpreterStub(); - String result; - exception.expect(InterpretationException.class); - result = voiceManager.interpret("something", hliStub.getId()); - assertNull(result); + assertThrows(InterpretationException.class, () -> voiceManager.interpret("something", hliStub.getId())); } @Test @@ -164,9 +157,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest { hliStub = new HumanLanguageInterpreterStub(); source = new AudioSourceStub(); - exception.expect(IllegalStateException.class); - voiceManager.startDialog(ksService, sttService, ttsService, hliStub, source, sink, Locale.getDefault(), "word", - null); + assertThrows(IllegalStateException.class, () -> voiceManager.startDialog(ksService, sttService, ttsService, + hliStub, source, sink, Locale.getDefault(), "word", null)); assertFalse(ksService.isWordSpotted()); } diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/InterpretCommandTest.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/InterpretCommandTest.java index c53f7a8be..571aeb139 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/InterpretCommandTest.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/InterpretCommandTest.java @@ -13,14 +13,14 @@ package org.openhab.core.voice.voiceconsolecommandextension; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Dictionary; import java.util.Hashtable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.voice.internal.HumanLanguageInterpreterStub; import org.openhab.core.voice.internal.TTSServiceStub; import org.openhab.core.voice.internal.VoiceManagerImpl; @@ -47,7 +47,7 @@ public class InterpretCommandTest extends VoiceConsoleCommandExtensionTest { private VoiceStub voice; private TTSServiceStub ttsService; - @Before + @BeforeEach public void setUp() throws IOException, InterruptedException { ttsService = new TTSServiceStub(); hliStub = new HumanLanguageInterpreterStub(); diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/SayCommandTest.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/SayCommandTest.java index e3b0b9778..c7ebe40ff 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/SayCommandTest.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/SayCommandTest.java @@ -13,7 +13,8 @@ package org.openhab.core.voice.voiceconsolecommandextension; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.util.Arrays; @@ -21,11 +22,9 @@ import java.util.Collection; import java.util.Dictionary; import java.util.Hashtable; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.openhab.core.items.Item; import org.openhab.core.items.ItemRegistry; import org.openhab.core.library.items.StringItem; @@ -47,22 +46,17 @@ import org.osgi.service.cm.ConfigurationAdmin; * @author Mihaela Memova - Initial contribution * @author Velin Yordanov - migrated tests from groovy to java */ -@RunWith(Parameterized.class) public class SayCommandTest extends VoiceConsoleCommandExtensionTest { + private static final String CONFIG_DEFAULT_TTS = "defaultTTS"; private static final String SUBCMD_SAY = "say"; - private boolean shouldItemsBePassed; - private boolean shouldItemsBeRegistered; - private boolean shouldMultipleItemsBeRegistered; - private TTSService defaultTTSService; - private boolean ttsServiceMockShouldBeRegistered; - private boolean shouldStreamBeExpected; private static TTSServiceStub ttsService; + private SinkStub sink; private VoiceStub voice; - @Before + @BeforeEach public void setUp() { sink = new SinkStub(); voice = new VoiceStub(); @@ -74,17 +68,6 @@ public class SayCommandTest extends VoiceConsoleCommandExtensionTest { registerService(voice); } - public SayCommandTest(boolean areItemsPassed, boolean areItemsRegistered, boolean areMultipleItemsRegistered, - TTSService defaultTTSService, boolean isTTSServiceMockRegistered, boolean isStreamProcessedExpected) { - this.shouldItemsBePassed = areItemsPassed; - this.shouldItemsBeRegistered = areItemsRegistered; - this.shouldMultipleItemsBeRegistered = areMultipleItemsRegistered; - this.defaultTTSService = defaultTTSService; - this.ttsServiceMockShouldBeRegistered = isStreamProcessedExpected; - this.shouldStreamBeExpected = isStreamProcessedExpected; - } - - @Parameters public static Collection data() { Object[][] params = new Object[13][5]; params[0] = new Object[] { false, false, false, null, false, false }; @@ -99,13 +82,16 @@ public class SayCommandTest extends VoiceConsoleCommandExtensionTest { params[9] = new Object[] { true, false, false, null, true, true }; params[10] = new Object[] { true, false, false, ttsService, true, true }; params[11] = new Object[] { true, false, false, ttsService, false, false }; - params[12] = new Object[] { true, true, true, ttsService, true, false }; + params[12] = new Object[] { true, true, true, ttsService, true, true }; return Arrays.asList(params); } - @Test - public void testSayCommand() throws IOException { + @ParameterizedTest + @MethodSource("data") + public void testSayCommand(boolean shouldItemsBePassed, boolean shouldItemsBeRegistered, + boolean shouldMultipleItemsBeRegistered, TTSService defaultTTSService, + boolean ttsServiceMockShouldBeRegistered, boolean shouldStreamBeExpected) throws IOException { String[] methodParameters = new String[2]; methodParameters[0] = SUBCMD_SAY; diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoiceConsoleCommandExtensionTest.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoiceConsoleCommandExtensionTest.java index 7f42031f5..35bae741b 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoiceConsoleCommandExtensionTest.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoiceConsoleCommandExtensionTest.java @@ -12,9 +12,9 @@ */ package org.openhab.core.voice.voiceconsolecommandextension; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.openhab.core.audio.AudioManager; import org.openhab.core.io.console.extensions.ConsoleCommandExtension; import org.openhab.core.test.java.JavaOSGiTest; @@ -41,7 +41,7 @@ public abstract class VoiceConsoleCommandExtensionTest extends JavaOSGiTest { protected SinkStub sink; protected AudioSourceStub source; - @Before + @BeforeEach public void setup() { voiceManager = getService(VoiceManager.class, VoiceManagerImpl.class); assertNotNull(voiceManager); diff --git a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoicesCommandTest.java b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoicesCommandTest.java index d7ad533db..db2132b4c 100644 --- a/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoicesCommandTest.java +++ b/itests/org.openhab.core.voice.tests/src/main/java/org/openhab/core/voice/voiceconsolecommandextension/VoicesCommandTest.java @@ -13,12 +13,12 @@ package org.openhab.core.voice.voiceconsolecommandextension; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openhab.core.voice.internal.SinkStub; import org.openhab.core.voice.internal.TTSServiceStub; import org.openhab.core.voice.internal.VoiceStub; @@ -36,7 +36,7 @@ public class VoicesCommandTest extends VoiceConsoleCommandExtensionTest { private SinkStub sink; private VoiceStub voice; - @Before + @BeforeEach public void setUp() { BundleContext context = bundleContext; diff --git a/pom.xml b/pom.xml index 9181e2b99..83e52d581 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ ${oh.java.version} ${oh.java.version} - 4.3.0 + 5.1.2 4.2.1 4.2.7 0.10.0 @@ -368,7 +368,7 @@ Import-Package: \\ org.apache.maven.plugins maven-surefire-plugin - 2.22.1 + 3.0.0-M5