From 3e4087f0aed98708ba1b434f1287cf61382a4fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hunyady=20Mih=C3=A1ly?= Date: Tue, 27 Feb 2024 11:04:41 +0100 Subject: [PATCH] test(junit4): revert to junit4 using kotest everywhere possible SUITEDEV-35237 Co-authored-by: davidSchuppa <32750715+davidSchuppa@users.noreply.github.com> --- Makefile | 14 +- common/build.gradle.kts | 12 +- .../common/feature/InnerFeatureTest.kt | 4 +- core-api/build.gradle.kts | 12 +- .../java/com/emarsys/core/api/ApiTest.kt | 4 +- core/build.gradle.kts | 13 +- .../core/DefaultCoreCompletionHandlerTest.kt | 7 +- .../java/com/emarsys/core/DeviceInfoTest.kt | 10 +- .../ActivityLifecycleActionRegistryTest.kt | 7 +- .../activity/ActivityLifecycleWatchdogTest.kt | 9 +- .../activity/CurrentActivityWatchdogTest.kt | 7 +- .../com/emarsys/core/api/AsyncProxyTest.kt | 9 +- .../emarsys/core/api/LogExceptionProxyTest.kt | 10 +- .../core/app/AppLifecycleObserverTest.kt | 9 +- .../ConcurrentHandlerHolderFactoryTest.kt | 10 +- .../core/concurrency/CoreHandlerTest.kt | 10 +- .../core/connection/ConnectionProviderTest.kt | 7 +- .../core/connection/ConnectionWatchDogTest.kt | 7 +- .../ConnectivityChangeReceiverTest.kt | 10 +- ...ty_getConnectionState_ParameterizedTest.kt | 4 +- .../HardwareIdContentResolverTest.kt | 7 +- .../com/emarsys/core/crypto/CryptoTest.kt | 12 +- .../HardwareIdentificationCryptoTest.kt | 10 +- .../DelegatingCoreSQLiteDatabaseTest.kt | 16 +- ...abase_registerTrigger_parameterizedTest.kt | 217 +++++++++--------- ...base_triggerRecursion_parameterizedTest.kt | 91 ++++---- .../database/helper/AbstractDbHelperTest.kt | 7 +- .../core/database/helper/CoreDbHelperTest.kt | 11 +- .../AbstractSqliteRepositoryTest.kt | 7 +- .../specification/EverythingTest.kt | 8 +- .../specification/FilterByRequestIdsTest.kt | 8 +- .../QueryLatestRequestModelTest.kt | 8 +- .../core/device/LanguageProviderTest.kt | 7 +- .../endpoint/ServiceEndpointProviderTest.kt | 10 +- .../emarsys/core/fake/FakeRequestTask.java | 2 + .../core/feature/FeatureRegistryTest.kt | 10 +- .../NotificationManagerHelperTest.kt | 9 +- .../activity/CurrentActivityProviderTest.kt | 7 +- .../hardwareid/HardwareIdProviderTest.kt | 7 +- .../provider/random/RandomProviderTest.kt | 6 +- .../timestamp/TimestampProviderTest.kt | 4 +- .../core/provider/uuid/UUIDProviderTest.kt | 4 +- .../provider/version/VersionProviderTest.kt | 8 +- .../core/request/RequestManagerDennaTest.kt | 10 +- .../core/request/RequestManagerOfflineTest.kt | 11 +- .../core/request/RequestManagerTest.kt | 61 +++-- .../emarsys/core/request/RequestTaskTest.kt | 13 +- .../emarsys/core/request/RestClientTest.kt | 9 +- ...CompletionHandlerMiddlewareProviderTest.kt | 8 +- .../model/CompositeRequestModelTest.kt | 7 +- .../model/RequestModelRepositoryTest.kt | 17 +- .../core/request/model/RequestModelTest.kt | 10 +- .../specification/FilterByUrlPatternTest.kt | 8 +- .../core/resource/MetaDataReaderTest.kt | 7 +- .../response/AbstractResponseHandlerTest.kt | 7 +- .../response/ResponseHandlersProcessorTest.kt | 9 +- .../core/response/ResponseModelTest.kt | 12 +- .../core/shard/ShardModelRepositoryTest.kt | 14 +- .../com/emarsys/core/shard/ShardModelTest.kt | 7 +- .../specification/FilterByShardIdsTest.kt | 8 +- .../specification/FilterByShardTypeTest.kt | 8 +- .../core/storage/AbstractStorageTest.kt | 9 +- .../core/storage/BooleanStorageTest.kt | 7 +- .../core/storage/CoreStorageKeyTest.kt | 4 +- .../core/storage/DefaultKeyValueStoreTest.kt | 34 ++- .../SecureSharedPreferencesProviderTest.kt | 8 +- .../emarsys/core/storage/StringStorageTest.kt | 7 +- .../core/testUtil/RequestModelTestUtils.kt | 4 +- .../java/com/emarsys/core/util/AssertTest.kt | 6 +- .../com/emarsys/core/util/DatabaseUtilTest.kt | 4 +- .../core/util/ExceptionExtensionsKtTest.kt | 4 +- .../emarsys/core/util/FileDownloaderTest.kt | 37 +-- .../util/HeaderUtilsInstrumentationTest.kt | 4 +- .../com/emarsys/core/util/ImageUtilsTest.kt | 27 ++- .../com/emarsys/core/util/JsonUtilsTest.kt | 8 +- .../emarsys/core/util/MapExtensionsKtTest.kt | 7 +- .../core/util/RequestModelUtilsTest.kt | 5 +- .../core/util/SerializationUtilsTest.kt | 4 +- .../com/emarsys/core/util/SystemUtilsTest.kt | 5 +- .../emarsys/core/util/TimestampUtilsTest.kt | 7 +- .../util/batch/BatchingShardTriggerTest.kt | 7 +- .../core/util/batch/ListChunkerTest.kt | 10 +- .../core/util/log/LogShardListMergerTest.kt | 10 +- .../com/emarsys/core/util/log/LoggerTest.kt | 11 +- .../core/util/log/entry/AppEventLogTest.kt | 5 +- .../core/util/log/entry/CrashLogTest.kt | 8 +- .../core/util/log/entry/InAppLogTest.kt | 6 +- .../core/util/log/entry/LogEntryKtTest.kt | 4 +- .../util/log/entry/MethodNotAlllowedTest.kt | 5 +- .../util/log/entry/OfflineQueueSizeTest.kt | 5 +- .../core/util/log/entry/RequestLogTest.kt | 9 +- .../core/util/log/entry/StatusLogTest.kt | 15 +- .../util/predicate/ListSizeAtLeastTest.kt | 8 +- .../core/validate/JsonObjectValidatorTest.kt | 10 +- .../CoreCompletionHandlerMiddlewareTest.kt | 7 +- .../emarsys/core/worker/DefaultWorkerTest.kt | 7 +- emarsys-e2e-test/build.gradle.kts | 12 +- .../java/com/emarsys/EmarsysE2ETests.kt | 48 ++-- emarsys-firebase/build.gradle.kts | 12 +- .../EmarsysFirebaseMessagingServiceTest.kt | 12 +- ...marsysFirebaseMessagingServiceUtilsTest.kt | 7 +- emarsys-huawei/build.gradle.kts | 12 +- .../EmarsysHuaweiMessagingServiceTest.kt | 11 +- .../EmarsysHuaweiMessagingServiceUtilsTest.kt | 7 +- emarsys-sdk/build.gradle.kts | 12 +- .../emarsys/DefaultInboxIntegrationTest.kt | 32 +-- .../java/com/emarsys/EmarsysTest.kt | 52 ++++- .../androidTest/java/com/emarsys/InAppTest.kt | 10 +- .../InappNotificationIntegrationTest.kt | 18 +- .../emarsys/MobileEngageIntegrationTest.kt | 58 +++-- ...ngageRefreshContactTokenIntegrationTest.kt | 29 +-- .../com/emarsys/PredictIntegrationTest.kt | 111 +++++---- .../java/com/emarsys/PredictTest.kt | 10 +- .../androidTest/java/com/emarsys/PushTest.kt | 10 +- .../emarsys/RemoteConfigIntegrationTest.kt | 28 ++- .../com/emarsys/config/ConfigLoaderTest.kt | 7 +- .../java/com/emarsys/config/ConfigTest.kt | 24 +- .../com/emarsys/config/EmarsysConfigTest.kt | 11 +- .../java/com/emarsys/deeplink/DeepLinkTest.kt | 11 +- .../di/EmarsysDependencyInjectionTest.kt | 7 +- .../emarsys/eventservice/EventServiceTest.kt | 11 +- .../java/com/emarsys/geofence/GeofenceTest.kt | 11 +- .../emarsys/inapp/ui/InlineInAppViewTest.kt | 11 +- .../com/emarsys/inbox/MessageInboxTest.kt | 11 +- .../emarsys/mobileengage/MobileEngageTest.kt | 12 +- .../mapper/RemoteMessageMapperFactoryTest.kt | 7 +- .../oneventaction/OnEventActionTest.kt | 11 +- .../emarsys/predict/PredictRestrictedTest.kt | 12 +- ...rdwareIdentificationContentProviderTest.kt | 7 +- emarsys/build.gradle.kts | 12 +- .../emarsys/EmarsysRequestModelFactoryTest.kt | 10 +- .../config/DefaultConfigInternalTest.kt | 11 +- .../config/FetchRemoteConfigActionTest.kt | 12 +- .../config/RemoteConfigResponseMapperTest.kt | 10 +- gradle/libs.versions.toml | 1 + mobile-engage-api/build.gradle.kts | 12 +- .../com/emarsys/mobileengage/api/MEApiTest.kt | 4 +- mobile-engage/build.gradle.kts | 12 +- .../DefaultMobileEngageInternalTest.kt | 8 +- .../MobileEngageRequestContextTest.kt | 7 +- .../DefaultClientServiceInternalTest.kt | 10 +- .../deeplink/DeepLinkActionTest.kt | 12 +- .../deeplink/DefaultDeepLinkInternalTest.kt | 7 +- .../device/DeviceInfoStartActionTest.kt | 11 +- .../event/CacheableEventHandlerTest.kt | 7 +- .../event/DefaultEventServiceInternalTest.kt | 10 +- .../geofence/DefaultGeofenceInternalTest.kt | 7 +- .../geofence/FetchGeofencesActionTest.kt | 13 +- .../geofence/GeofenceFilterTest.kt | 19 +- .../GeofencePendingIntentProviderTest.kt | 7 +- .../geofence/GeofenceResponseMapperTest.kt | 10 +- .../mobileengage/iam/AppStartActionTest.kt | 10 +- .../iam/InAppEventHandlerInternalTest.kt | 8 +- .../mobileengage/iam/InAppInternalTest.kt | 8 +- .../iam/OverlayInAppPresenterTest.kt | 7 +- .../mobileengage/iam/PushToInAppActionTest.kt | 8 +- .../iam/SaveDisplayedIamActionTest.kt | 11 +- .../iam/dialog/IamDialogProviderTest.kt | 12 +- .../mobileengage/iam/dialog/IamDialogTest.kt | 11 +- .../action/SendDisplayedIamActionTest.kt | 11 +- .../iam/jsbridge/IamJsBridgeFactoryTest.kt | 4 +- .../iam/jsbridge/IamJsBridgeTest.kt | 11 +- .../jsbridge/JSCommandFactoryProviderTest.kt | 4 +- .../iam/jsbridge/JSCommandFactoryTest.kt | 11 +- .../iam/model/IamConversionUtilsTest.kt | 7 +- .../ButtonClickedRepositoryTest.kt | 7 +- .../DisplayedIamRepositoryTest.kt | 7 +- .../RequestRepositoryProxyTest.kt | 11 +- .../specification/FilterByCampaignIdTest.kt | 8 +- .../iam/webview/IamWebViewClientTest.kt | 7 +- .../iam/webview/IamWebViewFactoryTest.kt | 13 +- .../iam/webview/IamWebViewTest.kt | 11 +- .../inbox/DefaultMessageInboxInternalTest.kt | 7 +- .../inbox/MessageInboxResponseMapperTest.kt | 7 +- .../notification/ActionCommandFactoryTest.kt | 11 +- ...ityCommandLifecycleCallbacksFactoryTest.kt | 4 +- ...chActivityCommandLifecycleCallbacksTest.kt | 12 +- .../NotificationCommandFactoryTest.kt | 11 +- .../command/AppEventCommandTest.kt | 11 +- .../command/CompositeCommandTest.kt | 4 +- .../command/CustomEventCommandTest.kt | 7 +- .../command/DismissNotificationCommandTest.kt | 4 +- .../command/LaunchApplicationCommandTest.kt | 11 +- .../NotificationInformationCommandTest.kt | 20 +- .../command/OpenExternalUrlCommandTest.kt | 4 +- .../PreloadedInappHandlerCommandTest.kt | 11 +- ...ilentNotificationInformationCommandTest.kt | 20 +- .../command/TrackActionClickCommandTest.kt | 4 +- .../command/TrackMessageOpenCommandTest.kt | 4 +- .../push/DefaultPushInternalTest.kt | 7 +- .../push/DefaultPushTokenProviderTest.kt | 6 +- ...ionHandlerRefreshTokenProxyProviderTest.kt | 10 +- ...eCompletionHandlerRefreshTokenProxyTest.kt | 11 +- .../MobileEngageRequestModelFactoryTest.kt | 10 +- .../mapper/ContactTokenHeaderMapperTest.kt | 10 +- .../mapper/DefaultRequestHeaderMapperTest.kt | 10 +- .../DeviceEventStateRequestMapperTest.kt | 7 +- .../mapper/MobileEngageHeaderMapperTest.kt | 10 +- .../mapper/OpenIdTokenRequestMapperTest.kt | 10 +- .../ClientInfoResponseHandlerTest.kt | 13 +- .../DeviceEventStateResponseHandlerTest.kt | 7 +- .../InAppCleanUpResponseHandlerTest.kt | 10 +- .../InAppCleanUpResponseHandlerV4Test.kt | 7 +- .../InAppMessageResponseHandlerTest.kt | 11 +- ...ileEngageClientStateResponseHandlerTest.kt | 13 +- .../MobileEngageTokenResponseHandlerTest.kt | 10 +- .../OnEventActionResponseHandlerTest.kt | 11 +- .../mobileengage/service/IntentUtilsTest.kt | 7 +- .../service/MessagingServiceUtilsTest.kt | 13 +- .../service/NotificationActionUtilsTest.kt | 12 +- .../service/RemoteMessageMapperV1Test.kt | 11 +- .../service/RemoteMessageMapperV2Test.kt | 11 +- .../session/MobileEngageSessionTest.kt | 8 +- .../storage/MobileEngageStorageKeyTest.kt | 4 +- .../util/RequestModelHelperTest.kt | 10 +- .../util/RequestPayloadUtilsTest.kt | 9 +- predict-api/build.gradle.kts | 12 +- .../api/model/RecommendationFilterTest.kt | 7 +- .../api/model/RecommendationLogicTest.kt | 4 +- predict/build.gradle.kts | 12 +- .../predict/DefaultPredictInternalTest.kt | 7 +- .../predict/PredictResponseMapperTest.kt | 10 +- .../PredictRequestModelBuilderProviderTest.kt | 10 +- .../request/PredictHeaderFactoryTest.kt | 10 +- .../request/PredictRequestModelBuilderTest.kt | 7 +- .../response/VisitorIdResponseHandlerTest.kt | 12 +- .../predict/response/XPResponseHandlerTest.kt | 11 +- .../shard/PredictShardListMergerTest.kt | 7 +- .../predict/storage/PredictStorageKeyTest.kt | 4 +- .../emarsys/predict/util/CartItemUtilsTest.kt | 11 +- sample/build.gradle.kts | 45 +++- testUtils/build.gradle.kts | 27 +-- .../testUtil/JUnitTestEngineListener.kt | 41 ++++ .../emarsys/testUtil/KotestRunnerAndroid.kt | 45 ++++ .../java/com/emarsys/testUtil/RetryUtils.kt | 9 + .../main/java/com/emarsys/testUtil/Specs.kt | 44 ++++ .../emarsys/testUtil/rules/ConnectionRule.kt | 18 +- .../testUtil/rules/DuplicatedThreadRule.kt | 25 +- .../com/emarsys/testUtil/rules/RetryRule.kt | 32 +++ 239 files changed, 1592 insertions(+), 1466 deletions(-) create mode 100644 testUtils/src/main/java/com/emarsys/testUtil/JUnitTestEngineListener.kt create mode 100644 testUtils/src/main/java/com/emarsys/testUtil/KotestRunnerAndroid.kt create mode 100644 testUtils/src/main/java/com/emarsys/testUtil/RetryUtils.kt create mode 100644 testUtils/src/main/java/com/emarsys/testUtil/Specs.kt create mode 100644 testUtils/src/main/java/com/emarsys/testUtil/rules/RetryRule.kt diff --git a/Makefile b/Makefile index bcbb3853f..14f23679e 100644 --- a/Makefile +++ b/Makefile @@ -44,8 +44,6 @@ test-android-firebase-emulator: check-env ## run Android Instrumented tests on e --device model=Pixel2.arm,version=28,locale=en,orientation=portrait \ --device model=MediumPhone.arm,version=30,locale=en,orientation=portrait \ --device model=SmallPhone.arm,version=33,locale=en,orientation=portrait \ - --environment-variables runnerBuilder=de.mannodermaus.junit5.AndroidJUnit5Builder \ - --environment-variables clearPackageData=true \ --client-details matrixLabel="Android Emarsys SDK - virtual devices" test-android-firebase: check-env ## run Android Instrumented tests on real devices on Firebase Test Lab @@ -53,13 +51,11 @@ test-android-firebase: check-env ## run Android Instrumented tests on real devic --type instrumentation \ --app ./sample/build/outputs/apk/androidTest/debug/sample-debug-androidTest.apk \ --test ./$(MODULE_NAME)/build/outputs/apk/androidTest/debug/$(MODULE_NAME)-debug-androidTest.apk \ - --device model=f2q,version=30,locale=en,orientation=portrait \ - --device model=a51,version=31,locale=en,orientation=portrait \ - --device model=bluejay,version=32,locale=en,orientation=portrait \ - --device model=b4q,version=33,locale=en,orientation=portrait \ - --environment-variables runnerBuilder=de.mannodermaus.junit5.AndroidJUnit5Builder \ - --environment-variables clearPackageData=true \ - --client-details matrixLabel="Unified SDK - physical devices" + --device model=redfin,version=30,locale=en,orientation=portrait \ + --device model=q2q,version=31,locale=en,orientation=portrait \ + --device model=oriole,version=32,locale=en,orientation=portrait \ + --device model=felix,version=33,locale=en,orientation=portrait \ + --client-details matrixLabel="Android Emarsys SDK - physical devices" run-github-workflow-locally: check-env ## needs act to be installed: `brew install act` and docker running. Pass in workflow path to run @act --secret-file ./workflow.secrets -W $(WORKFLOW_PATH) --container-architecture linux/amd64 diff --git a/common/build.gradle.kts b/common/build.gradle.kts index b1c6ae25a..ea6f251b7 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -19,15 +19,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/common/src/androidTest/java/com/emarsys/common/feature/InnerFeatureTest.kt b/common/src/androidTest/java/com/emarsys/common/feature/InnerFeatureTest.kt index 71b503b8e..6862cbe32 100644 --- a/common/src/androidTest/java/com/emarsys/common/feature/InnerFeatureTest.kt +++ b/common/src/androidTest/java/com/emarsys/common/feature/InnerFeatureTest.kt @@ -1,13 +1,13 @@ package com.emarsys.common.feature +import com.emarsys.testUtil.AnnotationSpec import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Test -class InnerFeatureTest { +class InnerFeatureTest : AnnotationSpec() { @Test fun testValues_shouldReturnCorrectValues() { diff --git a/core-api/build.gradle.kts b/core-api/build.gradle.kts index 0ebd99ada..2c145d3bd 100644 --- a/core-api/build.gradle.kts +++ b/core-api/build.gradle.kts @@ -25,15 +25,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/core-api/src/androidTest/java/com/emarsys/core/api/ApiTest.kt b/core-api/src/androidTest/java/com/emarsys/core/api/ApiTest.kt index 0898dd37f..9a53a0b43 100644 --- a/core-api/src/androidTest/java/com/emarsys/core/api/ApiTest.kt +++ b/core-api/src/androidTest/java/com/emarsys/core/api/ApiTest.kt @@ -1,10 +1,10 @@ package com.emarsys.core.api -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec -class ApiTest { +class ApiTest : AnnotationSpec() { @Test diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 206ad6be3..a8d73efd1 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -25,9 +25,6 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" - val version: GitVersion by rootProject.extra buildConfigField("int", "VERSION_CODE", "${version.versionCode}") @@ -44,7 +41,15 @@ android { packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/core/src/androidTest/java/com/emarsys/core/DefaultCoreCompletionHandlerTest.kt b/core/src/androidTest/java/com/emarsys/core/DefaultCoreCompletionHandlerTest.kt index 26ca2b18e..1deb110cf 100644 --- a/core/src/androidTest/java/com/emarsys/core/DefaultCoreCompletionHandlerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/DefaultCoreCompletionHandlerTest.kt @@ -4,9 +4,8 @@ import com.emarsys.core.api.ResponseErrorException import com.emarsys.core.api.result.CompletionListener import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.spy @@ -15,7 +14,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -class DefaultCoreCompletionHandlerTest { +class DefaultCoreCompletionHandlerTest : AnnotationSpec() { companion object { const val STATUS_CODE = 500 @@ -30,7 +29,7 @@ class DefaultCoreCompletionHandlerTest { private lateinit var responseErrorException: ResponseErrorException - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun init() { mockMap = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt b/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt index f254094b0..9acb7efeb 100644 --- a/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt @@ -13,6 +13,7 @@ import com.emarsys.core.device.LanguageProvider import com.emarsys.core.provider.hardwareid.HardwareIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.util.AndroidVersionUtils +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ApplicationTestUtils.applicationDebug import com.emarsys.testUtil.ApplicationTestUtils.applicationRelease import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext @@ -22,16 +23,13 @@ import io.kotest.matchers.booleans.shouldBeTrue import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.util.* -class DeviceInfoTest { +class DeviceInfoTest : AnnotationSpec() { companion object { private const val HARDWARE_ID = "hwid" @@ -49,7 +47,7 @@ class DeviceInfoTest { private lateinit var mockNotificationManagerHelper: NotificationSettings - @BeforeEach + @Before fun setup() { tz = TimeZone.getTimeZone("Asia/Tokyo") TimeZone.setDefault(tz) @@ -72,7 +70,7 @@ class DeviceInfoTest { ) } - @AfterEach + @After fun teardown() { TimeZone.setDefault(null) } diff --git a/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleActionRegistryTest.kt b/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleActionRegistryTest.kt index 3f244579a..5499e56b2 100644 --- a/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleActionRegistryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleActionRegistryTest.kt @@ -6,9 +6,8 @@ import com.emarsys.core.activity.ActivityLifecycleAction.ActivityLifecycle.RESUM import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.activity.CurrentActivityProvider +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.doReturn @@ -19,7 +18,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class ActivityLifecycleActionRegistryTest { +class ActivityLifecycleActionRegistryTest : AnnotationSpec() { private lateinit var activityLifecycleActionRegistry: ActivityLifecycleActionRegistry private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder @@ -30,7 +29,7 @@ class ActivityLifecycleActionRegistryTest { private lateinit var mockActions: MutableList private lateinit var mockActivity: Activity - @BeforeEach + @Before fun setup() { mockActivity = mock() mockAction1 = mock { diff --git a/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleWatchdogTest.kt b/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleWatchdogTest.kt index f5ecc4cf9..e78abe04a 100644 --- a/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleWatchdogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/activity/ActivityLifecycleWatchdogTest.kt @@ -1,20 +1,17 @@ package com.emarsys.core.activity import android.app.Activity -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class ActivityLifecycleWatchdogTest { +class ActivityLifecycleWatchdogTest : AnnotationSpec() { private lateinit var watchdog: ActivityLifecycleWatchdog private lateinit var mockRegistry: ActivityLifecycleActionRegistry private lateinit var mockActivity: Activity - @BeforeEach + @Before fun setUp() { mockRegistry = mock() mockActivity = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/activity/CurrentActivityWatchdogTest.kt b/core/src/androidTest/java/com/emarsys/core/activity/CurrentActivityWatchdogTest.kt index 8f5f895ef..a181c91ea 100644 --- a/core/src/androidTest/java/com/emarsys/core/activity/CurrentActivityWatchdogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/activity/CurrentActivityWatchdogTest.kt @@ -5,22 +5,21 @@ import android.os.Bundle import com.emarsys.core.provider.Property import com.emarsys.core.provider.activity.CurrentActivityProvider import com.emarsys.core.provider.activity.FallbackActivityProvider +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.inOrder import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions -class CurrentActivityWatchdogTest { +class CurrentActivityWatchdogTest : AnnotationSpec() { private lateinit var watchdog: CurrentActivityWatchdog private lateinit var activity: Activity private lateinit var nextActivity: Activity private lateinit var activityProvider: Property - @BeforeEach + @Before fun setUp() { activityProvider = mock() watchdog = CurrentActivityWatchdog(activityProvider) diff --git a/core/src/androidTest/java/com/emarsys/core/api/AsyncProxyTest.kt b/core/src/androidTest/java/com/emarsys/core/api/AsyncProxyTest.kt index ac6f786d9..b83416fd4 100644 --- a/core/src/androidTest/java/com/emarsys/core/api/AsyncProxyTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/api/AsyncProxyTest.kt @@ -2,21 +2,18 @@ package com.emarsys.core.api import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.ThreadSpy import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import java.util.concurrent.Callable import java.util.concurrent.CountDownLatch -class AsyncProxyTest { +class AsyncProxyTest : AnnotationSpec() { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() } diff --git a/core/src/androidTest/java/com/emarsys/core/api/LogExceptionProxyTest.kt b/core/src/androidTest/java/com/emarsys/core/api/LogExceptionProxyTest.kt index 33270a756..0a688bc36 100644 --- a/core/src/androidTest/java/com/emarsys/core/api/LogExceptionProxyTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/api/LogExceptionProxyTest.kt @@ -8,10 +8,8 @@ import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.util.log.LogLevel import com.emarsys.core.util.log.Logger import com.emarsys.core.util.log.entry.CrashLog +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.eq @@ -21,11 +19,11 @@ import java.lang.reflect.InvocationTargetException import java.util.concurrent.CountDownLatch -class LogExceptionProxyTest { +class LogExceptionProxyTest : AnnotationSpec() { private lateinit var mockLogger: Logger private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() mockLogger = mock() @@ -39,7 +37,7 @@ class LogExceptionProxyTest { setupCoreComponent(dependencyContainer) } - @AfterEach + @After fun tearDown() { tearDownCoreComponent() } diff --git a/core/src/androidTest/java/com/emarsys/core/app/AppLifecycleObserverTest.kt b/core/src/androidTest/java/com/emarsys/core/app/AppLifecycleObserverTest.kt index b80222c06..381fbb075 100644 --- a/core/src/androidTest/java/com/emarsys/core/app/AppLifecycleObserverTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/app/AppLifecycleObserverTest.kt @@ -8,17 +8,14 @@ import androidx.lifecycle.LifecycleRegistry import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.session.Session +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.verify import java.util.concurrent.CountDownLatch -class AppLifecycleObserverTest { +class AppLifecycleObserverTest : AnnotationSpec() { private lateinit var mockSession: Session private lateinit var appLifecycleObserver: AppLifecycleObserver private lateinit var coreHandlerHolder: ConcurrentHandlerHolder @@ -26,7 +23,7 @@ class AppLifecycleObserverTest { private lateinit var uiHandler: Handler - @BeforeEach + @Before fun setUp() { uiHandler = Handler(Looper.getMainLooper()) mockSession = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/concurrency/ConcurrentHandlerHolderFactoryTest.kt b/core/src/androidTest/java/com/emarsys/core/concurrency/ConcurrentHandlerHolderFactoryTest.kt index 09193f6dc..2c1e18c28 100644 --- a/core/src/androidTest/java/com/emarsys/core/concurrency/ConcurrentHandlerHolderFactoryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/concurrency/ConcurrentHandlerHolderFactoryTest.kt @@ -1,23 +1,21 @@ package com.emarsys.core.concurrency import com.emarsys.core.handler.ConcurrentHandlerHolder +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class ConcurrentHandlerHolderFactoryTest { +class ConcurrentHandlerHolderFactoryTest : AnnotationSpec() { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() } - @AfterEach + @After fun tearDown() { concurrentHandlerHolder.coreLooper.quit() } diff --git a/core/src/androidTest/java/com/emarsys/core/concurrency/CoreHandlerTest.kt b/core/src/androidTest/java/com/emarsys/core/concurrency/CoreHandlerTest.kt index 04410470e..073ef2ef8 100644 --- a/core/src/androidTest/java/com/emarsys/core/concurrency/CoreHandlerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/concurrency/CoreHandlerTest.kt @@ -1,19 +1,17 @@ package com.emarsys.core.concurrency import android.os.HandlerThread +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import java.util.concurrent.CountDownLatch -class CoreHandlerTest { +class CoreHandlerTest : AnnotationSpec() { private lateinit var handler: CoreHandler private lateinit var handlerThread: HandlerThread private lateinit var failingRunnable: Runnable - @BeforeEach + @Before fun setUp() { val threadName = "test" handlerThread = HandlerThread(threadName) @@ -22,7 +20,7 @@ class CoreHandlerTest { failingRunnable = Runnable { throw RuntimeException("error") } } - @AfterEach + @After fun tearDown() { handlerThread.quit() } diff --git a/core/src/androidTest/java/com/emarsys/core/connection/ConnectionProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/connection/ConnectionProviderTest.kt index 04b37be08..0ad319405 100644 --- a/core/src/androidTest/java/com/emarsys/core/connection/ConnectionProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/connection/ConnectionProviderTest.kt @@ -1,16 +1,15 @@ package com.emarsys.core.connection import com.emarsys.core.request.model.RequestModel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.should import io.kotest.matchers.types.beTheSameInstanceAs -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.mock import org.mockito.Mockito.`when` import java.net.URL -class ConnectionProviderTest { +class ConnectionProviderTest : AnnotationSpec() { companion object { const val HTTP_PATH = "http://emarsys.com" const val HTTPS_PATH = "https://emarsys.com" @@ -19,7 +18,7 @@ class ConnectionProviderTest { private lateinit var provider: ConnectionProvider - @BeforeEach + @Before fun setUp() { provider = ConnectionProvider() } diff --git a/core/src/androidTest/java/com/emarsys/core/connection/ConnectionWatchDogTest.kt b/core/src/androidTest/java/com/emarsys/core/connection/ConnectionWatchDogTest.kt index dee11c25a..70b07824d 100644 --- a/core/src/androidTest/java/com/emarsys/core/connection/ConnectionWatchDogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/connection/ConnectionWatchDogTest.kt @@ -8,6 +8,7 @@ import androidx.test.filters.SdkSuppress import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.worker.DefaultWorker +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils.getContextMockWithAppContextWithConnectivityManager import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.ReflectionTestUtils @@ -18,17 +19,15 @@ import io.mockk.every import io.mockk.just import io.mockk.mockk import io.mockk.verify -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test @SdkSuppress(minSdkVersion = Build.VERSION_CODES.P) -class ConnectionWatchDogTest { +class ConnectionWatchDogTest : AnnotationSpec() { private lateinit var context: Context private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setup() { context = getTargetContext().applicationContext concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() diff --git a/core/src/androidTest/java/com/emarsys/core/connection/ConnectivityChangeReceiverTest.kt b/core/src/androidTest/java/com/emarsys/core/connection/ConnectivityChangeReceiverTest.kt index 7ef86038a..5621bcb66 100644 --- a/core/src/androidTest/java/com/emarsys/core/connection/ConnectivityChangeReceiverTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/connection/ConnectivityChangeReceiverTest.kt @@ -7,14 +7,12 @@ import androidx.test.platform.app.InstrumentationRegistry import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.fake.FakeConnectionChangeListener import com.emarsys.core.handler.ConcurrentHandlerHolder +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import java.util.concurrent.CountDownLatch -class ConnectivityChangeReceiverTest { +class ConnectivityChangeReceiverTest : AnnotationSpec() { private lateinit var receiver: ConnectivityChangeReceiver private lateinit var mockListener: ConnectionChangeListener private lateinit var context: Context @@ -22,7 +20,7 @@ class ConnectivityChangeReceiverTest { lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setup() { context = InstrumentationRegistry.getInstrumentation().targetContext concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() @@ -30,7 +28,7 @@ class ConnectivityChangeReceiverTest { mockListener = mock() } - @AfterEach + @After fun tearDown() { concurrentHandlerHolder.coreLooper.quit() } diff --git a/core/src/androidTest/java/com/emarsys/core/connection/Connectivity_getConnectionState_ParameterizedTest.kt b/core/src/androidTest/java/com/emarsys/core/connection/Connectivity_getConnectionState_ParameterizedTest.kt index d25087e51..80032b5c6 100644 --- a/core/src/androidTest/java/com/emarsys/core/connection/Connectivity_getConnectionState_ParameterizedTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/connection/Connectivity_getConnectionState_ParameterizedTest.kt @@ -4,6 +4,7 @@ import android.net.NetworkCapabilities import android.os.Build import androidx.test.filters.SdkSuppress import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils.getConnectivityManagerMock import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.ReflectionTestUtils.setInstanceField @@ -11,11 +12,10 @@ import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Test @SdkSuppress(minSdkVersion = Build.VERSION_CODES.P) -class Connectivity_getConnectionState_ParameterizedTest { +class Connectivity_getConnectionState_ParameterizedTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt b/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt index 28706f70d..070f4e3e0 100644 --- a/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt @@ -5,14 +5,13 @@ import com.emarsys.core.contentresolver.hardwareid.HardwareIdContentResolver import com.emarsys.core.crypto.HardwareIdentificationCrypto import com.emarsys.core.database.DatabaseContract import com.emarsys.core.device.HardwareIdentification +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.mockk.every import io.mockk.mockk import io.mockk.verify -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class HardwareIdContentResolverTest { +class HardwareIdContentResolverTest : AnnotationSpec() { companion object { private val SHARED_PACKAGE_NAMES = @@ -28,7 +27,7 @@ class HardwareIdContentResolverTest { private lateinit var mockHardwareIdentificationCrypto: HardwareIdentificationCrypto private lateinit var mockCursor: Cursor - @BeforeEach + @Before fun setUp() { mockCursor = mockk(relaxed = true) { every { moveToFirst() } returns true diff --git a/core/src/androidTest/java/com/emarsys/core/crypto/CryptoTest.kt b/core/src/androidTest/java/com/emarsys/core/crypto/CryptoTest.kt index 96e26bf8f..428e8801d 100644 --- a/core/src/androidTest/java/com/emarsys/core/crypto/CryptoTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/crypto/CryptoTest.kt @@ -1,16 +1,17 @@ package com.emarsys.core.crypto import android.util.Base64 +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.Test import java.security.KeyFactory import java.security.PublicKey import java.security.spec.X509EncodedKeySpec -class CryptoTest { +class CryptoTest : AnnotationSpec() { private companion object { - private const val PUBLIC_KEY = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAELjWEUIBX9zlm1OI4gF1hMCBLzpaBwgs9HlmSIBAqP4MDGy4ibOOV3FVDrnAY0Q34LZTbPBlp3gRNZJ19UoSy2Q==" + private const val PUBLIC_KEY = + "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAELjWEUIBX9zlm1OI4gF1hMCBLzpaBwgs9HlmSIBAqP4MDGy4ibOOV3FVDrnAY0Q34LZTbPBlp3gRNZJ19UoSy2Q==" private const val SECRET = "testSecret" private const val OLD_ITERATION_COUNT = 65536 } @@ -18,8 +19,9 @@ class CryptoTest { @Test fun testVerify_success() { val crypto = Crypto(createPublicKey()) - val result = crypto.verify("testData".toByteArray(), - "MEUCIQDb6AxUK2W4IyKJ/P02Y0BNlm2ioP7ytu3dOyumc4hN8gIgEzwKmeCtd6Jn9Neg4Epn+oSkV4wAJNmfAgeeAM0u7Nw=" + val result = crypto.verify( + "testData".toByteArray(), + "MEUCIQDb6AxUK2W4IyKJ/P02Y0BNlm2ioP7ytu3dOyumc4hN8gIgEzwKmeCtd6Jn9Neg4Epn+oSkV4wAJNmfAgeeAM0u7Nw=" ) result shouldBe true diff --git a/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt b/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt index 2788ca272..e6ae28896 100644 --- a/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt @@ -1,13 +1,12 @@ package com.emarsys.core.crypto import com.emarsys.core.device.HardwareIdentification +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class HardwareIdentificationCryptoTest { +class HardwareIdentificationCryptoTest : AnnotationSpec() { companion object { private const val SECRET = "SECRET" @@ -16,14 +15,15 @@ class HardwareIdentificationCryptoTest { private const val SALT = "testSalt" private const val IV = "testIv" private val HARDWARE = HardwareIdentification(HARDWARE_ID, null, null, null) - private val ENCRYPTED_HARDWARE = HardwareIdentification(HARDWARE_ID, ENCRYPTED_HARDWARE_ID, SALT, IV) + private val ENCRYPTED_HARDWARE = + HardwareIdentification(HARDWARE_ID, ENCRYPTED_HARDWARE_ID, SALT, IV) } private lateinit var hardwareIdentificationCryptoWithSecret: HardwareIdentificationCrypto private lateinit var hardwareIdentificationCryptoWithoutSecret: HardwareIdentificationCrypto private lateinit var mockCrypto: Crypto - @BeforeEach + @Before fun setUp() { mockCrypto = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabaseTest.kt b/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabaseTest.kt index 6ef57c53d..82a67562c 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabaseTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabaseTest.kt @@ -4,25 +4,23 @@ import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.trigger.TriggerEvent import com.emarsys.core.database.trigger.TriggerKey import com.emarsys.core.database.trigger.TriggerType +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class DelegatingCoreSQLiteDatabaseTest { - +class DelegatingCoreSQLiteDatabaseTest : AnnotationSpec() { private lateinit var db: DelegatingCoreSQLiteDatabase private lateinit var triggerMap: MutableMap> - @BeforeEach + @Before fun init() { - val coreDbHelper = CoreDbHelper(InstrumentationRegistry.getTargetContext().applicationContext, mutableMapOf()) + val coreDbHelper = CoreDbHelper( + InstrumentationRegistry.getTargetContext().applicationContext, + mutableMapOf() + ) triggerMap = mutableMapOf() diff --git a/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest.kt b/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest.kt index efbe74410..fd0569447 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest.kt @@ -5,22 +5,41 @@ import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.trigger.TriggerEvent import com.emarsys.core.database.trigger.TriggerKey import com.emarsys.core.database.trigger.TriggerType +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry +import io.kotest.data.forAll +import io.kotest.data.headers +import io.kotest.data.row +import io.kotest.data.table import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions -class DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest { +class DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest : AnnotationSpec() { + + companion object { + + private const val TABLE_NAME = "TEST" + private const val COLUMN_1 = "column1" + private const val COLUMN_2 = "column2" + const val CREATE = "CREATE TABLE $TABLE_NAME ($COLUMN_1 TEXT, $COLUMN_2 INTEGER);" + const val DROP = "DROP TABLE $TABLE_NAME IF EXISTS;" + + private lateinit var mockRunnable: Runnable + private lateinit var db: DelegatingCoreSQLiteDatabase + + private val contentValues = ContentValues().apply { + put(COLUMN_1, "value") + put(COLUMN_2, 1234) + } + } private lateinit var registeredTriggerMap: MutableMap> - @BeforeEach - fun init() { + @Before + fun setUp() { DatabaseTestUtils.deleteCoreDatabase() val coreDbHelper = CoreDbHelper( @@ -35,28 +54,89 @@ class DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest { mockRunnable = mock() } - @ParameterizedTest - @MethodSource("data") - fun testTrigger( - tableName: String, - triggerType: TriggerType, - triggerEvent: TriggerEvent, - setup: Runnable, - trigger: Runnable, - action: Runnable - ) { - setup.run() - - val unusedTriggerMap = createUnusedTriggerMap(tableName, triggerEvent) - unusedTriggerMap.forEach { (key, trigger) -> - db.registerTrigger(key.tableName, key.triggerType, key.triggerEvent, trigger) - } - db.registerTrigger(tableName, triggerType, triggerEvent, trigger) + @Test + fun testTrigger() { + table( + headers("tableName", "triggerType", "triggerEvent", "setup", "trigger", "action"), + row( + TABLE_NAME, + TriggerType.BEFORE, + TriggerEvent.INSERT, + Runnable { + + }, + Runnable { + db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { + it.count shouldBe 0 + } + mockRunnable.run() + }, + Runnable { + db.insert(TABLE_NAME, null, contentValues) + }), + row( + TABLE_NAME, + TriggerType.AFTER, + TriggerEvent.INSERT, + Runnable { + + }, + Runnable { + db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { + it.count shouldBe 1 + } + mockRunnable.run() + }, + Runnable { + db.insert(TABLE_NAME, null, contentValues) + }), + row( + TABLE_NAME, + TriggerType.BEFORE, + TriggerEvent.DELETE, + Runnable { + db.insert(TABLE_NAME, null, contentValues) + }, + Runnable { + db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { + it.count shouldBe 1 + } + mockRunnable.run() + }, + Runnable { + db.delete(TABLE_NAME, null, null) + }), + row( + TABLE_NAME, + TriggerType.AFTER, + TriggerEvent.DELETE, + Runnable { + db.insert(TABLE_NAME, null, contentValues) + }, + Runnable { + db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { + it.count shouldBe 0 + } + mockRunnable.run() + }, + Runnable { + db.delete(TABLE_NAME, null, null) + }) + ).forAll { tableName, triggerType, triggerEvent, setup, trigger, action -> + setUp() + setup.run() + + val unusedTriggerMap = createUnusedTriggerMap(tableName, triggerEvent) + unusedTriggerMap.forEach { (key, trigger) -> + db.registerTrigger(key.tableName, key.triggerType, key.triggerEvent, trigger) + } + db.registerTrigger(tableName, triggerType, triggerEvent, trigger) - action.run() + action.run() - unusedTriggerMap.values.forEach { verifyNoInteractions(it) } - verify(mockRunnable).run() + unusedTriggerMap.values.forEach { verifyNoInteractions(it) } + verify(mockRunnable).run() + } } private fun createUnusedTriggerMap( @@ -80,89 +160,4 @@ class DelegatingCoreSQLiteDatabase_registerTrigger_parameterizedTest { } } - companion object { - - private const val TABLE_NAME = "TEST" - private const val COLUMN_1 = "column1" - private const val COLUMN_2 = "column2" - const val CREATE = "CREATE TABLE $TABLE_NAME ($COLUMN_1 TEXT, $COLUMN_2 INTEGER);" - - private lateinit var mockRunnable: Runnable - private lateinit var db: DelegatingCoreSQLiteDatabase - - private val contentValues = ContentValues().apply { - put(COLUMN_1, "value") - put(COLUMN_2, 1234) - } - - @JvmStatic - fun data(): Collection> { - return listOf( - arrayOf( - TABLE_NAME, - TriggerType.BEFORE, - TriggerEvent.INSERT, - Runnable { - - }, - Runnable { - db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { - it.count shouldBe 0 - } - mockRunnable.run() - }, - Runnable { - db.insert(TABLE_NAME, null, contentValues) - }), - arrayOf( - TABLE_NAME, - TriggerType.AFTER, - TriggerEvent.INSERT, - Runnable { - - }, - Runnable { - db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { - it.count shouldBe 1 - } - mockRunnable.run() - }, - Runnable { - db.insert(TABLE_NAME, null, contentValues) - }), - arrayOf( - TABLE_NAME, - TriggerType.BEFORE, - TriggerEvent.DELETE, - Runnable { - db.insert(TABLE_NAME, null, contentValues) - }, - Runnable { - db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { - it.count shouldBe 1 - } - mockRunnable.run() - }, - Runnable { - db.delete(TABLE_NAME, null, null) - }), - arrayOf( - TABLE_NAME, - TriggerType.AFTER, - TriggerEvent.DELETE, - Runnable { - db.insert(TABLE_NAME, null, contentValues) - }, - Runnable { - db.backingDatabase.rawQuery("SELECT * FROM $TABLE_NAME", emptyArray()).let { - it.count shouldBe 0 - } - mockRunnable.run() - }, - Runnable { - db.delete(TABLE_NAME, null, null) - }) - ) - } - } } \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest.kt b/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest.kt index b536ad146..de66b7909 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest.kt @@ -4,21 +4,34 @@ import android.content.ContentValues import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.trigger.TriggerEvent import com.emarsys.core.database.trigger.TriggerType +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource -import org.mockito.Mockito +import io.kotest.data.forAll +import io.kotest.data.row +import kotlinx.coroutines.runBlocking import org.mockito.Mockito.mock +import org.mockito.Mockito.verify -class DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest { +class DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest : AnnotationSpec() { + + companion object { + private const val TABLE_NAME = "TEST" + private const val COLUMN_1 = "column1" + private const val COLUMN_2 = "column2" + const val CREATE = "CREATE TABLE $TABLE_NAME ($COLUMN_1 TEXT, $COLUMN_2 INTEGER);" + + private val contentValues = ContentValues().apply { + put(COLUMN_1, "value") + put(COLUMN_2, 1234) + } + } private lateinit var mockRunnable: Runnable private lateinit var db: DelegatingCoreSQLiteDatabase - @BeforeEach - fun init() { + @Before + fun setUp() { DatabaseTestUtils.deleteCoreDatabase() val coreDbHelper = CoreDbHelper( @@ -29,78 +42,60 @@ class DelegatingCoreSQLiteDatabase_triggerRecursion_parameterizedTest { db.backingDatabase.execSQL(CREATE) - mockRunnable = mock(Runnable::class.java) - } - - @ParameterizedTest - @MethodSource("data") - fun testRegisterTrigger_doesNotRunInto_recursiveTriggerLoop( - triggerType: TriggerType, - triggerEvent: TriggerEvent, - triggerAction: Runnable - ) { - val trigger = Runnable { - triggerAction.run() - mockRunnable.run() - } - - db.registerTrigger(TABLE_NAME, triggerType, triggerEvent, trigger) - - triggerAction.run() - - Mockito.verify(mockRunnable).run() + mockRunnable = mock() } - companion object { - private const val TABLE_NAME = "TEST" - private const val COLUMN_1 = "column1" - private const val COLUMN_2 = "column2" - const val CREATE = "CREATE TABLE $TABLE_NAME ($COLUMN_1 TEXT, $COLUMN_2 INTEGER);" - - private val contentValues = ContentValues().apply { - put(COLUMN_1, "value") - put(COLUMN_2, 1234) - } - } - - fun data(): Collection> { - return listOf( - arrayOf( + @Test + fun testRegisterTrigger_doesNotRunInto_recursiveTriggerLoop() = runBlocking { + forAll( + row( TriggerType.BEFORE, TriggerEvent.INSERT, Runnable { db.insert(TABLE_NAME, null, contentValues) }), - arrayOf( + row( TriggerType.AFTER, TriggerEvent.INSERT, Runnable { db.insert(TABLE_NAME, null, contentValues) }), - arrayOf( + row( TriggerType.BEFORE, TriggerEvent.DELETE, Runnable { db.delete(TABLE_NAME, null, null) }), - arrayOf( + row( TriggerType.AFTER, TriggerEvent.DELETE, Runnable { db.delete(TABLE_NAME, null, null) }), - arrayOf( + row( TriggerType.BEFORE, TriggerEvent.UPDATE, Runnable { db.update(TABLE_NAME, contentValues, null, null) }), - arrayOf( + row( TriggerType.AFTER, TriggerEvent.UPDATE, Runnable { db.update(TABLE_NAME, contentValues, null, null) }) - ) + ) { triggerType, triggerEvent, triggerAction -> + setUp() + val trigger = Runnable { + triggerAction.run() + mockRunnable.run() + } + + db.registerTrigger(TABLE_NAME, triggerType, triggerEvent, trigger) + + triggerAction.run() + + verify(mockRunnable).run() + } } } \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/database/helper/AbstractDbHelperTest.kt b/core/src/androidTest/java/com/emarsys/core/database/helper/AbstractDbHelperTest.kt index 41aee479c..09b7856f3 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/helper/AbstractDbHelperTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/helper/AbstractDbHelperTest.kt @@ -3,12 +3,11 @@ package com.emarsys.core.database.helper import android.content.Context import android.database.sqlite.SQLiteDatabase import com.emarsys.core.database.trigger.TriggerKey +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class AbstractDbHelperTest { +class AbstractDbHelperTest : AnnotationSpec() { private class DummyDbHelper( context: Context, databaseName: String, @@ -24,7 +23,7 @@ class AbstractDbHelperTest { private lateinit var triggerMap: MutableMap> - @BeforeEach + @Before fun init() { context = getTargetContext() triggerMap = mutableMapOf() diff --git a/core/src/androidTest/java/com/emarsys/core/database/helper/CoreDbHelperTest.kt b/core/src/androidTest/java/com/emarsys/core/database/helper/CoreDbHelperTest.kt index 9922deefe..8d222e83e 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/helper/CoreDbHelperTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/helper/CoreDbHelperTest.kt @@ -2,27 +2,24 @@ package com.emarsys.core.database.helper import android.database.Cursor import android.database.sqlite.SQLiteDatabase +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class CoreDbHelperTest { +class CoreDbHelperTest : AnnotationSpec() { companion object { const val LATEST_DB_VERSION = 5 } - private lateinit var dbHelper: CoreDbHelper private lateinit var db: SQLiteDatabase - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() dbHelper = CoreDbHelper( @@ -32,7 +29,7 @@ class CoreDbHelperTest { DatabaseTestUtils.dropAllTables(db) } - @AfterEach + @After fun tearDown() { db.close() } diff --git a/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt b/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt index 4a0b83ed6..2da00ac76 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt @@ -20,13 +20,12 @@ import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestModel import com.emarsys.core.util.serialization.SerializationUtils.serializableToBlob +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.mockito.anyNotNull import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull @@ -37,7 +36,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -class AbstractSqliteRepositoryTest { +class AbstractSqliteRepositoryTest : AnnotationSpec() { companion object { private const val DISTINCT = true @@ -58,7 +57,7 @@ class AbstractSqliteRepositoryTest { private lateinit var testConcurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun init() { DatabaseTestUtils.deleteCoreDatabase() diff --git a/core/src/androidTest/java/com/emarsys/core/database/repository/specification/EverythingTest.kt b/core/src/androidTest/java/com/emarsys/core/database/repository/specification/EverythingTest.kt index 4d713b4c4..e146066cf 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/repository/specification/EverythingTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/repository/specification/EverythingTest.kt @@ -5,23 +5,21 @@ import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.shard.ShardModel import com.emarsys.core.shard.ShardModelRepository +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.collections.beEmpty import io.kotest.matchers.should import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class EverythingTest { +class EverythingTest : AnnotationSpec() { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() diff --git a/core/src/androidTest/java/com/emarsys/core/database/repository/specification/FilterByRequestIdsTest.kt b/core/src/androidTest/java/com/emarsys/core/database/repository/specification/FilterByRequestIdsTest.kt index f9a10fe52..ddf46b4b3 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/repository/specification/FilterByRequestIdsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/repository/specification/FilterByRequestIdsTest.kt @@ -7,15 +7,13 @@ import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestModel import com.emarsys.core.request.model.RequestModelRepository import com.emarsys.core.request.model.specification.FilterByRequestIds +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class FilterByRequestIdsTest { +class FilterByRequestIdsTest : AnnotationSpec() { private lateinit var repository: RequestModelRepository @@ -24,7 +22,7 @@ class FilterByRequestIdsTest { private lateinit var requestModel3: RequestModel private lateinit var requestModel4: RequestModel - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() val timestampProvider = TimestampProvider() diff --git a/core/src/androidTest/java/com/emarsys/core/database/repository/specification/QueryLatestRequestModelTest.kt b/core/src/androidTest/java/com/emarsys/core/database/repository/specification/QueryLatestRequestModelTest.kt index 8df447c0f..05968e42f 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/repository/specification/QueryLatestRequestModelTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/repository/specification/QueryLatestRequestModelTest.kt @@ -7,21 +7,19 @@ import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestModel import com.emarsys.core.request.model.RequestModelRepository import com.emarsys.core.request.model.specification.QueryLatestRequestModel +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class QueryLatestRequestModelTest { +class QueryLatestRequestModelTest : AnnotationSpec() { private lateinit var specification: QueryLatestRequestModel - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() specification = QueryLatestRequestModel() diff --git a/core/src/androidTest/java/com/emarsys/core/device/LanguageProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/device/LanguageProviderTest.kt index eef063e8f..33c6d2e19 100644 --- a/core/src/androidTest/java/com/emarsys/core/device/LanguageProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/device/LanguageProviderTest.kt @@ -2,18 +2,17 @@ package com.emarsys.core.device import android.os.Build.VERSION_CODES.P import androidx.test.filters.SdkSuppress +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import java.util.Locale -class LanguageProviderTest { +class LanguageProviderTest : AnnotationSpec() { private lateinit var languageProvider: LanguageProvider - @BeforeEach + @Before fun setUp() { languageProvider = LanguageProvider() } diff --git a/core/src/androidTest/java/com/emarsys/core/endpoint/ServiceEndpointProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/endpoint/ServiceEndpointProviderTest.kt index d2552161b..0b8c55a3b 100644 --- a/core/src/androidTest/java/com/emarsys/core/endpoint/ServiceEndpointProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/endpoint/ServiceEndpointProviderTest.kt @@ -1,26 +1,22 @@ package com.emarsys.core.endpoint import com.emarsys.core.storage.StringStorage +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito -class ServiceEndpointProviderTest { +class ServiceEndpointProviderTest : AnnotationSpec() { companion object { const val ENDPOINT = "https://emarsys.com" const val DEFAULT_ENDPOINT = "https://default.emarsys.com" } - private lateinit var serviceEndpointProvider: ServiceEndpointProvider private lateinit var mockServiceUrlStorage: StringStorage - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockServiceUrlStorage = Mockito.mock(StringStorage::class.java) diff --git a/core/src/androidTest/java/com/emarsys/core/fake/FakeRequestTask.java b/core/src/androidTest/java/com/emarsys/core/fake/FakeRequestTask.java index 13b9e482c..e6e89a6ec 100644 --- a/core/src/androidTest/java/com/emarsys/core/fake/FakeRequestTask.java +++ b/core/src/androidTest/java/com/emarsys/core/fake/FakeRequestTask.java @@ -1,12 +1,14 @@ package com.emarsys.core.fake; import static org.mockito.Mockito.mock; + import com.emarsys.core.api.result.Try; import com.emarsys.core.connection.ConnectionProvider; import com.emarsys.core.provider.timestamp.TimestampProvider; import com.emarsys.core.request.RequestTask; import com.emarsys.core.request.model.RequestModel; import com.emarsys.core.response.ResponseModel; + import java.util.HashMap; import java.util.List; diff --git a/core/src/androidTest/java/com/emarsys/core/feature/FeatureRegistryTest.kt b/core/src/androidTest/java/com/emarsys/core/feature/FeatureRegistryTest.kt index 7b9c29ed9..6596f7676 100644 --- a/core/src/androidTest/java/com/emarsys/core/feature/FeatureRegistryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/feature/FeatureRegistryTest.kt @@ -5,21 +5,19 @@ import com.emarsys.core.feature.FeatureRegistry.disableFeature import com.emarsys.core.feature.FeatureRegistry.enableFeature import com.emarsys.core.feature.FeatureRegistry.isFeatureEnabled import com.emarsys.core.feature.FeatureRegistry.reset +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class FeatureRegistryTest { +class FeatureRegistryTest : AnnotationSpec() { private lateinit var feature1: FlipperFeature private lateinit var feature2: FlipperFeature private lateinit var feature3: FlipperFeature private lateinit var features: List - @BeforeEach + @Before fun setUp() { reset() feature1 = mock() @@ -31,7 +29,7 @@ class FeatureRegistryTest { features = listOf(feature1, feature2, feature3) } - @AfterEach + @After fun tearDown() { reset() } diff --git a/core/src/androidTest/java/com/emarsys/core/notification/NotificationManagerHelperTest.kt b/core/src/androidTest/java/com/emarsys/core/notification/NotificationManagerHelperTest.kt index 763fca20d..28762eae2 100644 --- a/core/src/androidTest/java/com/emarsys/core/notification/NotificationManagerHelperTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/notification/NotificationManagerHelperTest.kt @@ -1,15 +1,12 @@ package com.emarsys.core.notification import com.emarsys.core.api.notification.ChannelSettings +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class NotificationManagerHelperTest { +class NotificationManagerHelperTest : AnnotationSpec() { private companion object { const val CHANNEL_ID_1 = "channelId1" @@ -21,7 +18,7 @@ class NotificationManagerHelperTest { private lateinit var notificationManagerHelper: NotificationManagerHelper - @BeforeEach + @Before fun setUp() { mockNotificationManagerProxy = mock(NotificationManagerProxy::class.java) notificationManagerHelper = NotificationManagerHelper(mockNotificationManagerProxy) diff --git a/core/src/androidTest/java/com/emarsys/core/provider/activity/CurrentActivityProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/activity/CurrentActivityProviderTest.kt index 69cac77f4..e31a88841 100644 --- a/core/src/androidTest/java/com/emarsys/core/provider/activity/CurrentActivityProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/provider/activity/CurrentActivityProviderTest.kt @@ -1,14 +1,13 @@ package com.emarsys.core.provider.activity import android.app.Activity +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import java.lang.ref.WeakReference -class CurrentActivityProviderTest { +class CurrentActivityProviderTest : AnnotationSpec() { private lateinit var provider: CurrentActivityProvider private lateinit var mockFallbackActivityProvider: FallbackActivityProvider @@ -18,7 +17,7 @@ class CurrentActivityProviderTest { } - @BeforeEach + @Before fun setUp() { mockFallbackActivityProvider = mock() provider = CurrentActivityProvider(WeakReference(null), mockFallbackActivityProvider) diff --git a/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt index 51ec2f981..e1c397dcf 100644 --- a/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt @@ -7,11 +7,10 @@ import com.emarsys.core.database.repository.SqlSpecification import com.emarsys.core.device.HardwareIdentification import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.storage.Storage +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -19,7 +18,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions -class HardwareIdProviderTest { +class HardwareIdProviderTest : AnnotationSpec() { companion object { private const val HARDWARE_ID = "hw_value" @@ -47,7 +46,7 @@ class HardwareIdProviderTest { private lateinit var mockRepository: Repository - @BeforeEach + @Before fun setUp() { mockStorage = mock() mockUUIDProvider = mock { diff --git a/core/src/androidTest/java/com/emarsys/core/provider/random/RandomProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/random/RandomProviderTest.kt index 5590774b9..0f5c5d566 100644 --- a/core/src/androidTest/java/com/emarsys/core/provider/random/RandomProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/provider/random/RandomProviderTest.kt @@ -1,16 +1,16 @@ package com.emarsys.core.provider.random +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual import io.kotest.matchers.doubles.shouldBeLessThanOrEqual -import org.junit.jupiter.api.Test -class RandomProviderTest { +class RandomProviderTest : AnnotationSpec() { @Test fun testProvideRandomDouble() { val randomProvider = RandomProvider() randomProvider.provideDouble(1.0) shouldBeGreaterThanOrEqual 0.0 - randomProvider.provideDouble(1.0) shouldBeLessThanOrEqual 1.0 + randomProvider.provideDouble(1.0) shouldBeLessThanOrEqual 1.0 } } \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/provider/timestamp/TimestampProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/timestamp/TimestampProviderTest.kt index ecf4470d9..56ea6044b 100644 --- a/core/src/androidTest/java/com/emarsys/core/provider/timestamp/TimestampProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/provider/timestamp/TimestampProviderTest.kt @@ -1,9 +1,9 @@ package com.emarsys.core.provider.timestamp +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class TimestampProviderTest { +class TimestampProviderTest : AnnotationSpec() { @Test fun testProvideTimestamp_returnsTheCurrentTimestamp() { val before = System.currentTimeMillis() diff --git a/core/src/androidTest/java/com/emarsys/core/provider/uuid/UUIDProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/uuid/UUIDProviderTest.kt index 0b93cc6fa..c2530cacf 100644 --- a/core/src/androidTest/java/com/emarsys/core/provider/uuid/UUIDProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/provider/uuid/UUIDProviderTest.kt @@ -1,9 +1,9 @@ package com.emarsys.core.provider.uuid +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.Test -class UUIDProviderTest { +class UUIDProviderTest : AnnotationSpec() { @Test fun testProvideId_returnsNotNullId() { val provider = UUIDProvider() diff --git a/core/src/androidTest/java/com/emarsys/core/provider/version/VersionProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/version/VersionProviderTest.kt index 9d6a7b50d..735990545 100644 --- a/core/src/androidTest/java/com/emarsys/core/provider/version/VersionProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/provider/version/VersionProviderTest.kt @@ -1,17 +1,15 @@ package com.emarsys.core.provider.version +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class VersionProviderTest { +class VersionProviderTest : AnnotationSpec() { private lateinit var versionProvider: VersionProvider - @BeforeEach + @Before fun setUp() { versionProvider = VersionProvider() } diff --git a/core/src/androidTest/java/com/emarsys/core/request/RequestManagerDennaTest.kt b/core/src/androidTest/java/com/emarsys/core/request/RequestManagerDennaTest.kt index 1d5f45d0f..798af6104 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/RequestManagerDennaTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/RequestManagerDennaTest.kt @@ -19,21 +19,19 @@ import com.emarsys.core.shard.ShardModel import com.emarsys.core.shard.ShardModelRepository import com.emarsys.core.worker.DefaultWorker import com.emarsys.core.worker.Worker +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils.checkConnection import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.TestUrls.DENNA_ECHO import io.kotest.matchers.shouldBe import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.mock import java.util.concurrent.CountDownLatch -class RequestManagerDennaTest { +class RequestManagerDennaTest : AnnotationSpec() { private lateinit var manager: RequestManager private lateinit var headers: MutableMap private lateinit var model: RequestModel @@ -48,7 +46,7 @@ class RequestManagerDennaTest { private lateinit var mockRequestModelMapper: Mapper - @BeforeEach + @Before fun init() { deleteCoreDatabase() val requestModelMappers: MutableList> = mutableListOf() @@ -109,7 +107,7 @@ class RequestManagerDennaTest { headers["Header2"] = "value2" } - @AfterEach + @After fun tearDown() { concurrentHandlerHolder.coreLooper.quit() } diff --git a/core/src/androidTest/java/com/emarsys/core/request/RequestManagerOfflineTest.kt b/core/src/androidTest/java/com/emarsys/core/request/RequestManagerOfflineTest.kt index 5070cb5bb..13e544ddf 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/RequestManagerOfflineTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/RequestManagerOfflineTest.kt @@ -22,26 +22,23 @@ import com.emarsys.core.shard.ShardModel import com.emarsys.core.shard.ShardModelRepository import com.emarsys.core.worker.DefaultWorker import com.emarsys.core.worker.Worker +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.collections.beEmpty import io.kotest.matchers.should import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import java.io.IOException import java.util.concurrent.CountDownLatch -class RequestManagerOfflineTest { +class RequestManagerOfflineTest : AnnotationSpec() { companion object { const val URL = "https://www.emarsys.com/" } - private lateinit var connectionStates: Array private lateinit var requestResults: Array private lateinit var requestModels: Array @@ -60,7 +57,7 @@ class RequestManagerOfflineTest { private lateinit var coreCompletionHandlerMiddlewareProvider: CoreCompletionHandlerMiddlewareProvider private lateinit var mockProxyProvider: CompletionHandlerProxyProvider - @BeforeEach + @Before fun setup() { watchDogCountDown = 0 completionHandlerCountDown = 0 @@ -70,7 +67,7 @@ class RequestManagerOfflineTest { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() } - @AfterEach + @After fun tearDown() { concurrentHandlerHolder.coreLooper.quit() concurrentHandlerHolder.networkLooper.quit() diff --git a/core/src/androidTest/java/com/emarsys/core/request/RequestManagerTest.kt b/core/src/androidTest/java/com/emarsys/core/request/RequestManagerTest.kt index 57e5072ff..3c2027a6e 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/RequestManagerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/RequestManagerTest.kt @@ -22,27 +22,39 @@ import com.emarsys.core.shard.ShardModel import com.emarsys.core.worker.DefaultWorker import com.emarsys.core.worker.DelegatorCompletionHandlerProvider import com.emarsys.core.worker.Worker +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils.checkConnection import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.ReflectionTestUtils +import com.emarsys.testUtil.RetryUtils import com.emarsys.testUtil.TestUrls.DENNA_ECHO import com.emarsys.testUtil.TestUrls.customResponse import com.emarsys.testUtil.mockito.ThreadSpy +import com.emarsys.testUtil.rules.RetryRule import io.kotest.matchers.shouldBe import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -import org.junitpioneer.jupiter.RetryingTest -import org.mockito.kotlin.* +import org.junit.Rule +import org.mockito.kotlin.any +import org.mockito.kotlin.doAnswer +import org.mockito.kotlin.doReturn +import org.mockito.kotlin.isNull +import org.mockito.kotlin.mock +import org.mockito.kotlin.timeout +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever import java.net.UnknownHostException import java.util.concurrent.CountDownLatch -class RequestManagerTest { +class RequestManagerTest : AnnotationSpec() { + + @Rule + @JvmField + val retryRule: RetryRule = RetryUtils.retryRule + private lateinit var manager: RequestManager private lateinit var requestModel: RequestModel private lateinit var shardModel: ShardModel @@ -66,8 +78,7 @@ class RequestManagerTest { private lateinit var callbackRegistryThreadSpy: ThreadSpy> private lateinit var shardRepositoryThreadSpy: ThreadSpy> - - @BeforeEach + @Before fun setUp() { deleteCoreDatabase() val requestModelMappers: MutableList> = mutableListOf() @@ -155,13 +166,13 @@ class RequestManagerTest { ) } - @AfterEach + @After fun tearDown() { concurrentHandlerHolder.coreLooper.quit() } @Test - @RetryingTest(3) + fun testSubmit_shouldAddRequestModelToQueue() { manager.submit( requestModel, @@ -173,7 +184,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_withRequestModel_shouldInvokeRunOnTheWorker() { val worker = mock() ReflectionTestUtils.setInstanceField(manager, "worker", worker) @@ -185,7 +196,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_withRequestModel_executesRunnableOn_CoreSDKHandlerThread() { runBlocking { withContext(Dispatchers.IO) { @@ -197,7 +208,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_withRequestModel_Success() { whenever(mockConnectionWatchDog.isConnected).thenReturn(true, false) whenever(mockRequestRepository.isEmpty()).thenReturn(false, false, true) @@ -213,7 +224,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_withRequestModel_shouldRegisterCallbackToRegistry() { val completionListener = mock() @@ -223,7 +234,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_withRequestModel_shouldRegister_null_ToRegistryAsWell() { manager.submit(requestModel, null) @@ -232,7 +243,7 @@ class RequestManagerTest { @Test - @RetryingTest(3) + fun testSubmitNow_withoutCompletionHandler_shouldCallProxyProviderForCompletionHandler() { whenever(mockDelegatorCompletionHandlerProvider.provide(any(), any())).doReturn( mockDefaultHandler @@ -248,7 +259,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmitNow_shouldCallProxyProviderForCompletionHandler() { manager.submitNow(requestModel, fakeCompletionHandler) verify(mockDelegatorCompletionHandlerProvider).provide( @@ -260,7 +271,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmitNow_shouldCallProxyProviderForCompletionHandler_withScope() { val mockOtherHandler: Handler = mock() manager.submitNow(requestModel, fakeCompletionHandler, mockOtherHandler) @@ -273,14 +284,14 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmitNow_shouldCallRestClientsExecuteWithGivenParameters() { manager.submitNow(requestModel, fakeCompletionHandler) verify(mockRestClient).execute(requestModel, mockDefaultHandler) } @Test - @RetryingTest(3) + fun testSubmitNow_shouldCallRestClient_withDefaultHandler() { manager.submitNow(requestModel) @@ -288,7 +299,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testError_callbackWithResponseContainsRequestModel() { requestModel = RequestModel.Builder(timestampProvider, uuidProvider).url(customResponse(405)) @@ -308,7 +319,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testError_withRequestModel_callbackWithException() { requestModel = RequestModel.Builder(timestampProvider, uuidProvider) .url("https://www.nosuchwebsite.emarsys.com").method(RequestMethod.GET).build() @@ -326,7 +337,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_shouldAddShardModelToDatabase() { manager.submit(shardModel) runBlocking { @@ -335,7 +346,7 @@ class RequestManagerTest { } @Test - @RetryingTest(3) + fun testSubmit_withShardModel_executesRunnableOn_CoreSDKHandlerThread() { runBlocking { withContext(Dispatchers.IO) { diff --git a/core/src/androidTest/java/com/emarsys/core/request/RequestTaskTest.kt b/core/src/androidTest/java/com/emarsys/core/request/RequestTaskTest.kt index aea3e1ed5..36b7efb1b 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/RequestTaskTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/RequestTaskTest.kt @@ -3,12 +3,8 @@ package com.emarsys.core.request import com.emarsys.core.connection.ConnectionProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.request.model.RequestModel - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.fail - +import com.emarsys.testUtil.AnnotationSpec +import io.kotest.assertions.fail import org.mockito.kotlin.doReturn import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock @@ -16,19 +12,18 @@ import org.mockito.kotlin.whenever import java.net.URL import javax.net.ssl.HttpsURLConnection -class RequestTaskTest { +class RequestTaskTest : AnnotationSpec() { private lateinit var connectionProvider: ConnectionProvider private lateinit var mockTimestampProvider: TimestampProvider - companion object { private const val WRONG_URL = "https://localhost/missing" private const val TIMESTAMP_1: Long = 600 private const val TIMESTAMP_2: Long = 1600 } - @BeforeEach + @Before fun setUp() { connectionProvider = ConnectionProvider() mockTimestampProvider = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/request/RestClientTest.kt b/core/src/androidTest/java/com/emarsys/core/request/RestClientTest.kt index d867ab27b..c59c81a85 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/RestClientTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/RestClientTest.kt @@ -13,15 +13,12 @@ import com.emarsys.core.request.model.RequestResult import com.emarsys.core.request.model.asRequestResult import com.emarsys.core.response.ResponseHandlersProcessor import com.emarsys.core.testUtil.RequestModelTestUtils +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.TestUrls import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -29,7 +26,7 @@ import org.mockito.kotlin.verify import java.net.UnknownHostException import java.util.concurrent.CountDownLatch -class RestClientTest { +class RestClientTest : AnnotationSpec() { private lateinit var client: RestClient private lateinit var latch: CountDownLatch @@ -43,7 +40,7 @@ class RestClientTest { @Suppress("UNCHECKED_CAST") - @BeforeEach + @Before fun setup() { ConnectionTestUtils.checkConnection(InstrumentationRegistry.getTargetContext()) diff --git a/core/src/androidTest/java/com/emarsys/core/request/factory/CoreCompletionHandlerMiddlewareProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/request/factory/CoreCompletionHandlerMiddlewareProviderTest.kt index 579edf94c..60c8db0da 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/factory/CoreCompletionHandlerMiddlewareProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/factory/CoreCompletionHandlerMiddlewareProviderTest.kt @@ -9,19 +9,17 @@ import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.worker.CoreCompletionHandlerMiddleware import com.emarsys.core.worker.Worker +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.should import io.kotest.matchers.types.beInstanceOf -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.verify import java.util.concurrent.CountDownLatch -class CoreCompletionHandlerMiddlewareProviderTest { - +class CoreCompletionHandlerMiddlewareProviderTest : AnnotationSpec() { private lateinit var mockRequestRepository: Repository @@ -34,7 +32,7 @@ class CoreCompletionHandlerMiddlewareProviderTest { private lateinit var latch: CountDownLatch private lateinit var runnableFactory: RunnableFactory - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { latch = CountDownLatch(1) diff --git a/core/src/androidTest/java/com/emarsys/core/request/model/CompositeRequestModelTest.kt b/core/src/androidTest/java/com/emarsys/core/request/model/CompositeRequestModelTest.kt index 46451e05b..4a062c41f 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/model/CompositeRequestModelTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/model/CompositeRequestModelTest.kt @@ -2,13 +2,12 @@ package com.emarsys.core.request.model import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import java.net.URL -class CompositeRequestModelTest { +class CompositeRequestModelTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 800L @@ -26,7 +25,7 @@ class CompositeRequestModelTest { private lateinit var payload: Map private lateinit var headers: Map - @BeforeEach + @Before fun setUp() { payload = createPayload() headers = createHeaders() diff --git a/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelRepositoryTest.kt b/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelRepositoryTest.kt index 8fc2b1d7d..56fe50774 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelRepositoryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelRepositoryTest.kt @@ -16,18 +16,17 @@ import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.repository.specification.Everything import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.util.serialization.SerializationUtils +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import org.json.JSONException -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test +import org.junit.Assert import org.mockito.Mockito import java.util.* -class RequestModelRepositoryTest { +class RequestModelRepositoryTest : AnnotationSpec() { companion object { @@ -49,7 +48,7 @@ class RequestModelRepositoryTest { private var headers: HashMap? = null private var payload: HashMap? = null - @BeforeEach + @Before fun init() { deleteCoreDatabase() context = getTargetContext() @@ -72,21 +71,21 @@ class RequestModelRepositoryTest { result.getAsString(REQUEST_COLUMN_NAME_REQUEST_ID) shouldBe request!!.id result.getAsString(REQUEST_COLUMN_NAME_METHOD) shouldBe request!!.method.name result.getAsString(REQUEST_COLUMN_NAME_URL) shouldBe request!!.url.toString() - Assertions.assertArrayEquals( + Assert.assertArrayEquals( SerializationUtils.serializableToBlob( request!!.headers ), result.getAsByteArray(REQUEST_COLUMN_NAME_HEADERS) ) - Assertions.assertArrayEquals( + Assert.assertArrayEquals( SerializationUtils.serializableToBlob( request!!.payload ), result.getAsByteArray(REQUEST_COLUMN_NAME_PAYLOAD) ) - Assertions.assertEquals( + Assert.assertEquals( request!!.timestamp, result.getAsLong(REQUEST_COLUMN_NAME_TIMESTAMP) as Long ) - Assertions.assertEquals(request!!.ttl, result.getAsLong(REQUEST_COLUMN_NAME_TTL) as Long) + Assert.assertEquals(request!!.ttl, result.getAsLong(REQUEST_COLUMN_NAME_TTL) as Long) } @Test diff --git a/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelTest.kt b/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelTest.kt index 7cb8155a5..e04a6e0bc 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/model/RequestModelTest.kt @@ -3,19 +3,15 @@ package com.emarsys.core.request.model import android.net.Uri import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito import java.net.URL import java.util.* -class RequestModelTest { +class RequestModelTest : AnnotationSpec() { private lateinit var url: String private lateinit var method: RequestMethod private lateinit var payload: Map @@ -27,7 +23,7 @@ class RequestModelTest { private lateinit var uuidProvider: UUIDProvider - @BeforeEach + @Before fun init() { url = "https://google.com" method = RequestMethod.PUT diff --git a/core/src/androidTest/java/com/emarsys/core/request/model/specification/FilterByUrlPatternTest.kt b/core/src/androidTest/java/com/emarsys/core/request/model/specification/FilterByUrlPatternTest.kt index 1529ffd06..33b20f16c 100644 --- a/core/src/androidTest/java/com/emarsys/core/request/model/specification/FilterByUrlPatternTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/request/model/specification/FilterByUrlPatternTest.kt @@ -8,18 +8,16 @@ import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestModel import com.emarsys.core.request.model.RequestModelRepository +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.collections.shouldContainAll import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class FilterByUrlPatternTest { +class FilterByUrlPatternTest : AnnotationSpec() { private lateinit var specification: FilterByUrlPattern @@ -28,7 +26,7 @@ class FilterByUrlPatternTest { private lateinit var timestampProvider: TimestampProvider private lateinit var uuidProvider: UUIDProvider - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() pattern = "root/___/_%/event" diff --git a/core/src/androidTest/java/com/emarsys/core/resource/MetaDataReaderTest.kt b/core/src/androidTest/java/com/emarsys/core/resource/MetaDataReaderTest.kt index 1be902260..64acc55e7 100644 --- a/core/src/androidTest/java/com/emarsys/core/resource/MetaDataReaderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/resource/MetaDataReaderTest.kt @@ -3,18 +3,17 @@ package com.emarsys.core.resource import android.content.Context import android.content.pm.ApplicationInfo import android.os.Bundle +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers import org.mockito.Mockito -class MetaDataReaderTest { +class MetaDataReaderTest : AnnotationSpec() { private var reader: MetaDataReader? = null - @BeforeEach + @Before @Throws(Exception::class) fun setUp() { reader = MetaDataReader() diff --git a/core/src/androidTest/java/com/emarsys/core/response/AbstractResponseHandlerTest.kt b/core/src/androidTest/java/com/emarsys/core/response/AbstractResponseHandlerTest.kt index 760c2ae88..0ba0947d2 100644 --- a/core/src/androidTest/java/com/emarsys/core/response/AbstractResponseHandlerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/response/AbstractResponseHandlerTest.kt @@ -1,7 +1,6 @@ package com.emarsys.core.response -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -9,11 +8,11 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -class AbstractResponseHandlerTest { +class AbstractResponseHandlerTest : AnnotationSpec() { private lateinit var abstractResponseHandler: AbstractResponseHandler - @BeforeEach + @Before fun init() { abstractResponseHandler = mock() } diff --git a/core/src/androidTest/java/com/emarsys/core/response/ResponseHandlersProcessorTest.kt b/core/src/androidTest/java/com/emarsys/core/response/ResponseHandlersProcessorTest.kt index 6b7b8f857..94560e2a5 100644 --- a/core/src/androidTest/java/com/emarsys/core/response/ResponseHandlersProcessorTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/response/ResponseHandlersProcessorTest.kt @@ -1,20 +1,17 @@ package com.emarsys.core.response +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.collections.shouldContainAll -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.inOrder import org.mockito.Mockito.mock -class ResponseHandlersProcessorTest { +class ResponseHandlersProcessorTest : AnnotationSpec() { private lateinit var responseHandlersProcessor: ResponseHandlersProcessor - @BeforeEach + @Before fun setUp() { responseHandlersProcessor = ResponseHandlersProcessor() } diff --git a/core/src/androidTest/java/com/emarsys/core/response/ResponseModelTest.kt b/core/src/androidTest/java/com/emarsys/core/response/ResponseModelTest.kt index da27a7f5f..dca8cb5fc 100644 --- a/core/src/androidTest/java/com/emarsys/core/response/ResponseModelTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/response/ResponseModelTest.kt @@ -1,22 +1,18 @@ package com.emarsys.core.response + import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.request.model.RequestModel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import org.json.JSONException import org.json.JSONObject - - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.net.HttpCookie import java.util.* -class ResponseModelTest { +class ResponseModelTest : AnnotationSpec() { companion object { private const val timestamp: Long = 4200 @@ -32,7 +28,7 @@ class ResponseModelTest { private lateinit var mockRequestModel: RequestModel - @BeforeEach + @Before fun init() { statusCode = 200 message = "OK" diff --git a/core/src/androidTest/java/com/emarsys/core/shard/ShardModelRepositoryTest.kt b/core/src/androidTest/java/com/emarsys/core/shard/ShardModelRepositoryTest.kt index 1c871d398..6d227c317 100644 --- a/core/src/androidTest/java/com/emarsys/core/shard/ShardModelRepositoryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/shard/ShardModelRepositoryTest.kt @@ -11,20 +11,16 @@ import com.emarsys.core.database.DatabaseContract.SHARD_COLUMN_TYPE import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.util.serialization.SerializationUtils.serializableToBlob +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Assertions - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - +import org.junit.Assert import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import java.io.Serializable -class ShardModelRepositoryTest { +class ShardModelRepositoryTest : AnnotationSpec() { private lateinit var shardModel: ShardModel private lateinit var repository: ShardModelRepository @@ -39,7 +35,7 @@ class ShardModelRepositoryTest { const val SHARD_ID = "shard_id" } - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() context = InstrumentationRegistry.getTargetContext() @@ -63,7 +59,7 @@ class ShardModelRepositoryTest { result.getAsString(SHARD_COLUMN_TYPE) shouldBe shardModel.type result.getAsLong(SHARD_COLUMN_TIMESTAMP) shouldBe shardModel.timestamp result.getAsLong(SHARD_COLUMN_TTL) shouldBe shardModel.ttl - Assertions.assertArrayEquals( + Assert.assertArrayEquals( serializableToBlob(shardModel.data), result.getAsByteArray(SHARD_COLUMN_DATA) ) diff --git a/core/src/androidTest/java/com/emarsys/core/shard/ShardModelTest.kt b/core/src/androidTest/java/com/emarsys/core/shard/ShardModelTest.kt index 83c630454..f4caf5046 100644 --- a/core/src/androidTest/java/com/emarsys/core/shard/ShardModelTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/shard/ShardModelTest.kt @@ -2,14 +2,13 @@ package com.emarsys.core.shard import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.mock import org.mockito.Mockito.`when` -class ShardModelTest { +class ShardModelTest : AnnotationSpec() { companion object { const val ID = "shard_id" @@ -24,7 +23,7 @@ class ShardModelTest { private lateinit var payload: Map - @BeforeEach + @Before fun init() { payload = createPayload() timestampProvider = mock(TimestampProvider::class.java) diff --git a/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardIdsTest.kt b/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardIdsTest.kt index 098410bd6..f3fe97ec8 100644 --- a/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardIdsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardIdsTest.kt @@ -7,17 +7,15 @@ import com.emarsys.core.database.repository.specification.Everything import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.shard.ShardModel import com.emarsys.core.shard.ShardModelRepository +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class FilterByShardIdsTest { +class FilterByShardIdsTest : AnnotationSpec() { private lateinit var context: Context private lateinit var originalShardList: List @@ -25,7 +23,7 @@ class FilterByShardIdsTest { private lateinit var concurrentHadlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() context = InstrumentationRegistry.getTargetContext().applicationContext diff --git a/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardTypeTest.kt b/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardTypeTest.kt index 7864e4944..77effc865 100644 --- a/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardTypeTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/shard/specification/FilterByShardTypeTest.kt @@ -6,17 +6,15 @@ import com.emarsys.core.database.repository.specification.Everything import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.shard.ShardModel import com.emarsys.core.shard.ShardModelRepository +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class FilterByShardTypeTest { +class FilterByShardTypeTest : AnnotationSpec() { companion object { @@ -28,7 +26,7 @@ class FilterByShardTypeTest { private lateinit var repository: ShardModelRepository private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { DatabaseTestUtils.deleteCoreDatabase() specification = FilterByShardType(TYPE) diff --git a/core/src/androidTest/java/com/emarsys/core/storage/AbstractStorageTest.kt b/core/src/androidTest/java/com/emarsys/core/storage/AbstractStorageTest.kt index d747a600c..601a14d7d 100644 --- a/core/src/androidTest/java/com/emarsys/core/storage/AbstractStorageTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/storage/AbstractStorageTest.kt @@ -1,20 +1,17 @@ package com.emarsys.core.storage import android.content.SharedPreferences +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ReflectionTestUtils import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.CALLS_REAL_METHODS import org.mockito.kotlin.mock import org.mockito.kotlin.times import org.mockito.kotlin.verify -class AbstractStorageTest { +class AbstractStorageTest : AnnotationSpec() { private companion object { const val VALUE = "value" } @@ -23,7 +20,7 @@ class AbstractStorageTest { private lateinit var mockStorage: AbstractStorage - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockSharedPreferences = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/storage/BooleanStorageTest.kt b/core/src/androidTest/java/com/emarsys/core/storage/BooleanStorageTest.kt index dfa167a73..c0674658e 100644 --- a/core/src/androidTest/java/com/emarsys/core/storage/BooleanStorageTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/storage/BooleanStorageTest.kt @@ -1,17 +1,16 @@ package com.emarsys.core.storage import android.content.SharedPreferences +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.anyBoolean import org.mockito.Mockito.anyString import org.mockito.Mockito.mock import org.mockito.Mockito.verify import org.mockito.Mockito.verifyNoMoreInteractions -class BooleanStorageTest { +class BooleanStorageTest : AnnotationSpec() { private companion object { const val VALUE = true @@ -24,7 +23,7 @@ class BooleanStorageTest { private lateinit var storageKey: StorageKey - @BeforeEach + @Before fun setUp() { storageKey = mock(StorageKey::class.java).apply { whenever(key).thenReturn(KEY) diff --git a/core/src/androidTest/java/com/emarsys/core/storage/CoreStorageKeyTest.kt b/core/src/androidTest/java/com/emarsys/core/storage/CoreStorageKeyTest.kt index 32fff1f9d..0ada85924 100644 --- a/core/src/androidTest/java/com/emarsys/core/storage/CoreStorageKeyTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/storage/CoreStorageKeyTest.kt @@ -1,13 +1,13 @@ package com.emarsys.core.storage +import com.emarsys.testUtil.AnnotationSpec import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Test -class CoreStorageKeyTest { +class CoreStorageKeyTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/storage/DefaultKeyValueStoreTest.kt b/core/src/androidTest/java/com/emarsys/core/storage/DefaultKeyValueStoreTest.kt index 2bfd8d945..66ff00290 100644 --- a/core/src/androidTest/java/com/emarsys/core/storage/DefaultKeyValueStoreTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/storage/DefaultKeyValueStoreTest.kt @@ -3,16 +3,14 @@ package com.emarsys.core.storage import android.annotation.SuppressLint import android.content.Context import android.content.SharedPreferences +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test +import org.junit.Assert -class DefaultKeyValueStoreTest { +class DefaultKeyValueStoreTest : AnnotationSpec() { companion object { private const val KEY = "key" private const val DELTA = 0.001 @@ -28,7 +26,7 @@ class DefaultKeyValueStoreTest { private lateinit var store: DefaultKeyValueStore private lateinit var prefs: SharedPreferences - @BeforeEach + @Before @SuppressLint("ApplySharedPref") fun init() { prefs = InstrumentationRegistry.getTargetContext() @@ -38,7 +36,7 @@ class DefaultKeyValueStoreTest { store = DefaultKeyValueStore(prefs) } - @AfterEach + @After fun tearDown() { prefs.edit().clear().commit() } @@ -170,13 +168,13 @@ class DefaultKeyValueStoreTest { fun test_put_get_float_shouldStoreValue() { store.putFloat(KEY, 2.4f) store - Assertions.assertEquals(2.4f, store.getFloat(KEY), DELTA.toFloat()) + Assert.assertEquals(2.4f, store.getFloat(KEY), DELTA.toFloat()) } @Test fun test_put_get_double_shouldStoreValue() { store.putDouble(KEY, 0.2) - Assertions.assertEquals(0.2, store.getDouble(KEY), DELTA) + Assert.assertEquals(0.2, store.getDouble(KEY), DELTA) } @Test @@ -187,11 +185,11 @@ class DefaultKeyValueStoreTest { store.putDouble(KEY4, java.lang.Double.POSITIVE_INFINITY) store.putDouble(KEY5, java.lang.Double.NEGATIVE_INFINITY) - Assertions.assertEquals(java.lang.Double.MAX_VALUE, store.getDouble(KEY1), DELTA) - Assertions.assertEquals(java.lang.Double.MIN_VALUE, store.getDouble(KEY2), DELTA) - Assertions.assertEquals(java.lang.Double.NaN, store.getDouble(KEY3), DELTA) - Assertions.assertEquals(java.lang.Double.POSITIVE_INFINITY, store.getDouble(KEY4), DELTA) - Assertions.assertEquals(java.lang.Double.NEGATIVE_INFINITY, store.getDouble(KEY5), DELTA) + Assert.assertEquals(java.lang.Double.MAX_VALUE, store.getDouble(KEY1), DELTA) + Assert.assertEquals(java.lang.Double.MIN_VALUE, store.getDouble(KEY2), DELTA) + Assert.assertEquals(java.lang.Double.NaN, store.getDouble(KEY3), DELTA) + Assert.assertEquals(java.lang.Double.POSITIVE_INFINITY, store.getDouble(KEY4), DELTA) + Assert.assertEquals(java.lang.Double.NEGATIVE_INFINITY, store.getDouble(KEY5), DELTA) } @Test @@ -212,10 +210,10 @@ class DefaultKeyValueStoreTest { store.getLong(KEY) shouldBe 88111 store.putFloat(KEY, 765.23f) - Assertions.assertEquals(765.23f, store.getFloat(KEY), DELTA.toFloat()) + Assert.assertEquals(765.23f, store.getFloat(KEY), DELTA.toFloat()) store.putDouble(KEY, 0.03013) - Assertions.assertEquals(0.03013, store.getDouble(KEY), DELTA) + Assert.assertEquals(0.03013, store.getDouble(KEY), DELTA) store.putBoolean(KEY, true) store.getBoolean(KEY) shouldBe true @@ -237,11 +235,11 @@ class DefaultKeyValueStoreTest { store.putFloat(KEY4, 44.2f) store.remove(KEY4) - Assertions.assertEquals(0.0f, store.getFloat(KEY4), DELTA.toFloat()) + Assert.assertEquals(0.0f, store.getFloat(KEY4), DELTA.toFloat()) store.putDouble(KEY5, 120120.0301) store.remove(KEY5) - Assertions.assertEquals(0.0, store.getDouble(KEY5), DELTA) + Assert.assertEquals(0.0, store.getDouble(KEY5), DELTA) store.putBoolean(KEY6, true) store.remove(KEY6) diff --git a/core/src/androidTest/java/com/emarsys/core/storage/SecureSharedPreferencesProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/storage/SecureSharedPreferencesProviderTest.kt index c0df4afc5..4dfc3af2e 100644 --- a/core/src/androidTest/java/com/emarsys/core/storage/SecureSharedPreferencesProviderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/storage/SecureSharedPreferencesProviderTest.kt @@ -3,15 +3,13 @@ package com.emarsys.core.storage import android.content.Context import android.content.Context.MODE_PRIVATE import android.content.SharedPreferences +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class SecureSharedPreferencesProviderTest { +class SecureSharedPreferencesProviderTest : AnnotationSpec() { private lateinit var sharedPreferencesProvider: SecureSharedPreferencesProvider @@ -19,7 +17,7 @@ class SecureSharedPreferencesProviderTest { private lateinit var context: Context private lateinit var oldSharedPrefs: SharedPreferences - @BeforeEach + @Before fun setUp() { context = InstrumentationRegistry.getTargetContext().applicationContext oldSharedPrefs = context.getSharedPreferences("test_shared_prefs", MODE_PRIVATE) diff --git a/core/src/androidTest/java/com/emarsys/core/storage/StringStorageTest.kt b/core/src/androidTest/java/com/emarsys/core/storage/StringStorageTest.kt index bcea4ae01..62d734ff8 100644 --- a/core/src/androidTest/java/com/emarsys/core/storage/StringStorageTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/storage/StringStorageTest.kt @@ -1,16 +1,15 @@ package com.emarsys.core.storage import android.content.SharedPreferences +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.anyString import org.mockito.Mockito.mock import org.mockito.Mockito.verify import org.mockito.Mockito.verifyNoMoreInteractions -class StringStorageTest { +class StringStorageTest : AnnotationSpec() { private companion object { const val VALUE = "value" @@ -23,7 +22,7 @@ class StringStorageTest { private lateinit var storageKey: StorageKey - @BeforeEach + @Before fun setUp() { storageKey = mock(StorageKey::class.java).apply { whenever(key).thenReturn(KEY) diff --git a/core/src/androidTest/java/com/emarsys/core/testUtil/RequestModelTestUtils.kt b/core/src/androidTest/java/com/emarsys/core/testUtil/RequestModelTestUtils.kt index b7ff18938..a78ac99f3 100644 --- a/core/src/androidTest/java/com/emarsys/core/testUtil/RequestModelTestUtils.kt +++ b/core/src/androidTest/java/com/emarsys/core/testUtil/RequestModelTestUtils.kt @@ -1,10 +1,10 @@ package com.emarsys.core.testUtil +import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestMethod +import com.emarsys.core.request.model.RequestMethod.GET import com.emarsys.core.request.model.RequestModel -import com.emarsys.core.provider.timestamp.TimestampProvider -import com.emarsys.core.request.model.RequestMethod.* import com.emarsys.testUtil.TestUrls object RequestModelTestUtils { diff --git a/core/src/androidTest/java/com/emarsys/core/util/AssertTest.kt b/core/src/androidTest/java/com/emarsys/core/util/AssertTest.kt index 81a90a6ae..b7ce25551 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/AssertTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/AssertTest.kt @@ -1,12 +1,12 @@ package com.emarsys.core.util +import com.emarsys.testUtil.AnnotationSpec +import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.fail -class AssertTest { +class AssertTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/DatabaseUtilTest.kt b/core/src/androidTest/java/com/emarsys/core/util/DatabaseUtilTest.kt index 2e49a8318..3b4de19ac 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/DatabaseUtilTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/DatabaseUtilTest.kt @@ -1,11 +1,11 @@ package com.emarsys.core.util +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class DatabaseUtilTest { +class DatabaseUtilTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/ExceptionExtensionsKtTest.kt b/core/src/androidTest/java/com/emarsys/core/util/ExceptionExtensionsKtTest.kt index b6ed282a9..800839afd 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/ExceptionExtensionsKtTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/ExceptionExtensionsKtTest.kt @@ -1,9 +1,9 @@ package com.emarsys.core.util +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class ExceptionExtensionsKtTest { +class ExceptionExtensionsKtTest : AnnotationSpec() { @Test fun testRootCause_shouldReturn_withTheRootCauseOfTheException() { diff --git a/core/src/androidTest/java/com/emarsys/core/util/FileDownloaderTest.kt b/core/src/androidTest/java/com/emarsys/core/util/FileDownloaderTest.kt index f4c0f85c6..74dd3b19e 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/FileDownloaderTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/FileDownloaderTest.kt @@ -3,59 +3,62 @@ package com.emarsys.core.util import android.content.Context import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.FileTestUtils import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext +import com.emarsys.testUtil.RetryUtils import com.emarsys.testUtil.TestUrls.LARGE_IMAGE import com.emarsys.testUtil.TestUrls.customResponse +import com.emarsys.testUtil.rules.RetryRule import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test -import org.junitpioneer.jupiter.RetryingTest - +import org.junit.Rule import java.io.ByteArrayOutputStream import java.io.File import java.io.FileInputStream import java.io.InputStream -import java.util.* +import java.util.Arrays +import java.util.UUID import java.util.concurrent.CountDownLatch -class FileDownloaderTest { +class FileDownloaderTest : AnnotationSpec() { + + @Rule + @JvmField + val retryRule: RetryRule = RetryUtils.retryRule private lateinit var context: Context private lateinit var fileDownloader: FileDownloader - @BeforeEach + @Before fun setUp() { context = getTargetContext() fileDownloader = FileDownloader(context) } @Test - @RetryingTest(3) + fun testDownload_shouldNotReturnNull_whenUrlIsCorrect() { fileDownloader.download(LARGE_IMAGE) shouldNotBe null } @Test - @RetryingTest(3) + fun testDownload_shouldReturnNull_whenSchemeIsNotHttps() { fileDownloader.download("little://cat") shouldBe null } @Test - @RetryingTest(3) + fun testDownload_shouldReturnNull_whenResourceDoesNotExist() { val result = fileDownloader.download(customResponse(404)) result shouldBe null } @Test - @RetryingTest(3) + fun testDownload_returnedPathShouldExist() { val filePath = fileDownloader.download(LARGE_IMAGE) val file = File(filePath!!) @@ -63,7 +66,7 @@ class FileDownloaderTest { } @Test - @RetryingTest(3) + fun testDownload_downloadedAndRemoteFileShouldBeTheSame() { val latch = CountDownLatch(1) val concurrentHandlerHolder: ConcurrentHandlerHolder = @@ -91,7 +94,7 @@ class FileDownloaderTest { } @Test - @RetryingTest(3) + fun testDelete_shouldDeleteTheFile() { val filePath = createTempFile() val file = File(filePath) @@ -108,7 +111,7 @@ class FileDownloaderTest { } @Test - @RetryingTest(3) + fun testWriteReadFileIntoString() { val cacheFolder = context.cacheDir val fileName = UUID.randomUUID().toString() @@ -119,7 +122,7 @@ class FileDownloaderTest { } @Test - @RetryingTest(3) + fun testReadURLIntoString() { fileDownloader.download(LARGE_IMAGE)?.let { val expected = fileDownloader.readFileIntoString(it) diff --git a/core/src/androidTest/java/com/emarsys/core/util/HeaderUtilsInstrumentationTest.kt b/core/src/androidTest/java/com/emarsys/core/util/HeaderUtilsInstrumentationTest.kt index 83867167a..16330e651 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/HeaderUtilsInstrumentationTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/HeaderUtilsInstrumentationTest.kt @@ -1,10 +1,10 @@ package com.emarsys.core.util +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class HeaderUtilsInstrumentationTest { +class HeaderUtilsInstrumentationTest : AnnotationSpec() { private val username = "user" @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt index e4036ef0a..575d50add 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt @@ -6,16 +6,15 @@ import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper import com.emarsys.core.provider.hardwareid.HardwareIdProvider import com.emarsys.core.provider.version.VersionProvider +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext +import com.emarsys.testUtil.RetryUtils import com.emarsys.testUtil.copyInputStreamToFile +import com.emarsys.testUtil.rules.RetryRule import io.kotest.matchers.comparables.shouldBeLessThan import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test -import org.junitpioneer.jupiter.RetryingTest - +import org.junit.Rule import org.mockito.Mockito import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer @@ -23,7 +22,11 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.io.File -class ImageUtilsTest { +class ImageUtilsTest : AnnotationSpec() { + + @Rule + @JvmField + val retryRule: RetryRule = RetryUtils.retryRule private companion object { const val IMAGE_URL = "https://emarsys.com" @@ -36,7 +39,7 @@ class ImageUtilsTest { private lateinit var mockVersionProvider: VersionProvider - @BeforeEach + @Before fun setup() { mockFileDownloader = mock { on { download(any(), any()) } doAnswer { @@ -79,13 +82,13 @@ class ImageUtilsTest { @Test - @RetryingTest(3) + fun testLoadOptimizedBitmap_returnsNull_whenImageUrlIsNull() { ImageUtils.loadOptimizedBitmap(mockFileDownloader, null, deviceInfo) shouldBe null } @Test - @RetryingTest(3) + fun testLoadOptimizedBitmap_withRemoteUrl_CleansUpTempFile() { clearCache() getTargetContext().cacheDir.list()?.size shouldBe 0 @@ -94,7 +97,7 @@ class ImageUtilsTest { } @Test - @RetryingTest(3) + fun testLoadOptimizedBitmap_withLocalFile_ShouldNotCleanUpLocalFile() { clearCache() val fileUrl = mockFileDownloader.download(IMAGE_URL) @@ -110,7 +113,7 @@ class ImageUtilsTest { } @Test - @RetryingTest(3) + fun testLoadOptimizedBitmap_withRemoteUrl() { val bitmap = ImageUtils.loadOptimizedBitmap(mockFileDownloader, IMAGE_URL, deviceInfo) bitmap shouldNotBe null @@ -119,7 +122,7 @@ class ImageUtilsTest { } @Test - @RetryingTest(3) + fun testCalculateInSampleSize_returnedValueShouldBe4_whenRequestedWidthIs1080_widthIs2500() { val options = BitmapFactory.Options().apply { outWidth = 2500 diff --git a/core/src/androidTest/java/com/emarsys/core/util/JsonUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/JsonUtilsTest.kt index 4f0e389e9..89afaeb33 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/JsonUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/JsonUtilsTest.kt @@ -1,22 +1,20 @@ package com.emarsys.core.util + import com.emarsys.core.util.JsonUtils.fromList import com.emarsys.core.util.JsonUtils.fromMap import com.emarsys.core.util.JsonUtils.merge import com.emarsys.core.util.JsonUtils.toFlatMap import com.emarsys.core.util.JsonUtils.toFlatMapIncludingNulls +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import org.json.JSONArray import org.json.JSONException import org.json.JSONObject - - -import org.junit.jupiter.api.Test - import java.util.* -class JsonUtilsTest { +class JsonUtilsTest : AnnotationSpec() { private companion object { const val KEY_1 = "key1" diff --git a/core/src/androidTest/java/com/emarsys/core/util/MapExtensionsKtTest.kt b/core/src/androidTest/java/com/emarsys/core/util/MapExtensionsKtTest.kt index afd700a53..1d4378225 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/MapExtensionsKtTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/MapExtensionsKtTest.kt @@ -1,13 +1,14 @@ package com.emarsys.core.util +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class MapExtensionsKtTest { +class MapExtensionsKtTest : AnnotationSpec() { @Test fun testGetCaseInsensitive() { - val map: Map = mapOf("KeY0" to "Value0", "KeY1" to "Value1", "key2" to "Value2") + val map: Map = + mapOf("KeY0" to "Value0", "KeY1" to "Value1", "key2" to "Value2") val result = map.getCaseInsensitive("key1") result shouldBe "Value1" diff --git a/core/src/androidTest/java/com/emarsys/core/util/RequestModelUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/RequestModelUtilsTest.kt index 1e01012b1..01da1fa30 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/RequestModelUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/RequestModelUtilsTest.kt @@ -3,13 +3,12 @@ package com.emarsys.core.util import com.emarsys.core.request.model.CompositeRequestModel import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test - -class RequestModelUtilsTest { +class RequestModelUtilsTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/SerializationUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/SerializationUtilsTest.kt index 0a2ccedea..eaa55f684 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/SerializationUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/SerializationUtilsTest.kt @@ -3,10 +3,10 @@ package com.emarsys.core.util import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.core.util.serialization.SerializationUtils +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class SerializationUtilsTest { +class SerializationUtilsTest : AnnotationSpec() { @Test fun testSerialization() { val payload = HashMap() diff --git a/core/src/androidTest/java/com/emarsys/core/util/SystemUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/SystemUtilsTest.kt index c821165d4..23cf413af 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/SystemUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/SystemUtilsTest.kt @@ -1,11 +1,10 @@ package com.emarsys.core.util +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test - -class SystemUtilsTest { +class SystemUtilsTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt index a64c41f86..f6bf4baf1 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt @@ -5,17 +5,16 @@ import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper import com.emarsys.core.provider.hardwareid.HardwareIdProvider import com.emarsys.core.provider.version.VersionProvider +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.text.SimpleDateFormat import java.util.TimeZone -class TimestampUtilsTest { +class TimestampUtilsTest : AnnotationSpec() { companion object { private const val HARDWARE_ID = "hwid" @@ -29,7 +28,7 @@ class TimestampUtilsTest { private lateinit var mockNotificationManagerHelper: NotificationManagerHelper - @BeforeEach + @Before fun setup() { mockHardwareIdProvider = mock { on { provideHardwareId() } doReturn HARDWARE_ID diff --git a/core/src/androidTest/java/com/emarsys/core/util/batch/BatchingShardTriggerTest.kt b/core/src/androidTest/java/com/emarsys/core/util/batch/BatchingShardTriggerTest.kt index 2ae5cde95..0d910483b 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/batch/BatchingShardTriggerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/batch/BatchingShardTriggerTest.kt @@ -11,10 +11,9 @@ import com.emarsys.core.shard.specification.FilterByShardIds import com.emarsys.core.util.batch.BatchingShardTrigger.RequestStrategy.PERSISTENT import com.emarsys.core.util.batch.BatchingShardTrigger.RequestStrategy.TRANSIENT import com.emarsys.core.util.predicate.Predicate +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.any import org.mockito.kotlin.doReturn @@ -24,7 +23,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -class BatchingShardTriggerTest { +class BatchingShardTriggerTest : AnnotationSpec() { private lateinit var mockRepository: Repository private lateinit var mockPredicate: Predicate> @@ -35,7 +34,7 @@ class BatchingShardTriggerTest { private lateinit var mockConnectionWatchDog: ConnectionWatchDog - @BeforeEach + @Before fun setUp() { mockRepository = mock() mockPredicate = mock { diff --git a/core/src/androidTest/java/com/emarsys/core/util/batch/ListChunkerTest.kt b/core/src/androidTest/java/com/emarsys/core/util/batch/ListChunkerTest.kt index df93fd3c9..55e4bb985 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/batch/ListChunkerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/batch/ListChunkerTest.kt @@ -1,21 +1,17 @@ package com.emarsys.core.util.batch import com.emarsys.core.shard.ShardModel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class ListChunkerTest { +class ListChunkerTest : AnnotationSpec() { private lateinit var chunker: ListChunker - @BeforeEach + @Before fun init() { chunker = ListChunker(1) } diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt index 03244051e..859e74cc4 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt @@ -6,20 +6,16 @@ import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.core.shard.ShardModel +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.RandomTestUtils import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class LogShardListMergerTest { +class LogShardListMergerTest : AnnotationSpec() { private companion object { const val ID = "id" @@ -36,7 +32,7 @@ class LogShardListMergerTest { private lateinit var deviceInfo: DeviceInfo - @BeforeEach + @Before fun setUp() { timestampProvider = mock() whenever(timestampProvider.provideTimestamp()).thenReturn(TIMESTAMP) diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/LoggerTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/LoggerTest.kt index 85423d670..f10b2764d 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/LoggerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/LoggerTest.kt @@ -14,12 +14,10 @@ import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.shard.ShardModel import com.emarsys.core.storage.StringStorage import com.emarsys.core.util.log.entry.LogEntry +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.ThreadSpy import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -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.kotlin.any import org.mockito.kotlin.capture @@ -33,7 +31,7 @@ import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class LoggerTest { +class LoggerTest : AnnotationSpec() { companion object { const val TIMESTAMP = 400L @@ -42,7 +40,6 @@ class LoggerTest { } - private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder private lateinit var shardRepositoryMock: Repository private lateinit var timestampProviderMock: TimestampProvider @@ -52,7 +49,7 @@ class LoggerTest { private lateinit var loggerMock: Logger private lateinit var mockLogLevelStorage: StringStorage - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun init() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() @@ -86,7 +83,7 @@ class LoggerTest { setupCoreComponent(dependencyContainer) } - @AfterEach + @After fun tearDown() { if (CoreComponent.isSetup()) { core().concurrentHandlerHolder.coreLooper.quitSafely() diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/AppEventLogTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/AppEventLogTest.kt index 299816e28..240cb47df 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/AppEventLogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/AppEventLogTest.kt @@ -1,11 +1,10 @@ package com.emarsys.core.util.log.entry +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test - -class AppEventLogTest { +class AppEventLogTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/CrashLogTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/CrashLogTest.kt index 20ac32198..ef7a1f7d8 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/CrashLogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/CrashLogTest.kt @@ -1,18 +1,16 @@ package com.emarsys.core.util.log.entry +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class CrashLogTest { +class CrashLogTest : AnnotationSpec() { private lateinit var crashLog: CrashLog private lateinit var exception: Exception - @BeforeEach + @Before fun init() { exception = ConcurrentModificationException("cause of the exception") crashLog = CrashLog(exception, "testInfo") diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/InAppLogTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/InAppLogTest.kt index 1f4e36cf1..45e10b4ba 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/InAppLogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/InAppLogTest.kt @@ -4,14 +4,12 @@ package com.emarsys.core.util.log.entry import com.emarsys.core.di.FakeCoreDependencyContainer import com.emarsys.core.di.setupCoreComponent import com.emarsys.core.provider.uuid.UUIDProvider +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class InAppLogTest { +class InAppLogTest : AnnotationSpec() { private companion object { const val endTime = 10L const val startTime = 5L diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/LogEntryKtTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/LogEntryKtTest.kt index b15a0e44b..abb24e69e 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/LogEntryKtTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/LogEntryKtTest.kt @@ -1,12 +1,12 @@ package com.emarsys.core.util.log.entry import com.emarsys.core.util.log.LogLevel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class LogEntryKtTest { +class LogEntryKtTest : AnnotationSpec() { @Test fun testToData() { diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/MethodNotAlllowedTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/MethodNotAlllowedTest.kt index eb2e6cae8..f4b1b6c7d 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/MethodNotAlllowedTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/MethodNotAlllowedTest.kt @@ -1,11 +1,10 @@ package com.emarsys.core.util.log.entry +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test - -class MethodNotAllowedTest { +class MethodNotAllowedTest : AnnotationSpec() { private companion object { const val testCallerMethodName = "testCallerMethodName" diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/OfflineQueueSizeTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/OfflineQueueSizeTest.kt index 81645479f..c14ed7f27 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/OfflineQueueSizeTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/OfflineQueueSizeTest.kt @@ -1,11 +1,10 @@ package com.emarsys.core.util.log.entry +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test - -class OfflineQueueSizeTest { +class OfflineQueueSizeTest : AnnotationSpec() { @Test diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/RequestLogTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/RequestLogTest.kt index 54f8429c1..5cbeeef6e 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/RequestLogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/RequestLogTest.kt @@ -2,17 +2,14 @@ package com.emarsys.core.util.log.entry import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import java.net.URL -class RequestLogTest { +class RequestLogTest : AnnotationSpec() { private companion object { const val TOPIC = "log_request" const val IN_DATABASE_TIME_END = 3L @@ -23,7 +20,7 @@ class RequestLogTest { private lateinit var requestLog: RequestLog - @BeforeEach + @Before fun setUp() { mockRequestModel = mock { on { url }.doReturn(URL("https://emarsys.com")) diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/entry/StatusLogTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/entry/StatusLogTest.kt index e91b53933..15c0a460c 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/entry/StatusLogTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/entry/StatusLogTest.kt @@ -1,11 +1,10 @@ package com.emarsys.core.util.log.entry +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test - -class StatusLogTest { +class StatusLogTest : AnnotationSpec() { private companion object { const val testCallerMethodName = "testCallerMethodName" val testParameters = mapOf( @@ -13,11 +12,11 @@ class StatusLogTest { "parameter2" to "value2" ) val testStatus = mapOf( - "key1" to "value1", - "key2" to mapOf( - "statusMapKey1" to "statusValue1", - "statusMapKey2" to "statusValue2" - ) + "key1" to "value1", + "key2" to mapOf( + "statusMapKey1" to "statusValue1", + "statusMapKey2" to "statusValue2" + ) ) } diff --git a/core/src/androidTest/java/com/emarsys/core/util/predicate/ListSizeAtLeastTest.kt b/core/src/androidTest/java/com/emarsys/core/util/predicate/ListSizeAtLeastTest.kt index 7d97114a8..873c1fedb 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/predicate/ListSizeAtLeastTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/predicate/ListSizeAtLeastTest.kt @@ -1,17 +1,15 @@ package com.emarsys.core.util.predicate +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class ListSizeAtLeastTest { +class ListSizeAtLeastTest : AnnotationSpec() { private lateinit var predicate: ListSizeAtLeast - @BeforeEach + @Before fun init() { predicate = ListSizeAtLeast(5) } diff --git a/core/src/androidTest/java/com/emarsys/core/validate/JsonObjectValidatorTest.kt b/core/src/androidTest/java/com/emarsys/core/validate/JsonObjectValidatorTest.kt index 12308bff5..2d2bb6eb4 100644 --- a/core/src/androidTest/java/com/emarsys/core/validate/JsonObjectValidatorTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/validate/JsonObjectValidatorTest.kt @@ -1,23 +1,19 @@ package com.emarsys.core.validate +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.matchers.types.shouldBeSameInstanceAs import org.json.JSONObject - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class JsonObjectValidatorTest { +class JsonObjectValidatorTest : AnnotationSpec() { lateinit var json: JSONObject - @BeforeEach + @Before fun init() { json = JSONObject() .put("key1", "value1") diff --git a/core/src/androidTest/java/com/emarsys/core/worker/CoreCompletionHandlerMiddlewareTest.kt b/core/src/androidTest/java/com/emarsys/core/worker/CoreCompletionHandlerMiddlewareTest.kt index 235716f27..18e6441b6 100644 --- a/core/src/androidTest/java/com/emarsys/core/worker/CoreCompletionHandlerMiddlewareTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/worker/CoreCompletionHandlerMiddlewareTest.kt @@ -14,12 +14,11 @@ import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.core.request.model.specification.FilterByRequestIds import com.emarsys.core.response.ResponseModel +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.ThreadSpy import io.kotest.matchers.ints.shouldBeLessThanOrEqual import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.ArgumentCaptor import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.capture @@ -33,7 +32,7 @@ import org.mockito.kotlin.verifyNoMoreInteractions import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class CoreCompletionHandlerMiddlewareTest { +class CoreCompletionHandlerMiddlewareTest : AnnotationSpec() { private lateinit var coreCompletionHandler: CoreCompletionHandler private lateinit var requestRepository: Repository private lateinit var mockWorker: Worker @@ -44,7 +43,7 @@ class CoreCompletionHandlerMiddlewareTest { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setup() { expectedId = "expectedId" mockWorker = mock() diff --git a/core/src/androidTest/java/com/emarsys/core/worker/DefaultWorkerTest.kt b/core/src/androidTest/java/com/emarsys/core/worker/DefaultWorkerTest.kt index e86b71356..61e82011d 100644 --- a/core/src/androidTest/java/com/emarsys/core/worker/DefaultWorkerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/worker/DefaultWorkerTest.kt @@ -13,11 +13,10 @@ import com.emarsys.core.request.factory.CompletionHandlerProxyProvider import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.core.testUtil.RequestModelTestUtils.createRequestModel +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.doNothing @@ -30,7 +29,7 @@ import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class DefaultWorkerTest { +class DefaultWorkerTest : AnnotationSpec() { companion object { const val URL = "https://www.google.com" } @@ -48,7 +47,7 @@ class DefaultWorkerTest { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setup() { deleteCoreDatabase() watchDogMock = mock() diff --git a/emarsys-e2e-test/build.gradle.kts b/emarsys-e2e-test/build.gradle.kts index 7182a6cfe..ec9889e7c 100644 --- a/emarsys-e2e-test/build.gradle.kts +++ b/emarsys-e2e-test/build.gradle.kts @@ -23,15 +23,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt b/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt index 1fa25f2e7..23403c7d7 100644 --- a/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt +++ b/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt @@ -1,5 +1,6 @@ package com.emarsys + import android.app.Application import android.location.Location import android.location.LocationManager @@ -11,26 +12,30 @@ import com.emarsys.di.emarsys import com.emarsys.mobileengage.api.geofence.Trigger import com.emarsys.mobileengage.api.geofence.TriggerType import com.emarsys.mobileengage.api.inbox.Message -import com.emarsys.testUtil.* -import com.emarsys.testUtil.rules.ConnectionExtension -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.AnnotationSpec +import com.emarsys.testUtil.E2ETestUtils +import com.emarsys.testUtil.InstrumentationRegistry +import com.emarsys.testUtil.ReflectionTestUtils +import com.emarsys.testUtil.RetryUtils +import com.emarsys.testUtil.rules.DuplicatedThreadRule +import com.emarsys.testUtil.rules.RetryRule import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Disabled - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.junit.jupiter.api.extension.RegisterExtension -import org.junitpioneer.jupiter.RetryingTest - +import org.junit.Rule import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import com.emarsys.mobileengage.api.geofence.Geofence as MEGeofence -@ExtendWith(DuplicatedThreadExtension::class) -class EmarsysE2ETests { +class EmarsysE2ETests : AnnotationSpec() { + + @Rule + @JvmField + val retryRule: RetryRule = RetryUtils.retryRule + + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") companion object { private const val OLD_APPLICATION_CODE = "14C19-A121F" @@ -44,17 +49,13 @@ class EmarsysE2ETests { private val application: Application get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @JvmField - @RegisterExtension - var connectionExtension: ConnectionExtension = ConnectionExtension(application) - - @AfterEach + @After fun tearDown() { E2ETestUtils.tearDownEmarsys(application) } @Test - @RetryingTest(3) + fun testChangeApplicationCode() { setup(OLD_APPLICATION_CODE) @@ -73,7 +74,7 @@ class EmarsysE2ETests { } @Test - @RetryingTest(3) + fun testChangeApplicationCodeFromNull() { setup(null) @@ -92,7 +93,7 @@ class EmarsysE2ETests { } @Test - @RetryingTest(3) + fun testChangeApplicationCodeToNull() { var disabled = true setup(APPLICATION_CODE) @@ -116,7 +117,7 @@ class EmarsysE2ETests { } @Test - @RetryingTest(3) + fun testInbox_addTag_removeTag() { setup(APPLICATION_CODE) @@ -160,8 +161,7 @@ class EmarsysE2ETests { } @Test - @Disabled("Test is too flaky to run on pipeline") - @RetryingTest(3) + @Ignore fun testGeofence() { setup(APPLICATION_CODE) RetryUtil.retry { diff --git a/emarsys-firebase/build.gradle.kts b/emarsys-firebase/build.gradle.kts index 04aa81ede..6fe6968be 100644 --- a/emarsys-firebase/build.gradle.kts +++ b/emarsys-firebase/build.gradle.kts @@ -25,15 +25,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt b/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt index 990f81de3..454f491d3 100644 --- a/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt +++ b/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt @@ -1,5 +1,6 @@ package com.emarsys.service + import android.app.Application import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.device.DeviceInfo @@ -9,12 +10,10 @@ import com.emarsys.fake.FakeFirebaseDependencyContainer import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.push.PushInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.ReflectionTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -24,8 +23,7 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify -class EmarsysFirebaseMessagingServiceTest { - +class EmarsysFirebaseMessagingServiceTest : AnnotationSpec() { private val application: Application @@ -37,7 +35,7 @@ class EmarsysFirebaseMessagingServiceTest { private lateinit var spyCoreHandler: SdkHandler private lateinit var emarsysFirebaseMessagingService: EmarsysFirebaseMessagingService - @BeforeEach + @Before fun setUp() { emarsysFirebaseMessagingService = EmarsysFirebaseMessagingService() mockPushInternal = mock() @@ -51,7 +49,7 @@ class EmarsysFirebaseMessagingServiceTest { ) } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() FeatureTestUtils.resetFeatures() diff --git a/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceUtilsTest.kt b/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceUtilsTest.kt index cbeb81ed8..9cbbbbe22 100644 --- a/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceUtilsTest.kt +++ b/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceUtilsTest.kt @@ -4,16 +4,15 @@ import android.content.Context import android.os.Bundle import com.emarsys.fake.FakeFirebaseDependencyContainer import com.emarsys.mobileengage.di.setupMobileEngageComponent +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import com.google.firebase.messaging.RemoteMessage import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class EmarsysFirebaseMessagingServiceUtilsTest { +class EmarsysFirebaseMessagingServiceUtilsTest : AnnotationSpec() { private lateinit var context: Context - @BeforeEach + @Before fun init() { context = InstrumentationRegistry.getTargetContext() setupMobileEngageComponent( diff --git a/emarsys-huawei/build.gradle.kts b/emarsys-huawei/build.gradle.kts index 42152171a..acbe2feb4 100644 --- a/emarsys-huawei/build.gradle.kts +++ b/emarsys-huawei/build.gradle.kts @@ -26,15 +26,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt b/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt index 337f1d54d..e6651b09d 100644 --- a/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt +++ b/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt @@ -1,5 +1,6 @@ package com.emarsys.service + import android.app.Application import android.os.Looper import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory @@ -10,12 +11,10 @@ import com.emarsys.fake.FakeHuaweiDependencyContainer import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.push.PushInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.ReflectionTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -24,7 +23,7 @@ import org.mockito.kotlin.timeout import org.mockito.kotlin.times import org.mockito.kotlin.verify -class EmarsysHuaweiMessagingServiceTest { +class EmarsysHuaweiMessagingServiceTest : AnnotationSpec() { private val application: Application @@ -36,7 +35,7 @@ class EmarsysHuaweiMessagingServiceTest { private lateinit var emarsysHuaweiMessagingService: EmarsysHuaweiMessagingService private lateinit var spyCoreHandler: SdkHandler - @BeforeEach + @Before fun setUp() { mockPushInternal = mock() @@ -53,7 +52,7 @@ class EmarsysHuaweiMessagingServiceTest { emarsysHuaweiMessagingService = EmarsysHuaweiMessagingService() } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() FeatureTestUtils.resetFeatures() diff --git a/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceUtilsTest.kt b/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceUtilsTest.kt index c6c32a605..145398509 100644 --- a/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceUtilsTest.kt +++ b/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceUtilsTest.kt @@ -4,16 +4,15 @@ import android.content.Context import android.os.Bundle import com.emarsys.fake.FakeHuaweiDependencyContainer import com.emarsys.mobileengage.di.setupMobileEngageComponent +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import com.huawei.hms.push.RemoteMessage import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class EmarsysHuaweiMessagingServiceUtilsTest { +class EmarsysHuaweiMessagingServiceUtilsTest : AnnotationSpec() { private lateinit var context: Context - @BeforeEach + @Before fun init() { context = InstrumentationRegistry.getTargetContext() setupMobileEngageComponent( diff --git a/emarsys-sdk/build.gradle.kts b/emarsys-sdk/build.gradle.kts index 59c15d511..607a8cbc0 100644 --- a/emarsys-sdk/build.gradle.kts +++ b/emarsys-sdk/build.gradle.kts @@ -29,15 +29,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt index 939683c30..8e4e11be8 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt @@ -1,5 +1,6 @@ package com.emarsys + import android.app.Application import com.emarsys.config.EmarsysConfig import com.emarsys.core.device.DeviceInfo @@ -9,26 +10,32 @@ import com.emarsys.core.provider.hardwareid.HardwareIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.di.DefaultEmarsysComponent import com.emarsys.di.DefaultEmarsysDependencies +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.IntegrationTestUtils +import com.emarsys.testUtil.KotestRunnerAndroid import com.emarsys.testUtil.mockito.whenever -import com.emarsys.testUtil.rules.ConnectionExtension -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.rules.ConnectionRule +import com.emarsys.testUtil.rules.DuplicatedThreadRule import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.junit.jupiter.api.extension.RegisterExtension +import org.junit.Rule +import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.any import org.mockito.Mockito.mock import java.util.concurrent.CountDownLatch -@ExtendWith(DuplicatedThreadExtension::class) -class DefaultInboxIntegrationTest { +@RunWith(KotestRunnerAndroid::class) +class DefaultInboxIntegrationTest : AnnotationSpec() { + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") + + @Rule + @JvmField + val connectionRule = ConnectionRule(application) companion object { private const val APP_ID = "14C19-A121F" @@ -45,11 +52,8 @@ class DefaultInboxIntegrationTest { private val application: Application get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @JvmField - @RegisterExtension - var connectionExtension: ConnectionExtension = ConnectionExtension(application) - @BeforeEach + @Before fun setup() { DatabaseTestUtils.deleteCoreDatabase() @@ -86,7 +90,7 @@ class DefaultInboxIntegrationTest { IntegrationTestUtils.doLogin(2575) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys(application) } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt index b43de131e..daa1d8c09 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt @@ -34,7 +34,11 @@ import com.emarsys.core.request.RequestManager import com.emarsys.core.response.ResponseHandlersProcessor import com.emarsys.core.storage.StringStorage import com.emarsys.deeplink.DeepLinkApi -import com.emarsys.di.* +import com.emarsys.di.DefaultEmarsysComponent +import com.emarsys.di.FakeDependencyContainer +import com.emarsys.di.emarsys +import com.emarsys.di.isEmarsysComponentSetup +import com.emarsys.di.setupEmarsysComponent import com.emarsys.eventservice.EventServiceApi import com.emarsys.inapp.InAppApi import com.emarsys.inbox.MessageInboxApi @@ -49,7 +53,14 @@ import com.emarsys.mobileengage.event.EventServiceInternal import com.emarsys.mobileengage.geofence.FetchGeofencesAction import com.emarsys.mobileengage.iam.AppStartAction import com.emarsys.mobileengage.iam.model.requestRepositoryProxy.RequestRepositoryProxy -import com.emarsys.mobileengage.responsehandler.* +import com.emarsys.mobileengage.responsehandler.ClientInfoResponseHandler +import com.emarsys.mobileengage.responsehandler.DeviceEventStateResponseHandler +import com.emarsys.mobileengage.responsehandler.InAppCleanUpResponseHandler +import com.emarsys.mobileengage.responsehandler.InAppCleanUpResponseHandlerV4 +import com.emarsys.mobileengage.responsehandler.InAppMessageResponseHandler +import com.emarsys.mobileengage.responsehandler.MobileEngageClientStateResponseHandler +import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler +import com.emarsys.mobileengage.responsehandler.OnEventActionResponseHandler import com.emarsys.predict.PredictApi import com.emarsys.predict.PredictRestrictedApi import com.emarsys.predict.api.model.Logic @@ -58,23 +69,40 @@ import com.emarsys.predict.api.model.RecommendationFilter import com.emarsys.predict.response.VisitorIdResponseHandler import com.emarsys.predict.response.XPResponseHandler import com.emarsys.push.PushApi +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.CollectionTestUtils.getElementByType import com.emarsys.testUtil.CollectionTestUtils.numberOfElementsIn import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.IntegrationTestUtils import com.emarsys.testUtil.ReflectionTestUtils.getInstanceField -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.rules.ConnectionRule +import com.emarsys.testUtil.rules.DuplicatedThreadRule import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.kotlin.* +import org.junit.Rule +import org.mockito.kotlin.any +import org.mockito.kotlin.argumentCaptor +import org.mockito.kotlin.inOrder +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.spy +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoInteractions +import org.mockito.kotlin.verifyNoMoreInteractions +import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -@ExtendWith(DuplicatedThreadExtension::class) -class EmarsysTest { +class EmarsysTest : AnnotationSpec() { + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") + + + @Rule + @JvmField + val connectionRule = ConnectionRule(getTargetContext().applicationContext as Application) + companion object { private const val APPLICATION_CODE = "EMS11-C3FD3" private const val CONTACT_FIELD_ID = 3 @@ -130,7 +158,7 @@ class EmarsysTest { private lateinit var latch: CountDownLatch private lateinit var predictResultListenerCallback: (Try>) -> Unit - @BeforeEach + @Before fun setUp() { application = spy(getTargetContext().applicationContext as Application) completionListener = mock() @@ -250,7 +278,7 @@ class EmarsysTest { latch = CountDownLatch(1) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/InAppTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/InAppTest.kt index 09acc3e8f..3cd797599 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/InAppTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/InAppTest.kt @@ -11,23 +11,21 @@ import com.emarsys.inapp.InApp import com.emarsys.mobileengage.api.event.EventHandler import com.emarsys.mobileengage.di.mobileEngage import com.emarsys.mobileengage.iam.InAppInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -class InAppTest { +class InAppTest : AnnotationSpec() { private lateinit var inApp: InApp private lateinit var mockInAppInternal: InAppInternal private val application: Application get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @BeforeEach + @Before fun setUp() { mockInAppInternal = mock() val dependencyContainer = FakeDependencyContainer(inAppInternal = mockInAppInternal) @@ -36,7 +34,7 @@ class InAppTest { inApp = InApp() } - @AfterEach + @After fun tearDown() { application.unregisterActivityLifecycleCallbacks( mobileEngage().activityLifecycleWatchdog) diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/InappNotificationIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/InappNotificationIntegrationTest.kt index 1c35abba6..fee127402 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/InappNotificationIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/InappNotificationIntegrationTest.kt @@ -1,5 +1,6 @@ package com.emarsys +import android.app.Activity import android.app.Application import android.content.Context import android.content.Intent @@ -7,6 +8,7 @@ import com.emarsys.config.EmarsysConfig import com.emarsys.core.activity.ActivityLifecycleActionRegistry import com.emarsys.core.activity.ActivityLifecycleWatchdog import com.emarsys.core.app.AppLifecycleObserver +import com.emarsys.core.provider.activity.CurrentActivityProvider import com.emarsys.core.util.FileDownloader import com.emarsys.di.DefaultEmarsysComponent import com.emarsys.di.DefaultEmarsysDependencies @@ -15,13 +17,11 @@ import com.emarsys.mobileengage.iam.OverlayInAppPresenter import com.emarsys.mobileengage.service.IntentUtils import com.emarsys.mobileengage.service.NotificationData import com.emarsys.mobileengage.service.NotificationOperation +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.eq import org.mockito.kotlin.mock @@ -29,7 +29,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class InappNotificationIntegrationTest { +class InappNotificationIntegrationTest : AnnotationSpec() { private companion object { const val APP_ID = "14C19-A121F" @@ -39,12 +39,13 @@ class InappNotificationIntegrationTest { private lateinit var completionListenerLatch: CountDownLatch private lateinit var baseConfig: EmarsysConfig private lateinit var mockInappPresenterOverlay: OverlayInAppPresenter + private lateinit var mockCurrentActivityProvider: CurrentActivityProvider private val application: Application get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @BeforeEach + @Before fun setup() { completionListenerLatch = CountDownLatch(1) @@ -75,12 +76,17 @@ class InappNotificationIntegrationTest { ).thenAnswer { completionListenerLatch.countDown() } + mockCurrentActivityProvider = mock() + val mockActivity = mock() + whenever(mockCurrentActivityProvider.get()).thenReturn(mockActivity) DefaultEmarsysDependencies(baseConfig, object : DefaultEmarsysComponent(baseConfig) { override val overlayInAppPresenter: OverlayInAppPresenter get() = mockInappPresenterOverlay override val activityLifecycleWatchdog: ActivityLifecycleWatchdog get() = mock() + override val currentActivityProvider: CurrentActivityProvider + get() = mockCurrentActivityProvider override val activityLifecycleActionRegistry: ActivityLifecycleActionRegistry get() = mock() override val appLifecycleObserver: AppLifecycleObserver @@ -96,7 +102,7 @@ class InappNotificationIntegrationTest { IntegrationTestUtils.doLogin() } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys(application) } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt index 3210ce421..11e8efb17 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt @@ -1,5 +1,6 @@ package com.emarsys + import android.app.Activity import android.app.Application import android.content.Context @@ -18,25 +19,31 @@ import com.emarsys.di.DefaultEmarsysComponent import com.emarsys.di.DefaultEmarsysDependencies import com.emarsys.di.emarsys import com.emarsys.mobileengage.push.PushTokenProvider -import com.emarsys.testUtil.* +import com.emarsys.testUtil.AnnotationSpec +import com.emarsys.testUtil.ConnectionTestUtils +import com.emarsys.testUtil.DatabaseTestUtils +import com.emarsys.testUtil.InstrumentationRegistry +import com.emarsys.testUtil.IntegrationTestUtils +import com.emarsys.testUtil.RetryUtils import com.emarsys.testUtil.mockito.whenever -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.rules.DuplicatedThreadRule +import com.emarsys.testUtil.rules.RetryRule import io.kotest.matchers.ints.shouldBeInRange import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe - -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.junitpioneer.jupiter.RetryingTest - +import org.junit.Rule import org.mockito.ArgumentMatchers import org.mockito.Mockito.mock import java.util.concurrent.CountDownLatch -@ExtendWith(DuplicatedThreadExtension::class) -class MobileEngageIntegrationTest { +class MobileEngageIntegrationTest : AnnotationSpec() { + @Rule + @JvmField + val retryRule: RetryRule = RetryUtils.retryRule + + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") private companion object { private const val APP_ID = "14C19-A121F" @@ -56,7 +63,8 @@ class MobileEngageIntegrationTest { private val application: Application get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @BeforeEach + + @Before fun setup() { DatabaseTestUtils.deleteCoreDatabase() @@ -118,7 +126,7 @@ class MobileEngageIntegrationTest { completionHandlerLatch = CountDownLatch(1) } - @AfterEach + @After fun tearDown() { try { IntegrationTestUtils.tearDownEmarsys(application) @@ -129,7 +137,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testSetContact() { Emarsys.setContact( CONTACT_FIELD_ID, @@ -139,7 +147,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testClearContact() { Emarsys.clearContact( this::eventuallyStoreResult @@ -147,7 +155,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testTrackCustomEvent_V3_noAttributes() { Emarsys.trackCustomEvent( "integrationTestCustomEvent", @@ -157,7 +165,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testTrackCustomEvent_V3_withAttributes() { Emarsys.trackCustomEvent( "integrationTestCustomEvent", @@ -167,7 +175,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testTrackInternalCustomEvent_V3_noAttributes() { val eventServiceInternal = emarsys().eventServiceInternal @@ -179,7 +187,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testTrackInternalCustomEvent_V3_withAttributes() { val eventServiceInternal = emarsys().eventServiceInternal @@ -191,7 +199,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testSetPushToken() { Emarsys.push.setPushToken( "integration_test_push_token", @@ -200,7 +208,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testRemovePushToken() { Emarsys.push.clearPushToken( this::eventuallyStoreResult @@ -208,7 +216,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testDeepLinkOpen() { Thread.sleep(1000) val activity = mock(Activity::class.java) @@ -229,7 +237,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testTrackDeviceInfo() { val clientServiceInternal = emarsys().clientServiceInternal @@ -238,7 +246,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testConfig_changeApplicationCode() { val originalApplicationCode = Emarsys.config.applicationCode Emarsys.config.changeApplicationCode(OTHER_APP_ID, this::eventuallyStoreResult) @@ -248,7 +256,7 @@ class MobileEngageIntegrationTest { } @Test - @RetryingTest(3) + fun testConfig_changeApplicationCode_nilToSomething() { val setupLatch = CountDownLatch(1) emarsys().concurrentHandlerHolder.coreHandler.post { diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt index 8ffdb5a09..b0afc03b7 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt @@ -14,29 +14,32 @@ import com.emarsys.core.storage.Storage import com.emarsys.di.DefaultEmarsysComponent import com.emarsys.di.DefaultEmarsysDependencies import com.emarsys.di.emarsys +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.IntegrationTestUtils +import com.emarsys.testUtil.RetryUtils import com.emarsys.testUtil.mockito.whenever -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.rules.DuplicatedThreadRule +import com.emarsys.testUtil.rules.RetryRule import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.junitpioneer.jupiter.RetryingTest - +import org.junit.Rule import org.mockito.ArgumentMatchers import org.mockito.Mockito import java.util.concurrent.CountDownLatch -@ExtendWith(DuplicatedThreadExtension::class) +class MobileEngageRefreshContactTokenIntegrationTest : AnnotationSpec() { -class MobileEngageRefreshContactTokenIntegrationTest { + @Rule + @JvmField + val retryRule: RetryRule = RetryUtils.retryRule + + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") companion object { private const val APP_ID = "14C19-A121F" @@ -52,7 +55,7 @@ class MobileEngageRefreshContactTokenIntegrationTest { private val application: Application get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @BeforeEach + @Before fun setup() { DatabaseTestUtils.deleteCoreDatabase() @@ -103,13 +106,13 @@ class MobileEngageRefreshContactTokenIntegrationTest { completionListenerLatch = CountDownLatch(1) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys(application) } @Test - @RetryingTest(3) + fun testRefreshContactToken_shouldUpdateContactToken_whenOutDated() { contactTokenStorage.remove() contactTokenStorage.set("tokenForIntegrationTest") diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt index 145fb2822..1f1b1af9f 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt @@ -21,31 +21,34 @@ import com.emarsys.predict.api.model.Product import com.emarsys.predict.api.model.RecommendationFilter import com.emarsys.predict.api.model.RecommendationLogic import com.emarsys.predict.util.CartItemUtils +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ConnectionTestUtils import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.IntegrationTestUtils import com.emarsys.testUtil.mockito.whenever -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.rules.ConnectionRule +import com.emarsys.testUtil.rules.DuplicatedThreadRule import io.kotest.matchers.comparables.shouldBeGreaterThan import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith - +import org.junit.Rule import org.mockito.ArgumentMatchers import org.mockito.Mockito.mock import java.net.URLDecoder import java.util.concurrent.CountDownLatch import kotlin.reflect.KMutableProperty0 -@ExtendWith(DuplicatedThreadExtension::class) -class PredictIntegrationTest { +class PredictIntegrationTest : AnnotationSpec() { + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") + + @Rule + @JvmField + val connectionRule = ConnectionRule(application) companion object { private const val CONTACT_FIELD_ID = 3 @@ -71,7 +74,7 @@ class PredictIntegrationTest { get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @BeforeEach + @Before fun setup() { DatabaseTestUtils.deleteCoreDatabase() @@ -96,7 +99,10 @@ class PredictIntegrationTest { completionHandler = object : DefaultCoreCompletionHandler(mutableMapOf()) { override fun onSuccess(id: String, responseModel: ResponseModel) { super.onSuccess(id, responseModel) - if (responseModel.isPredictRequest and this@PredictIntegrationTest.responseModelMatches(responseModel)) { + if (responseModel.isPredictRequest and this@PredictIntegrationTest.responseModelMatches( + responseModel + ) + ) { this@PredictIntegrationTest.responseModel = responseModel latch.countDown() } @@ -157,7 +163,7 @@ class PredictIntegrationTest { } } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys(application) } @@ -287,8 +293,10 @@ class PredictIntegrationTest { testTrackSearchTerm() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.search(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.search(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -300,8 +308,10 @@ class PredictIntegrationTest { PredictCartItem(ITEM2, 2.2, 20.0), PredictCartItem(ITEM3, 3.3, 30.0) ) - Emarsys.predict.recommendProducts(RecommendationLogic.cart(cartItems), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.cart(cartItems), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -311,8 +321,10 @@ class PredictIntegrationTest { testTrackCart() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.cart(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.cart(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -332,16 +344,20 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.related(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.related(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @Test fun testRecommendProducts_withoutRelated() { - Emarsys.predict.recommendProducts(RecommendationLogic.related(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)).eventuallyAssert { + Emarsys.predict.recommendProducts( + RecommendationLogic.related(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ).eventuallyAssert { triedRecommendedProducts.errorCause shouldBe null triedRecommendedProducts.result shouldNotBe null triedRecommendedProducts.result!!.size shouldBe 0 @@ -363,8 +379,10 @@ class PredictIntegrationTest { testTrackCategoryView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.category(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.category(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -384,8 +402,10 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.alsoBought(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.alsoBought(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -395,8 +415,10 @@ class PredictIntegrationTest { testTrackCategoryView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.popular(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.popular(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -406,8 +428,10 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.personal(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.personal(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -417,8 +441,10 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.personal(listOf("1", "2", "3")), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.personal(listOf("1", "2", "3")), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -428,8 +454,10 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.home(), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.home(), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -439,8 +467,10 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.home(listOf("1", "2", "3")), - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.home(listOf("1", "2", "3")), + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -450,8 +480,10 @@ class PredictIntegrationTest { testTrackItemView() latch = CountDownLatch(1) - Emarsys.predict.recommendProducts(RecommendationLogic.home(listOf("1", "2", "3")), "hu", - eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter)) + Emarsys.predict.recommendProducts( + RecommendationLogic.home(listOf("1", "2", "3")), "hu", + eventuallyStoreResultInProperty(this::triedRecommendedProducts.setter) + ) eventuallyAssertForTriedRecommendedProducts() } @@ -517,7 +549,8 @@ class PredictIntegrationTest { } private val ResponseModel.isPredictRequest - get() = this.requestModel.url.toString().startsWith("https://recommender.scarabresearch.com/merchants/$MERCHANT_ID?") + get() = this.requestModel.url.toString() + .startsWith("https://recommender.scarabresearch.com/merchants/$MERCHANT_ID?") private val ResponseModel.baseUrl get() = URLDecoder.decode(this.requestModel.url.toString(), "UTF-8") diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/PredictTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/PredictTest.kt index 48a592c91..951ed46e7 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/PredictTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/PredictTest.kt @@ -14,20 +14,18 @@ import com.emarsys.predict.api.model.CartItem import com.emarsys.predict.api.model.Logic import com.emarsys.predict.api.model.Product import com.emarsys.predict.api.model.RecommendationFilter +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.RandomTestUtils.randomNumberString import com.emarsys.testUtil.RandomTestUtils.randomString import com.emarsys.testUtil.mockito.anyNotNull import io.kotest.assertions.throwables.shouldThrow -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.eq import org.mockito.kotlin.isNull import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class PredictTest { +class PredictTest : AnnotationSpec() { companion object { const val AVAILABILITY_ZONE = "HU" } @@ -40,7 +38,7 @@ class PredictTest { private lateinit var resultListenerCallback: (Try>) -> Unit - @BeforeEach + @Before fun setUp() { mockPredictInternal = mock() resultListenerCallback = mock() @@ -56,7 +54,7 @@ class PredictTest { mockRecommendationFilters = listOf(mockRecommendationFilter) } - @AfterEach + @After fun tearDown() { try { val handler = emarsys().concurrentHandlerHolder diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/PushTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/PushTest.kt index 3721af343..c29b70cc6 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/PushTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/PushTest.kt @@ -7,14 +7,12 @@ import com.emarsys.mobileengage.api.event.EventHandler import com.emarsys.mobileengage.api.push.NotificationInformationListener import com.emarsys.mobileengage.push.PushInternal import com.emarsys.push.Push +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.mock -class PushTest { +class PushTest : AnnotationSpec() { private lateinit var mockPushInternal: PushInternal private lateinit var mockCompletionListener: CompletionListener private lateinit var mockEventHandler: EventHandler @@ -22,7 +20,7 @@ class PushTest { private lateinit var push: Push - @BeforeEach + @Before fun setUp() { mockPushInternal = mock() mockCompletionListener = mock() @@ -35,7 +33,7 @@ class PushTest { push = Push() } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/RemoteConfigIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/RemoteConfigIntegrationTest.kt index d168421b7..6c2fbe5b4 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/RemoteConfigIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/RemoteConfigIntegrationTest.kt @@ -4,18 +4,26 @@ package com.emarsys import android.app.Application import com.emarsys.config.EmarsysConfig import com.emarsys.di.emarsys -import com.emarsys.testUtil.* -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.AnnotationSpec +import com.emarsys.testUtil.ConnectionTestUtils +import com.emarsys.testUtil.DatabaseTestUtils +import com.emarsys.testUtil.InstrumentationRegistry +import com.emarsys.testUtil.IntegrationTestUtils +import com.emarsys.testUtil.rules.ConnectionRule +import com.emarsys.testUtil.rules.DuplicatedThreadRule import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith +import org.junit.Rule import java.util.concurrent.CountDownLatch -@ExtendWith(DuplicatedThreadExtension::class) -class RemoteConfigIntegrationTest { +class RemoteConfigIntegrationTest : AnnotationSpec() { + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") + + @Rule + @JvmField + val connectionRule = ConnectionRule(application) private companion object { private const val APP_ID = "EMS1F-17E15" @@ -28,7 +36,7 @@ class RemoteConfigIntegrationTest { get() = InstrumentationRegistry.getTargetContext().applicationContext as Application - @BeforeEach + @Before fun setup() { DatabaseTestUtils.deleteCoreDatabase() @@ -44,7 +52,7 @@ class RemoteConfigIntegrationTest { latch = CountDownLatch(1) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys(application) } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigLoaderTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigLoaderTest.kt index b4464e0f2..89559f323 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigLoaderTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigLoaderTest.kt @@ -2,16 +2,15 @@ package com.emarsys.config import android.app.Application import android.content.SharedPreferences +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class ConfigLoaderTest { +class ConfigLoaderTest : AnnotationSpec() { companion object { private const val SHARED_PREF_NAME = "testPrefName" const val APP_CODE = "testAppCode" @@ -24,7 +23,7 @@ class ConfigLoaderTest { private lateinit var mockSharedPreferences: SharedPreferences private lateinit var mockApplication : Application - @BeforeEach + @Before fun setUp() { mockSharedPreferences = mock() mockApplication = mock { diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt index aa64b3239..6ed8cca4f 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt @@ -1,25 +1,26 @@ package com.emarsys.config + import com.emarsys.core.api.notification.NotificationSettings import com.emarsys.core.api.result.CompletionListener import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils import com.emarsys.testUtil.mockito.whenever -import com.emarsys.testUtil.rules.DuplicatedThreadExtension +import com.emarsys.testUtil.rules.DuplicatedThreadRule import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith +import org.junit.Rule import org.mockito.Mockito.mock import org.mockito.Mockito.verify import org.mockito.kotlin.doReturn -@ExtendWith(DuplicatedThreadExtension::class) -class ConfigTest { +class ConfigTest : AnnotationSpec() { + @Rule + @JvmField + val duplicateThreadRule = DuplicatedThreadRule("CoreSDKHandlerThread") companion object { private const val CLIENT_HOST = "https://me-client.eservice.emarsys.net" @@ -30,7 +31,7 @@ class ConfigTest { lateinit var config: Config lateinit var mockConfigInternal: ConfigInternal - @BeforeEach + @Before fun setUp() { mockConfigInternal = mock(ConfigInternal::class.java) val mockClientServiceProvider: ServiceEndpointProvider = org.mockito.kotlin.mock { @@ -54,7 +55,7 @@ class ConfigTest { } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } @@ -76,7 +77,10 @@ class ConfigTest { config.changeApplicationCode("testApplicationCode", mockCompletionListener) - verify(mockConfigInternal).changeApplicationCode("testApplicationCode", mockCompletionListener) + verify(mockConfigInternal).changeApplicationCode( + "testApplicationCode", + mockCompletionListener + ) } @Test diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/config/EmarsysConfigTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/config/EmarsysConfigTest.kt index c47ed96b8..5d04b30ce 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/config/EmarsysConfigTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/config/EmarsysConfigTest.kt @@ -1,5 +1,6 @@ package com.emarsys.config + import android.app.Application import com.emarsys.common.feature.InnerFeature import com.emarsys.core.api.experimental.FlipperFeature @@ -7,18 +8,16 @@ import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent import com.emarsys.mobileengage.api.event.EventHandler +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.IntegrationTestUtils import io.kotest.assertions.fail import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class EmarsysConfigTest { +class EmarsysConfigTest : AnnotationSpec() { companion object { private const val APP_ID = "appID" private const val MERCHANT_ID = "MERCHANT_ID" @@ -36,7 +35,7 @@ class EmarsysConfigTest { private var automaticPushTokenSending = false - @BeforeEach + @Before fun setUp() { FeatureTestUtils.resetFeatures() val mockClientServiceProvider: ServiceEndpointProvider = mock { @@ -67,7 +66,7 @@ class EmarsysConfigTest { ) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys(application) } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/deeplink/DeepLinkTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/deeplink/DeepLinkTest.kt index 812f80f45..23496b188 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/deeplink/DeepLinkTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/deeplink/DeepLinkTest.kt @@ -1,26 +1,25 @@ package com.emarsys.deeplink + import android.app.Activity import android.content.Intent import com.emarsys.core.api.result.CompletionListener import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent import com.emarsys.mobileengage.deeplink.DeepLinkInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class DeepLinkTest { +class DeepLinkTest : AnnotationSpec() { private lateinit var mockActivity: Activity private lateinit var mockCompletionListener: CompletionListener private lateinit var mockDeepLinkInternal: DeepLinkInternal private lateinit var deeplinkApi: DeepLink - @BeforeEach + @Before fun setUp() { mockActivity = mock() mockCompletionListener = mock() @@ -31,7 +30,7 @@ class DeepLinkTest { deepLinkInternal = mockDeepLinkInternal)) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/di/EmarsysDependencyInjectionTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/di/EmarsysDependencyInjectionTest.kt index dcdb751a4..a2cf3c6aa 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/di/EmarsysDependencyInjectionTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/di/EmarsysDependencyInjectionTest.kt @@ -1,15 +1,14 @@ package com.emarsys.di import com.emarsys.geofence.Geofence +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock -class EmarsysDependencyInjectionTest { +class EmarsysDependencyInjectionTest : AnnotationSpec() { - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/eventservice/EventServiceTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/eventservice/EventServiceTest.kt index 30100bd73..91a2dd216 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/eventservice/EventServiceTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/eventservice/EventServiceTest.kt @@ -1,17 +1,16 @@ package com.emarsys.eventservice + import com.emarsys.core.api.result.CompletionListener import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent import com.emarsys.mobileengage.event.EventServiceInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class EventServiceTest { +class EventServiceTest : AnnotationSpec() { companion object { private const val EVENT_NAME = "testEventName" private val EVENT_ATTRIBUTES = mapOf( @@ -25,7 +24,7 @@ class EventServiceTest { private lateinit var eventServiceApi: EventServiceApi - @BeforeEach + @Before fun setUp() { mockCompletionListener = mock() mockEventServiceInternal = mock() @@ -34,7 +33,7 @@ class EventServiceTest { setupEmarsysComponent(FakeDependencyContainer(eventServiceInternal = mockEventServiceInternal)) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/geofence/GeofenceTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/geofence/GeofenceTest.kt index aecf297a5..9179b1d55 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/geofence/GeofenceTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/geofence/GeofenceTest.kt @@ -1,25 +1,24 @@ package com.emarsys.geofence + import com.emarsys.core.api.result.CompletionListener import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent import com.emarsys.mobileengage.api.event.EventHandler import com.emarsys.mobileengage.geofence.GeofenceInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class GeofenceTest { +class GeofenceTest : AnnotationSpec() { private lateinit var geofenceProxy: GeofenceApi private lateinit var mockGeofenceInternal: GeofenceInternal - @BeforeEach + @Before fun setUp() { mockGeofenceInternal = mock() val dependencyContainer = FakeDependencyContainer(geofenceInternal = mockGeofenceInternal) @@ -29,7 +28,7 @@ class GeofenceTest { geofenceProxy = Geofence() } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/inapp/ui/InlineInAppViewTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/inapp/ui/InlineInAppViewTest.kt index 0cc7203cf..51329d0d2 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/inapp/ui/InlineInAppViewTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/inapp/ui/InlineInAppViewTest.kt @@ -1,5 +1,6 @@ package com.emarsys.inapp.ui + import androidx.test.core.app.ActivityScenario import com.emarsys.core.CoreCompletionHandler import com.emarsys.core.api.ResponseErrorException @@ -20,15 +21,13 @@ import com.emarsys.mobileengage.iam.model.InAppMetaData import com.emarsys.mobileengage.iam.webview.IamWebView import com.emarsys.mobileengage.iam.webview.IamWebViewFactory import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ExtensionTestUtils.runOnMain import com.emarsys.testUtil.IntegrationTestUtils import com.emarsys.testUtil.fake.FakeActivity import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.spy import org.mockito.kotlin.any import org.mockito.kotlin.doReturn @@ -39,7 +38,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class InlineInAppViewTest { +class InlineInAppViewTest : AnnotationSpec() { private companion object { const val VIEW_ID = "testViewId" const val OTHER_VIEW_ID = "testViewId2" @@ -60,7 +59,7 @@ class InlineInAppViewTest { private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() @@ -106,7 +105,7 @@ class InlineInAppViewTest { runOnMain {} } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() scenario.close() diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/inbox/MessageInboxTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/inbox/MessageInboxTest.kt index ebe2479ad..a2a28e3aa 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/inbox/MessageInboxTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/inbox/MessageInboxTest.kt @@ -1,5 +1,6 @@ package com.emarsys.inbox + import com.emarsys.core.api.result.CompletionListener import com.emarsys.core.api.result.ResultListener import com.emarsys.core.api.result.Try @@ -7,16 +8,14 @@ import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent import com.emarsys.mobileengage.api.inbox.InboxResult import com.emarsys.mobileengage.inbox.MessageInboxInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class MessageInboxTest { +class MessageInboxTest : AnnotationSpec() { private companion object { private const val TAG = "READ" private const val MESSAGE_ID = Integer.MAX_VALUE.toString() @@ -25,7 +24,7 @@ class MessageInboxTest { private lateinit var inbox: MessageInboxApi private lateinit var mockInboxInternal: MessageInboxInternal - @BeforeEach + @Before fun setUp() { mockInboxInternal = mock() val dependencyContainer = FakeDependencyContainer(messageInboxInternal = mockInboxInternal) @@ -34,7 +33,7 @@ class MessageInboxTest { inbox = MessageInbox() } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/MobileEngageTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/MobileEngageTest.kt index 59083bc3b..d540c263d 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/MobileEngageTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/MobileEngageTest.kt @@ -1,27 +1,27 @@ package com.emarsys.mobileengage + import com.emarsys.core.api.result.CompletionListener import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class MobileEngageTest { +class MobileEngageTest : AnnotationSpec() { companion object { private const val CONTACT_FIELD_ID = 999 private const val CONTACT_FIELD_VALUE = "testContactFieldValue" private const val CONTACT_ID_TOKEN = "idTOKENTOKENTOKENidTOKEN" } + private lateinit var mockMobileEngageInternal: MobileEngageInternal private lateinit var mockCompletionListener: CompletionListener private lateinit var mobileEngageApi: MobileEngage - @BeforeEach + @Before fun setUp() { mockMobileEngageInternal = mock() mockCompletionListener = mock() @@ -30,7 +30,7 @@ class MobileEngageTest { setupEmarsysComponent(FakeDependencyContainer(mobileEngageInternal = mockMobileEngageInternal)) } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperFactoryTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperFactoryTest.kt index 12b90045e..290a1a25b 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperFactoryTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperFactoryTest.kt @@ -3,20 +3,19 @@ package com.emarsys.mobileengage.service.mapper import android.content.Context import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.resource.MetaDataReader +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock -class RemoteMessageMapperFactoryTest { +class RemoteMessageMapperFactoryTest : AnnotationSpec() { private lateinit var mockMetaDataReader: MetaDataReader private lateinit var context: Context private lateinit var mockUuidProvider: UUIDProvider private lateinit var remoteMessageMapperFactory: RemoteMessageMapperFactory - @BeforeEach + @Before fun init() { mockMetaDataReader = mock() context = InstrumentationRegistry.getTargetContext() diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/oneventaction/OnEventActionTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/oneventaction/OnEventActionTest.kt index d1e0f22ad..5eb606c57 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/oneventaction/OnEventActionTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/oneventaction/OnEventActionTest.kt @@ -1,27 +1,26 @@ package com.emarsys.oneventaction + import android.content.Context import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.setupEmarsysComponent import com.emarsys.mobileengage.api.event.EventHandler import com.emarsys.mobileengage.event.CacheableEventHandler +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.IntegrationTestUtils import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class OnEventActionTest { +class OnEventActionTest : AnnotationSpec() { private lateinit var mockEventHandler: EventHandler private lateinit var onEventAction: OnEventAction private lateinit var mockOnEventActionCacheableEventHandler: CacheableEventHandler - @BeforeEach + @Before fun setUp() { mockEventHandler = mock() mockOnEventActionCacheableEventHandler = mock() @@ -33,7 +32,7 @@ class OnEventActionTest { onEventAction = OnEventAction() } - @AfterEach + @After fun tearDown() { IntegrationTestUtils.tearDownEmarsys() } diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt index c8a7dec12..db42a4aeb 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt @@ -5,13 +5,13 @@ import com.emarsys.di.FakeDependencyContainer import com.emarsys.di.emarsys import com.emarsys.di.setupEmarsysComponent import com.emarsys.di.tearDownEmarsysComponent -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.Mockito import org.mockito.kotlin.mock -class PredictRestrictedTest { +class PredictRestrictedTest : AnnotationSpec() { private companion object { const val CONTACT_FIELD_ID = 999 } @@ -20,7 +20,7 @@ class PredictRestrictedTest { private lateinit var predictRestricted: PredictRestricted - @BeforeEach + @Before fun setUp() { mockPredictInternal = mock() @@ -30,7 +30,7 @@ class PredictRestrictedTest { predictRestricted = PredictRestricted() } - @AfterEach + @After fun tearDown() { try { emarsys().concurrentHandlerHolder.coreLooper.quit() diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt index fc638539b..61f29906f 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt @@ -5,14 +5,13 @@ import android.database.Cursor import android.net.Uri import com.emarsys.core.database.CoreSQLiteDatabase import com.emarsys.core.database.helper.CoreDbHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ReflectionTestUtils import io.kotest.matchers.shouldBe import io.mockk.every import io.mockk.mockk -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -class SharedHardwareIdentificationContentProviderTest { +class SharedHardwareIdentificationContentProviderTest : AnnotationSpec() { private companion object { const val ENCRYPTED_HARDWARE_ID = "encrypted_hardware_id" @@ -25,7 +24,7 @@ class SharedHardwareIdentificationContentProviderTest { private lateinit var mockCursor: Cursor private lateinit var provider: SharedHardwareIdentificationContentProvider - @BeforeEach + @Before fun setUp() { mockCursor = mockk { every { getString(0) } returns ENCRYPTED_HARDWARE_ID diff --git a/emarsys/build.gradle.kts b/emarsys/build.gradle.kts index 11d1e7f0c..0ff6eec13 100644 --- a/emarsys/build.gradle.kts +++ b/emarsys/build.gradle.kts @@ -27,15 +27,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt b/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt index 8cd34c7cb..86c012a12 100644 --- a/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt @@ -6,15 +6,13 @@ import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.mobileengage.MobileEngageRequestContext -import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec +import io.kotest.matchers.shouldBe import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class EmarsysRequestModelFactoryTest { +class EmarsysRequestModelFactoryTest : AnnotationSpec() { companion object { const val HARDWARE_ID = "hardware_id" @@ -30,7 +28,7 @@ class EmarsysRequestModelFactoryTest { private lateinit var mockMobileEngageRequestContext: MobileEngageRequestContext - @BeforeEach + @Before fun setUp() { mockTimeStampProvider = mock { on { provideTimestamp() } doReturn TIMESTAMP diff --git a/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt b/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt index 09a0af14d..10a1ea61c 100644 --- a/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt @@ -1,5 +1,6 @@ package com.emarsys.config + import com.emarsys.EmarsysRequestModelFactory import com.emarsys.common.feature.InnerFeature import com.emarsys.config.model.RemoteConfig @@ -33,13 +34,11 @@ import com.emarsys.mobileengage.client.ClientServiceInternal import com.emarsys.mobileengage.push.PushInternal import com.emarsys.predict.PredictInternal import com.emarsys.predict.request.PredictRequestContext +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ExtensionTestUtils.tryCast import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.mockito.ThreadSpy import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doAnswer @@ -56,7 +55,7 @@ import org.mockito.kotlin.verifyNoMoreInteractions import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class DefaultConfigInternalTest { +class DefaultConfigInternalTest : AnnotationSpec() { private companion object { const val APPLICATION_CODE = "applicationCode" const val MERCHANT_ID = "merchantId" @@ -98,7 +97,7 @@ class DefaultConfigInternalTest { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { FeatureTestUtils.resetFeatures() @@ -187,7 +186,7 @@ class DefaultConfigInternalTest { ) } - @AfterEach + @After fun tearDown() { FeatureTestUtils.resetFeatures() } diff --git a/emarsys/src/androidTest/java/com/emarsys/config/FetchRemoteConfigActionTest.kt b/emarsys/src/androidTest/java/com/emarsys/config/FetchRemoteConfigActionTest.kt index ebd3be39a..8c670a36b 100644 --- a/emarsys/src/androidTest/java/com/emarsys/config/FetchRemoteConfigActionTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/config/FetchRemoteConfigActionTest.kt @@ -4,23 +4,23 @@ import com.emarsys.core.api.result.CompletionListener import com.emarsys.fake.FakeEmarsysDependencyContainer import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.Mockito.verify import org.mockito.kotlin.mock import org.mockito.kotlin.timeout import org.mockito.kotlin.times import org.mockito.kotlin.whenever -class FetchRemoteConfigActionTest { +class FetchRemoteConfigActionTest : AnnotationSpec() { private lateinit var fetchAction: FetchRemoteConfigAction private lateinit var mockConfigInternal: ConfigInternal private lateinit var mockCompletionListener: CompletionListener - @BeforeEach + @Before fun setup() { mockConfigInternal = mock() mockCompletionListener = mock() @@ -31,7 +31,7 @@ class FetchRemoteConfigActionTest { FetchRemoteConfigAction(mockConfigInternal, completionListener = mockCompletionListener) } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() } diff --git a/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt b/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt index cfd3ca502..057e9192a 100644 --- a/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt @@ -1,22 +1,20 @@ package com.emarsys.config + import com.emarsys.common.feature.InnerFeature import com.emarsys.config.model.RemoteConfig import com.emarsys.core.provider.hardwareid.HardwareIdProvider import com.emarsys.core.provider.random.RandomProvider import com.emarsys.core.response.ResponseModel import com.emarsys.core.util.log.LogLevel +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class RemoteConfigResponseMapperTest { +class RemoteConfigResponseMapperTest : AnnotationSpec() { private lateinit var mockResponseModel: ResponseModel @@ -25,7 +23,7 @@ class RemoteConfigResponseMapperTest { private lateinit var remoteConfigResponseMapper: RemoteConfigResponseMapper - @BeforeEach + @Before fun setup() { mockResponseModel = mock(ResponseModel::class.java) mockRandomProvider = mock(RandomProvider::class.java) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 14463451d..b392166ac 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -104,6 +104,7 @@ androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx io-coil = { module = "io.coil-kt:coil-compose", version.ref = "io-coil" } io-coil-compose = { module = "io.coil-kt:coil", version.ref = "io-coil" } junit = { group = "junit", name = "junit", version.ref = "junit" } +kotest-runner-junit4 = { module = "io.kotest:kotest-runner-junit4", version.ref = "kotest" } kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } mockk-android = { module = "io.mockk:mockk-android", version.ref = "mockk" } diff --git a/mobile-engage-api/build.gradle.kts b/mobile-engage-api/build.gradle.kts index e094252db..5438e8614 100644 --- a/mobile-engage-api/build.gradle.kts +++ b/mobile-engage-api/build.gradle.kts @@ -23,15 +23,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/mobile-engage-api/src/androidTest/java/com/emarsys/mobileengage/api/MEApiTest.kt b/mobile-engage-api/src/androidTest/java/com/emarsys/mobileengage/api/MEApiTest.kt index c5f18a4bd..7a340f3b1 100644 --- a/mobile-engage-api/src/androidTest/java/com/emarsys/mobileengage/api/MEApiTest.kt +++ b/mobile-engage-api/src/androidTest/java/com/emarsys/mobileengage/api/MEApiTest.kt @@ -1,10 +1,10 @@ package com.emarsys.mobileengage.api -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec -class MEApiTest { +class MEApiTest : AnnotationSpec() { @Test diff --git a/mobile-engage/build.gradle.kts b/mobile-engage/build.gradle.kts index fde89e990..7602e2577 100644 --- a/mobile-engage/build.gradle.kts +++ b/mobile-engage/build.gradle.kts @@ -27,8 +27,6 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true @@ -36,7 +34,15 @@ android { packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt index 914b156a8..c7df9451b 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt @@ -12,8 +12,8 @@ import com.emarsys.mobileengage.push.PushInternal import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory import com.emarsys.mobileengage.session.MobileEngageSession import com.emarsys.mobileengage.session.SessionIdHolder -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.eq @@ -29,7 +29,7 @@ import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit -class DefaultMobileEngageInternalTest { +class DefaultMobileEngageInternalTest : AnnotationSpec() { private companion object { const val CONTACT_FIELD_ID = 999 @@ -75,7 +75,7 @@ class DefaultMobileEngageInternalTest { private lateinit var mockSessionIdHolder: SessionIdHolder - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockEventServiceInternal = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/MobileEngageRequestContextTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/MobileEngageRequestContextTest.kt index 9ec37f054..c8dc72410 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/MobileEngageRequestContextTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/MobileEngageRequestContextTest.kt @@ -1,15 +1,14 @@ package com.emarsys.mobileengage +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock -class MobileEngageRequestContextTest { +class MobileEngageRequestContextTest : AnnotationSpec() { private lateinit var requestContext: MobileEngageRequestContext - @BeforeEach + @Before fun setUp() { requestContext = MobileEngageRequestContext( diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/client/DefaultClientServiceInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/client/DefaultClientServiceInternalTest.kt index 9f4821780..f12933f2c 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/client/DefaultClientServiceInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/client/DefaultClientServiceInternalTest.kt @@ -1,17 +1,15 @@ package com.emarsys.mobileengage.client + import com.emarsys.core.request.RequestManager import com.emarsys.core.request.model.RequestModel import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito import org.mockito.Mockito.verify -class DefaultClientServiceInternalTest { +class DefaultClientServiceInternalTest : AnnotationSpec() { private lateinit var mockRequestModelFactory: MobileEngageRequestModelFactory private lateinit var mockRequestModel: RequestModel @@ -19,7 +17,7 @@ class DefaultClientServiceInternalTest { private lateinit var clientServiceInternal: ClientServiceInternal - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockRequestModel = Mockito.mock(RequestModel::class.java) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DeepLinkActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DeepLinkActionTest.kt index a82e9d40c..f3abf13ba 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DeepLinkActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DeepLinkActionTest.kt @@ -6,16 +6,16 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.util.waitForTask -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.Mockito import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever -class DeepLinkActionTest { +class DeepLinkActionTest : AnnotationSpec() { companion object { init { Mockito.mock(Intent::class.java) @@ -27,7 +27,7 @@ class DeepLinkActionTest { private lateinit var action: DeepLinkAction - @BeforeEach + @Before fun setUp() { setupMobileEngageComponent(FakeMobileEngageDependencyContainer()) @@ -36,7 +36,7 @@ class DeepLinkActionTest { action = DeepLinkAction(deepLinkInternal) } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DefaultDeepLinkInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DefaultDeepLinkInternalTest.kt index 444f78d5c..f2057aa51 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DefaultDeepLinkInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/deeplink/DefaultDeepLinkInternalTest.kt @@ -14,9 +14,8 @@ import com.emarsys.core.request.model.RequestModel import com.emarsys.core.storage.StringStorage import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.session.SessionIdHolder +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito import org.mockito.Mockito.mock @@ -27,7 +26,7 @@ import org.mockito.kotlin.isNull import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -class DefaultDeepLinkInternalTest { +class DefaultDeepLinkInternalTest : AnnotationSpec() { private lateinit var mockActivity: Activity private lateinit var deepLinkInternal: DeepLinkInternal private lateinit var mockManager: RequestManager @@ -37,7 +36,7 @@ class DefaultDeepLinkInternalTest { private lateinit var mockDeviceInfo: DeviceInfo private lateinit var mockDeepLinkServiceProvider: ServiceEndpointProvider - @BeforeEach + @Before fun init() { mockActivity = mock(Activity::class.java, Mockito.RETURNS_DEEP_STUBS) mockManager = mock(RequestManager::class.java) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/device/DeviceInfoStartActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/device/DeviceInfoStartActionTest.kt index 607d8eb40..88b4c545a 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/device/DeviceInfoStartActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/device/DeviceInfoStartActionTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.device + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.storage.Storage import com.emarsys.mobileengage.client.ClientServiceInternal @@ -7,16 +8,14 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.util.waitForTask +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.SharedPrefsUtils import com.emarsys.testUtil.mockito.whenever -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions -class DeviceInfoStartActionTest { +class DeviceInfoStartActionTest : AnnotationSpec() { private lateinit var deviceInfoPayloadStorage: Storage private lateinit var mockClientServiceInternal: ClientServiceInternal @@ -24,7 +23,7 @@ class DeviceInfoStartActionTest { private lateinit var mockDeviceInfo: DeviceInfo - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { deviceInfoPayloadStorage = mock() @@ -41,7 +40,7 @@ class DeviceInfoStartActionTest { } - @AfterEach + @After fun tearDown() { SharedPrefsUtils.clearSharedPrefs("emarsys_secure_shared_preferences") tearDownMobileEngageComponent() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/CacheableEventHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/CacheableEventHandlerTest.kt index 5916e9ab0..a72f70947 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/CacheableEventHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/CacheableEventHandlerTest.kt @@ -3,21 +3,20 @@ package com.emarsys.mobileengage.event import android.content.Context import com.emarsys.common.feature.InnerFeature import com.emarsys.core.feature.FeatureRegistry +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.FeatureTestUtils import com.emarsys.testUtil.ReflectionTestUtils import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock -internal class CacheableEventHandlerTest { +internal class CacheableEventHandlerTest : AnnotationSpec() { private lateinit var cacheableEventHandler: CacheableEventHandler - @BeforeEach + @Before fun setUp() { FeatureTestUtils.resetFeatures() cacheableEventHandler = CacheableEventHandler() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/DefaultEventServiceInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/DefaultEventServiceInternalTest.kt index e985c79a9..680623211 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/DefaultEventServiceInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/event/DefaultEventServiceInternalTest.kt @@ -1,19 +1,17 @@ package com.emarsys.mobileengage.event + import com.emarsys.core.api.result.CompletionListener import com.emarsys.core.request.RequestManager import com.emarsys.core.request.model.RequestModel import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock import org.mockito.Mockito.verify import org.mockito.kotlin.spy -class DefaultEventServiceInternalTest { +class DefaultEventServiceInternalTest : AnnotationSpec() { companion object { const val REQUEST_ID = "request_id" @@ -31,7 +29,7 @@ class DefaultEventServiceInternalTest { private lateinit var eventServiceInternal: EventServiceInternal - @BeforeEach + @Before fun setUp() { mockRequestModel = mock(RequestModel::class.java) mockRequestManager = mock(RequestManager::class.java) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt index b38b0b72e..7f695c88d 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt @@ -26,6 +26,7 @@ import com.emarsys.mobileengage.geofence.model.GeofenceResponse import com.emarsys.mobileengage.geofence.model.TriggeringEmarsysGeofence import com.emarsys.mobileengage.notification.ActionCommandFactory import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ReflectionTestUtils import com.emarsys.testUtil.mockito.whenever import com.google.android.gms.location.FusedLocationProviderClient @@ -36,8 +37,6 @@ import com.google.android.gms.tasks.OnCompleteListener import com.google.android.gms.tasks.Task import io.kotest.matchers.shouldBe import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.spy import org.mockito.kotlin.any import org.mockito.kotlin.argumentCaptor @@ -50,7 +49,7 @@ import org.mockito.kotlin.verifyNoInteractions import java.util.concurrent.CountDownLatch import com.emarsys.mobileengage.api.geofence.Geofence as MEGeofence -class DefaultGeofenceInternalTest { +class DefaultGeofenceInternalTest : AnnotationSpec() { private companion object { val refreshTrigger = Trigger( @@ -106,7 +105,7 @@ class DefaultGeofenceInternalTest { private lateinit var pendingIntent: PendingIntent private lateinit var mockTask: Task - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() mockInitialEnterTriggerEnabledStorage = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt index c40baa0ee..b0da646ce 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt @@ -5,21 +5,20 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.util.waitForTask -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class FetchGeofencesActionTest { - +class FetchGeofencesActionTest : AnnotationSpec() { private lateinit var mockGeofenceInternal: GeofenceInternal private lateinit var mockActivity: Activity private lateinit var fetchGeofencesAction: FetchGeofencesAction - @BeforeEach + @Before fun setUp() { mockGeofenceInternal = mock() mockActivity = mock() @@ -29,7 +28,7 @@ class FetchGeofencesActionTest { fetchGeofencesAction = FetchGeofencesAction(mockGeofenceInternal) } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceFilterTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceFilterTest.kt index d2614d992..f1fc76907 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceFilterTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceFilterTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.geofence + import android.location.Location import android.location.LocationManager import com.emarsys.mobileengage.api.geofence.Geofence @@ -7,14 +8,12 @@ import com.emarsys.mobileengage.api.geofence.Trigger import com.emarsys.mobileengage.api.geofence.TriggerType import com.emarsys.mobileengage.geofence.model.GeofenceGroup import com.emarsys.mobileengage.geofence.model.GeofenceResponse +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test -class GeofenceFilterTest { +class GeofenceFilterTest : AnnotationSpec() { private companion object { val currentLocation: Location = Location(LocationManager.GPS_PROVIDER).apply { @@ -23,11 +22,11 @@ class GeofenceFilterTest { } val trigger = Trigger(id = "triggerId", type = TriggerType.ENTER, action = JSONObject()) val allGeofences = listOf( - Geofence("geofenceId1", 47.493160, 19.058355, 10.0, null, listOf(trigger)), - Geofence("geofenceId2", 47.493812, 19.058537, 10.0, null, listOf(trigger)), - Geofence("geofenceId3", 47.493827, 19.060715, 10.0, null, listOf(trigger)), - Geofence("geofenceId4", 47.489680, 19.061230, 350.0, null, listOf(trigger)), - Geofence("geofenceId5", 47.492292, 19.056440, 10.0, null, listOf(trigger)) + Geofence("geofenceId1", 47.493160, 19.058355, 10.0, null, listOf(trigger)), + Geofence("geofenceId2", 47.493812, 19.058537, 10.0, null, listOf(trigger)), + Geofence("geofenceId3", 47.493827, 19.060715, 10.0, null, listOf(trigger)), + Geofence("geofenceId4", 47.489680, 19.061230, 350.0, null, listOf(trigger)), + Geofence("geofenceId5", 47.492292, 19.056440, 10.0, null, listOf(trigger)) ) } @@ -35,7 +34,7 @@ class GeofenceFilterTest { private lateinit var geofenceFilter: GeofenceFilter - @BeforeEach + @Before fun setUp() { geofenceFilter = GeofenceFilter(allGeofences.size) } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProviderTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProviderTest.kt index 415b04af0..f2ffbd5b0 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProviderTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProviderTest.kt @@ -2,14 +2,15 @@ package com.emarsys.mobileengage.geofence import android.app.PendingIntent import androidx.test.platform.app.InstrumentationRegistry +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.Test -class GeofencePendingIntentProviderTest { +class GeofencePendingIntentProviderTest : AnnotationSpec() { @Test fun testProvidePendingIntent() { - val result = GeofencePendingIntentProvider(InstrumentationRegistry.getInstrumentation().context).providePendingIntent() + val result = + GeofencePendingIntentProvider(InstrumentationRegistry.getInstrumentation().context).providePendingIntent() result shouldNotBe null result::class.java shouldBe PendingIntent::class.java diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceResponseMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceResponseMapperTest.kt index 43ccbcc7d..9a2e63676 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceResponseMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/GeofenceResponseMapperTest.kt @@ -1,28 +1,26 @@ package com.emarsys.mobileengage.geofence + import com.emarsys.core.response.ResponseModel import com.emarsys.mobileengage.api.geofence.Geofence import com.emarsys.mobileengage.api.geofence.Trigger import com.emarsys.mobileengage.api.geofence.TriggerType import com.emarsys.mobileengage.geofence.model.GeofenceGroup import com.emarsys.mobileengage.geofence.model.GeofenceResponse +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import org.json.JSONArray import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class GeofenceResponseMapperTest { +class GeofenceResponseMapperTest : AnnotationSpec() { private lateinit var mockResponseModel: ResponseModel private lateinit var mapper: GeofenceResponseMapper - @BeforeEach + @Before fun setUp() { mapper = GeofenceResponseMapper() mockResponseModel = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/AppStartActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/AppStartActionTest.kt index 93a628207..a1c66dce9 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/AppStartActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/AppStartActionTest.kt @@ -7,22 +7,20 @@ import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.event.EventServiceInternal import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.util.waitForTask +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions -class AppStartActionTest { +class AppStartActionTest : AnnotationSpec() { private lateinit var mockEventServiceInternal: EventServiceInternal private lateinit var mockContactTokenStorage: Storage private lateinit var startAction: AppStartAction - @BeforeEach + @Before fun setUp() { mockEventServiceInternal = mock() mockContactTokenStorage = mock() @@ -32,7 +30,7 @@ class AppStartActionTest { startAction = AppStartAction(mockEventServiceInternal, mockContactTokenStorage) } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppEventHandlerInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppEventHandlerInternalTest.kt index b255f9862..ae9f3b47a 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppEventHandlerInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppEventHandlerInternalTest.kt @@ -1,18 +1,16 @@ package com.emarsys.mobileengage.iam +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class InAppEventHandlerInternalTest { +class InAppEventHandlerInternalTest : AnnotationSpec() { private lateinit var inAppEventHandlerInternal: InAppEventHandlerInternal - @BeforeEach + @Before fun setUp() { inAppEventHandlerInternal = InAppEventHandlerInternal() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppInternalTest.kt index 2671388ba..8b9b375d5 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/InAppInternalTest.kt @@ -4,14 +4,14 @@ import com.emarsys.core.api.result.CompletionListener import com.emarsys.core.request.model.RequestModel import com.emarsys.mobileengage.api.event.EventHandler import com.emarsys.mobileengage.event.EventServiceInternal -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.Mockito.mock import org.mockito.Mockito.verify -class InAppInternalTest { +class InAppInternalTest : AnnotationSpec() { private companion object { const val EVENT_NAME = "customEventName" @@ -25,7 +25,7 @@ class InAppInternalTest { private lateinit var mockEventServiceInternal: EventServiceInternal - @BeforeEach + @Before fun init() { mockRequestModel = mock(RequestModel::class.java) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/OverlayInAppPresenterTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/OverlayInAppPresenterTest.kt index 9801e040a..95845e8b3 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/OverlayInAppPresenterTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/OverlayInAppPresenterTest.kt @@ -12,12 +12,11 @@ import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.mobileengage.iam.dialog.IamDialog import com.emarsys.mobileengage.iam.dialog.IamDialogProvider import com.emarsys.mobileengage.iam.webview.MessageLoadedListener +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.fake.FakeActivity import com.emarsys.testUtil.mockito.anyNotNull import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -25,7 +24,7 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify import java.util.concurrent.CountDownLatch -class OverlayInAppPresenterTest { +class OverlayInAppPresenterTest : AnnotationSpec() { companion object { private var SID = "testSid" private var URL = "https://www.emarsys.com" @@ -39,7 +38,7 @@ class OverlayInAppPresenterTest { private lateinit var inAppPresenter: OverlayInAppPresenter - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() mockIamDialog = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/PushToInAppActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/PushToInAppActionTest.kt index 45e0231ba..eceb2cccc 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/PushToInAppActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/PushToInAppActionTest.kt @@ -1,14 +1,14 @@ package com.emarsys.mobileengage.iam import com.emarsys.core.provider.timestamp.TimestampProvider -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -class PushToInAppActionTest { +class PushToInAppActionTest : AnnotationSpec() { companion object { const val CAMPAIGN_ID = "campaignId" @@ -25,7 +25,7 @@ class PushToInAppActionTest { private lateinit var mockTimestampProvider: TimestampProvider - @BeforeEach + @Before fun setup() { mockOverlayInAppPresenter = mock() mockTimestampProvider = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/SaveDisplayedIamActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/SaveDisplayedIamActionTest.kt index 689bf2058..222462ec6 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/SaveDisplayedIamActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/SaveDisplayedIamActionTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.iam + import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.database.repository.Repository import com.emarsys.core.database.repository.SqlSpecification @@ -7,17 +8,15 @@ import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.mobileengage.iam.dialog.action.SaveDisplayedIamAction import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.ThreadSpy import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.timeout import org.mockito.kotlin.verify -class SaveDisplayedIamActionTest { +class SaveDisplayedIamActionTest : AnnotationSpec() { companion object { private const val CAMPAIGN_ID = "123" private const val SID = "testSid" @@ -33,7 +32,7 @@ class SaveDisplayedIamActionTest { private lateinit var timestampProvider: TimestampProvider - @BeforeEach + @Before fun init() { runBlocking { threadSpy = ThreadSpy() @@ -49,7 +48,7 @@ class SaveDisplayedIamActionTest { } } - @AfterEach + @After fun tearDown() { handler.coreLooper.quit() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogProviderTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogProviderTest.kt index 97b5ecb4f..90032fda8 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogProviderTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogProviderTest.kt @@ -1,23 +1,21 @@ package com.emarsys.mobileengage.iam.dialog + import androidx.test.core.app.ActivityScenario import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.fake.FakeActivity import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import java.util.concurrent.CountDownLatch import kotlin.concurrent.thread -class IamDialogProviderTest { +class IamDialogProviderTest : AnnotationSpec() { private lateinit var iamDialogProvider: IamDialogProvider private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { scenario = ActivityScenario.launch(FakeActivity::class.java) scenario.onActivity { activity -> @@ -31,7 +29,7 @@ class IamDialogProviderTest { } } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogTest.kt index 62a3e296a..a87657ce3 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/IamDialogTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.iam.dialog + import android.content.pm.ActivityInfo import android.os.Bundle import android.webkit.WebView @@ -26,15 +27,13 @@ import com.emarsys.mobileengage.iam.model.InAppMetaData import com.emarsys.mobileengage.iam.webview.IamWebView import com.emarsys.mobileengage.iam.webview.IamWebViewFactory import com.emarsys.mobileengage.iam.webview.MessageLoadedListener +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ExtensionTestUtils.runOnMain import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.ReflectionTestUtils import com.emarsys.testUtil.fake.FakeActivity import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -43,7 +42,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class IamDialogTest { +class IamDialogTest : AnnotationSpec() { private companion object { const val CAMPAIGN_ID = "id_value" private const val SID = "testSid" @@ -65,7 +64,7 @@ class IamDialogTest { private lateinit var iamDialog: IamDialog private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { scenario = ActivityScenario.launch(FakeActivity::class.java) val countDownLatch = CountDownLatch(1) @@ -112,7 +111,7 @@ class IamDialogTest { countDownLatch.await() } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() scenario.close() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/action/SendDisplayedIamActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/action/SendDisplayedIamActionTest.kt index 9e3335581..5ed8a44ef 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/action/SendDisplayedIamActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/dialog/action/SendDisplayedIamActionTest.kt @@ -1,31 +1,30 @@ package com.emarsys.mobileengage.iam.dialog.action + import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory.create import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.mobileengage.iam.InAppInternal +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.ThreadSpy -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.isNull import org.mockito.kotlin.whenever -class SendDisplayedIamActionTest { +class SendDisplayedIamActionTest : AnnotationSpec() { private lateinit var action: SendDisplayedIamAction private lateinit var handler: ConcurrentHandlerHolder private lateinit var inAppInternal: InAppInternal - @BeforeEach + @Before fun init() { handler = create() inAppInternal = Mockito.mock(InAppInternal::class.java) action = SendDisplayedIamAction(handler, inAppInternal) } - @AfterEach + @After fun tearDown() { handler.coreLooper.quit() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeFactoryTest.kt index e418cc7e1..b27c366c9 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeFactoryTest.kt @@ -1,11 +1,11 @@ package com.emarsys.mobileengage.iam.jsbridge import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock -class IamJsBridgeFactoryTest { +class IamJsBridgeFactoryTest : AnnotationSpec() { @Test fun createJsBridge_shouldReturnJSBridge() { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeTest.kt index 545d15b78..4bb812b46 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/IamJsBridgeTest.kt @@ -1,18 +1,17 @@ package com.emarsys.mobileengage.iam.jsbridge + import androidx.test.core.app.ActivityScenario import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.mobileengage.api.event.EventHandler import com.emarsys.mobileengage.iam.model.InAppMetaData import com.emarsys.mobileengage.iam.webview.IamWebView +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.fake.FakeActivity import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import org.json.JSONObject -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.kotlin.any import org.mockito.kotlin.anyOrNull @@ -26,7 +25,7 @@ import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions -class IamJsBridgeTest { +class IamJsBridgeTest : AnnotationSpec() { private val jsonObject = JSONObject( mapOf( @@ -51,7 +50,7 @@ class IamJsBridgeTest { private lateinit var captor: ArgumentCaptor private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { scenario = ActivityScenario.launch(FakeActivity::class.java) scenario.onActivity { activity -> @@ -86,7 +85,7 @@ class IamJsBridgeTest { } } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryProviderTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryProviderTest.kt index e77ec59a0..6c464bd90 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryProviderTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryProviderTest.kt @@ -8,11 +8,11 @@ import com.emarsys.core.provider.activity.CurrentActivityProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.mobileengage.iam.InAppInternal import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock -class JSCommandFactoryProviderTest { +class JSCommandFactoryProviderTest : AnnotationSpec() { @Test fun provide_shouldReturnJSCommandFactory() { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryTest.kt index c1e690438..b5fe608c4 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/jsbridge/JSCommandFactoryTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.iam.jsbridge + import android.app.Activity import android.content.ClipboardManager import androidx.test.core.app.ActivityScenario @@ -12,15 +13,13 @@ import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.mobileengage.iam.InAppInternal import com.emarsys.mobileengage.iam.model.InAppMetaData import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.fake.FakeActivity import com.emarsys.testUtil.mockito.ThreadSpy import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doAnswer @@ -34,7 +33,7 @@ import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class JSCommandFactoryTest { +class JSCommandFactoryTest : AnnotationSpec() { private companion object { const val PROPERTY = "testProperty" const val TIMESTAMP = 1233L @@ -57,7 +56,7 @@ class JSCommandFactoryTest { private lateinit var mockClipboardManager: ClipboardManager private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { scenario = ActivityScenario.launch(FakeActivity::class.java) val countDownLatch = CountDownLatch(1) @@ -91,7 +90,7 @@ class JSCommandFactoryTest { countDownLatch.await() } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/IamConversionUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/IamConversionUtilsTest.kt index 9d80c62d1..be9a1b0e5 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/IamConversionUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/IamConversionUtilsTest.kt @@ -3,12 +3,11 @@ package com.emarsys.mobileengage.iam.model import com.emarsys.core.util.TimestampUtils import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import java.util.Arrays -class IamConversionUtilsTest { +class IamConversionUtilsTest : AnnotationSpec() { private var buttonClicked1: ButtonClicked? = null private var buttonClicked2: ButtonClicked? = null private var buttonClicked3: ButtonClicked? = null @@ -16,7 +15,7 @@ class IamConversionUtilsTest { private var displayedIam2: DisplayedIam? = null private var displayedIam3: DisplayedIam? = null - @BeforeEach + @Before fun init() { buttonClicked1 = ButtonClicked("campaign1", "button1", 200) buttonClicked2 = ButtonClicked("campaign1", "button2", 400) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/buttonclicked/ButtonClickedRepositoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/buttonclicked/ButtonClickedRepositoryTest.kt index 9c8405c89..457d43f9a 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/buttonclicked/ButtonClickedRepositoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/buttonclicked/ButtonClickedRepositoryTest.kt @@ -7,21 +7,20 @@ import com.emarsys.core.database.DatabaseContract import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.helper.DbHelper import com.emarsys.core.handler.ConcurrentHandlerHolder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.mock import java.util.Date -class ButtonClickedRepositoryTest { +class ButtonClickedRepositoryTest : AnnotationSpec() { private lateinit var repository: ButtonClickedRepository private lateinit var buttonClicked1: ButtonClicked private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { deleteCoreDatabase() val context = getTargetContext() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/displayediam/DisplayedIamRepositoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/displayediam/DisplayedIamRepositoryTest.kt index f4a21ef78..cbaa0a3b3 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/displayediam/DisplayedIamRepositoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/displayediam/DisplayedIamRepositoryTest.kt @@ -8,23 +8,22 @@ import com.emarsys.core.database.DatabaseContract.DISPLAYED_IAM_COLUMN_NAME_TIME import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.helper.DbHelper import com.emarsys.core.handler.ConcurrentHandlerHolder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import java.util.Date -class DisplayedIamRepositoryTest { +class DisplayedIamRepositoryTest : AnnotationSpec() { private lateinit var iamRepository: DisplayedIamRepository private lateinit var displayedIam1: DisplayedIam private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { deleteCoreDatabase() val context = getTargetContext() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt index a4e0d4d63..0b314dc34 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.iam.model.requestRepositoryProxy + import com.emarsys.common.feature.InnerFeature import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.database.helper.CoreDbHelper @@ -26,17 +27,15 @@ import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIamRepository import com.emarsys.mobileengage.util.RequestModelHelper import com.emarsys.mobileengage.util.RequestPayloadUtils.createCompositeRequestModelPayload +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils.deleteCoreDatabase import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.RandomTestUtils.randomString import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.* -class RequestRepositoryProxyTest { +class RequestRepositoryProxyTest : AnnotationSpec() { private lateinit var mockRequestContext: MobileEngageRequestContext private lateinit var mockRequestModelRepository: Repository private lateinit var mockDisplayedIamRepository: Repository @@ -53,7 +52,7 @@ class RequestRepositoryProxyTest { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { deleteCoreDatabase() val context = getTargetContext() @@ -91,7 +90,7 @@ class RequestRepositoryProxyTest { ) } - @AfterEach + @After @Throws(Exception::class) fun tearDown() { FeatureRegistry.disableFeature(InnerFeature.EVENT_SERVICE_V4) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/specification/FilterByCampaignIdTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/specification/FilterByCampaignIdTest.kt index 9e51bbc19..3bee3df32 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/specification/FilterByCampaignIdTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/specification/FilterByCampaignIdTest.kt @@ -8,22 +8,20 @@ import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClickedRepository import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIamRepository +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.DatabaseTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - -class FilterByCampaignIdTest { +class FilterByCampaignIdTest : AnnotationSpec() { private lateinit var displayedIamRepository: DisplayedIamRepository private lateinit var buttonClickedRepository: ButtonClickedRepository private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun init() { DatabaseTestUtils.deleteCoreDatabase() concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewClientTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewClientTest.kt index 65621a514..36b5a8b5d 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewClientTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewClientTest.kt @@ -4,18 +4,17 @@ import android.webkit.WebView import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.mobileengage.fake.FakeMessageLoadedListener +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import java.util.concurrent.CountDownLatch -class IamWebViewClientTest { +class IamWebViewClientTest : AnnotationSpec() { private lateinit var latch: CountDownLatch private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { latch = CountDownLatch(1) concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewFactoryTest.kt index 2bddd5d18..84e18d0b3 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewFactoryTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.iam.webview + import androidx.test.core.app.ActivityScenario import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder @@ -8,20 +9,16 @@ import com.emarsys.mobileengage.iam.jsbridge.IamJsBridge import com.emarsys.mobileengage.iam.jsbridge.IamJsBridgeFactory import com.emarsys.mobileengage.iam.jsbridge.JSCommandFactory import com.emarsys.mobileengage.iam.jsbridge.JSCommandFactoryProvider +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ExtensionTestUtils.runOnMain import com.emarsys.testUtil.fake.FakeActivity import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.util.concurrent.CountDownLatch -class IamWebViewFactoryTest { +class IamWebViewFactoryTest : AnnotationSpec() { private lateinit var mockJSCommandFactoryProvider: JSCommandFactoryProvider private lateinit var mockJSCommandFactory: JSCommandFactory @@ -33,7 +30,7 @@ class IamWebViewFactoryTest { private lateinit var webViewFactory: IamWebViewFactory private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { mockJsBridge = mock() mockJsBridgeFactory = mock { @@ -61,7 +58,7 @@ class IamWebViewFactoryTest { } } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewTest.kt index 6510460d4..ca4dc1917 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/webview/IamWebViewTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.iam.webview + import android.app.Activity import androidx.test.core.app.ActivityScenario import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory @@ -11,18 +12,16 @@ import com.emarsys.mobileengage.iam.jsbridge.JSCommandFactory import com.emarsys.mobileengage.iam.jsbridge.OnAppEventListener import com.emarsys.mobileengage.iam.jsbridge.OnCloseListener import com.emarsys.mobileengage.iam.model.InAppMetaData +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ExtensionTestUtils.runOnMain import com.emarsys.testUtil.fake.FakeActivity import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class IamWebViewTest { +class IamWebViewTest : AnnotationSpec() { private lateinit var iamWebView: IamWebView private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder @@ -33,7 +32,7 @@ class IamWebViewTest { private lateinit var mockActivity: Activity private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun setUp() { concurrentHandlerHolder = ConcurrentHandlerHolderFactory.create() mockActivity = mock() @@ -63,7 +62,7 @@ class IamWebViewTest { } } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/DefaultMessageInboxInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/DefaultMessageInboxInternalTest.kt index 96cca0eb4..49fb42255 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/DefaultMessageInboxInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/DefaultMessageInboxInternalTest.kt @@ -18,10 +18,9 @@ import com.emarsys.mobileengage.api.inbox.Message import com.emarsys.mobileengage.fake.FakeRestClient import com.emarsys.mobileengage.fake.FakeResultListener import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import kotlinx.coroutines.CoroutineScope -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.doReturn @@ -33,7 +32,7 @@ import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class DefaultMessageInboxInternalTest { +class DefaultMessageInboxInternalTest : AnnotationSpec() { private companion object { private const val TAG = "READ" private const val LOWER_CASED_TAG = "read" @@ -54,7 +53,7 @@ class DefaultMessageInboxInternalTest { private lateinit var message: Message - @BeforeEach + @Before fun setUp() { message = Message( "testMessageId", diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/MessageInboxResponseMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/MessageInboxResponseMapperTest.kt index dc62ba59d..ed691cef8 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/MessageInboxResponseMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/inbox/MessageInboxResponseMapperTest.kt @@ -7,17 +7,16 @@ import com.emarsys.mobileengage.api.action.DismissActionModel import com.emarsys.mobileengage.api.action.OpenExternalUrlActionModel import com.emarsys.mobileengage.api.inbox.InboxResult import com.emarsys.mobileengage.api.inbox.Message +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import java.net.URL -class MessageInboxResponseMapperTest { +class MessageInboxResponseMapperTest : AnnotationSpec() { private lateinit var messageInboxResponseMapper: MessageInboxResponseMapper - @BeforeEach + @Before fun setUp() { messageInboxResponseMapper = MessageInboxResponseMapper() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/ActionCommandFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/ActionCommandFactoryTest.kt index a62208b27..d3aff66c6 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/ActionCommandFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/ActionCommandFactoryTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.notification + import android.content.Context import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.mobileengage.event.CacheableEventHandler @@ -7,19 +8,15 @@ import com.emarsys.mobileengage.event.EventServiceInternal import com.emarsys.mobileengage.notification.command.AppEventCommand import com.emarsys.mobileengage.notification.command.CustomEventCommand import com.emarsys.mobileengage.notification.command.OpenExternalUrlCommand +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONArray import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.mock -class ActionCommandFactoryTest { - +class ActionCommandFactoryTest : AnnotationSpec() { private lateinit var factory: ActionCommandFactory @@ -28,7 +25,7 @@ class ActionCommandFactoryTest { private lateinit var mockEventServiceInternal: EventServiceInternal private lateinit var mockNotificationCacheableEventHandler: CacheableEventHandler - @BeforeEach + @Before fun setUp() { context = InstrumentationRegistry.getTargetContext().applicationContext diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksFactoryTest.kt index fb9a948c4..7a757a1e4 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksFactoryTest.kt @@ -1,10 +1,10 @@ package com.emarsys.mobileengage.notification +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test import java.util.concurrent.CountDownLatch -class LaunchActivityCommandLifecycleCallbacksFactoryTest { +class LaunchActivityCommandLifecycleCallbacksFactoryTest : AnnotationSpec() { @Test fun testCreate() { val latch = CountDownLatch(1) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksTest.kt index 7b04e9dd7..607b7dcbe 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/LaunchActivityCommandLifecycleCallbacksTest.kt @@ -4,25 +4,27 @@ import android.app.Activity import android.content.Intent import android.content.pm.PackageManager import androidx.test.platform.app.InstrumentationRegistry +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.fake.FakeActivity import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.util.concurrent.CountDownLatch -class LaunchActivityCommandLifecycleCallbacksTest { +class LaunchActivityCommandLifecycleCallbacksTest : AnnotationSpec() { private lateinit var latch: CountDownLatch private lateinit var launchIntent: Intent private lateinit var mockPackageManager: PackageManager - @BeforeEach + @Before fun setUp() { latch = CountDownLatch(1) - launchIntent = Intent(InstrumentationRegistry.getInstrumentation().targetContext, FakeActivity::class.java) + launchIntent = Intent( + InstrumentationRegistry.getInstrumentation().targetContext, + FakeActivity::class.java + ) mockPackageManager = mock { on { getLaunchIntentForPackage(any()) } doReturn launchIntent } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/NotificationCommandFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/NotificationCommandFactoryTest.kt index 99b005970..4bd98c809 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/NotificationCommandFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/NotificationCommandFactoryTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.notification + import android.app.Activity import android.content.Context import android.content.Intent @@ -27,6 +28,7 @@ import com.emarsys.mobileengage.service.IntentUtils import com.emarsys.mobileengage.service.NotificationData import com.emarsys.mobileengage.service.NotificationMethod import com.emarsys.mobileengage.service.NotificationOperation +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import com.emarsys.testUtil.mockito.whenever import io.kotest.data.forAll @@ -36,13 +38,10 @@ import io.kotest.matchers.shouldNotBe import kotlinx.coroutines.runBlocking import org.json.JSONArray import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.mock import org.mockito.kotlin.mock -class NotificationCommandFactoryTest { +class NotificationCommandFactoryTest : AnnotationSpec() { private companion object { const val SID = "129487fw123" const val MISSING_SID = "Missing sid" @@ -92,7 +91,7 @@ class NotificationCommandFactoryTest { private lateinit var mockCurrentActivityProvider: CurrentActivityProvider private lateinit var mockActivity: Activity - @BeforeEach + @Before fun setUp() { context = InstrumentationRegistry.getTargetContext().applicationContext mockConcurrentHandlerHolder = mock() @@ -126,7 +125,7 @@ class NotificationCommandFactoryTest { factory = NotificationCommandFactory(context) } - @AfterEach + @After fun tearDown() { tearDownMobileEngageComponent() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/AppEventCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/AppEventCommandTest.kt index 96267f479..4ceda5170 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/AppEventCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/AppEventCommandTest.kt @@ -4,24 +4,23 @@ import android.content.Context import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.mobileengage.event.CacheableEventHandler +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.mockito.ThreadSpy +import io.kotest.assertions.fail import org.json.JSONException import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.fail import org.mockito.kotlin.* import java.util.concurrent.CountDownLatch -class AppEventCommandTest { +class AppEventCommandTest : AnnotationSpec() { private lateinit var applicationContext: Context private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder private lateinit var mockEventHandler: CacheableEventHandler - @BeforeEach + @Before fun setUp() { applicationContext = getTargetContext().applicationContext mockEventHandler = mock() @@ -90,7 +89,7 @@ class AppEventCommandTest { null ).run() } catch (e: Exception) { - fail(e.message) + fail(e.message!!) } } } \ No newline at end of file diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CompositeCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CompositeCommandTest.kt index 65719ae94..4f7b752fc 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CompositeCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CompositeCommandTest.kt @@ -1,13 +1,13 @@ package com.emarsys.mobileengage.notification.command -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.inOrder import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class CompositeCommandTest { +class CompositeCommandTest : AnnotationSpec() { @Test diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CustomEventCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CustomEventCommandTest.kt index 57880973a..e07e1c5c6 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CustomEventCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/CustomEventCommandTest.kt @@ -1,15 +1,14 @@ package com.emarsys.mobileengage.notification.command import com.emarsys.mobileengage.event.EventServiceInternal +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito -class CustomEventCommandTest { +class CustomEventCommandTest : AnnotationSpec() { private lateinit var mockEventServiceInternal: EventServiceInternal - @BeforeEach + @Before fun setUp() { mockEventServiceInternal = Mockito.mock(EventServiceInternal::class.java) } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/DismissNotificationCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/DismissNotificationCommandTest.kt index 390a815d4..6cf51b52e 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/DismissNotificationCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/DismissNotificationCommandTest.kt @@ -6,14 +6,14 @@ import android.content.Intent import com.emarsys.mobileengage.service.NotificationData import com.emarsys.mobileengage.service.NotificationOperation -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions -class DismissNotificationCommandTest { +class DismissNotificationCommandTest : AnnotationSpec() { private companion object { const val TITLE = "title" const val BODY = "body" diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/LaunchApplicationCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/LaunchApplicationCommandTest.kt index 74bad0104..ab7fe3fbd 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/LaunchApplicationCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/LaunchApplicationCommandTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.notification.command + import android.app.Activity import android.app.Application import android.content.Intent @@ -9,13 +10,11 @@ import androidx.lifecycle.Lifecycle import androidx.test.core.app.ActivityScenario import com.emarsys.mobileengage.fake.FakeActivityLifecycleCallbacks import com.emarsys.mobileengage.notification.LaunchActivityCommandLifecycleCallbacksFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.fake.FakeActivity import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -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.ArgumentMatchers import org.mockito.Mockito @@ -25,13 +24,13 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class LaunchApplicationCommandTest { +class LaunchApplicationCommandTest : AnnotationSpec() { private lateinit var scenario: ActivityScenario private lateinit var mockProviderLaunchActivityCommand: LaunchActivityCommandLifecycleCallbacksFactory - @BeforeEach + @Before fun setUp() { scenario = ActivityScenario.launch(FakeActivity::class.java) scenario.onActivity { activity -> @@ -40,7 +39,7 @@ class LaunchApplicationCommandTest { } } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/NotificationInformationCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/NotificationInformationCommandTest.kt index e02cca2a1..e3c86681e 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/NotificationInformationCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/NotificationInformationCommandTest.kt @@ -3,23 +3,29 @@ package com.emarsys.mobileengage.notification.command import com.emarsys.mobileengage.api.push.NotificationInformation import com.emarsys.mobileengage.api.push.NotificationInformationListener import com.emarsys.mobileengage.push.NotificationInformationListenerProvider -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class NotificationInformationCommandTest { +class NotificationInformationCommandTest : AnnotationSpec() { @Test fun testRun() { val mockNotificationInformationListener: NotificationInformationListener = mock() - val mockNotificationInformationListenerProvider: NotificationInformationListenerProvider = mock { - on { notificationInformationListener } doReturn mockNotificationInformationListener - } + val mockNotificationInformationListenerProvider: NotificationInformationListenerProvider = + mock { + on { notificationInformationListener } doReturn mockNotificationInformationListener + } val notificationInformation = NotificationInformation("campaignId") - val notificationInformationCommand = NotificationInformationCommand(mockNotificationInformationListenerProvider, notificationInformation) + val notificationInformationCommand = NotificationInformationCommand( + mockNotificationInformationListenerProvider, + notificationInformation + ) notificationInformationCommand.run() verify(mockNotificationInformationListenerProvider).notificationInformationListener - verify(mockNotificationInformationListener).onNotificationInformationReceived(notificationInformation) + verify(mockNotificationInformationListener).onNotificationInformationReceived( + notificationInformation + ) } } \ No newline at end of file diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/OpenExternalUrlCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/OpenExternalUrlCommandTest.kt index cd72640bc..19be2f6c9 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/OpenExternalUrlCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/OpenExternalUrlCommandTest.kt @@ -3,13 +3,13 @@ package com.emarsys.mobileengage.notification.command import android.content.Context import android.content.Intent -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.Mockito import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class OpenExternalUrlCommandTest { +class OpenExternalUrlCommandTest : AnnotationSpec() { companion object { init { Mockito.mock(Context::class.java) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/PreloadedInappHandlerCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/PreloadedInappHandlerCommandTest.kt index 5a7561d66..f00b30873 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/PreloadedInappHandlerCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/PreloadedInappHandlerCommandTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.notification.command + import com.emarsys.core.activity.ActivityLifecycleActionRegistry import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.handler.ConcurrentHandlerHolder @@ -10,13 +11,11 @@ import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.service.NotificationData import com.emarsys.mobileengage.service.NotificationOperation +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.FileTestUtils import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -26,7 +25,7 @@ import java.io.File import java.util.concurrent.CountDownLatch -class PreloadedInappHandlerCommandTest { +class PreloadedInappHandlerCommandTest : AnnotationSpec() { companion object { private const val URL = "https://www.google.com" const val TITLE = "title" @@ -61,7 +60,7 @@ class PreloadedInappHandlerCommandTest { private lateinit var fileUrl: String - @BeforeEach + @Before fun setUp() { fileUrl = InstrumentationRegistry.getTargetContext().applicationContext.cacheDir.absolutePath + "/test.file" @@ -83,7 +82,7 @@ class PreloadedInappHandlerCommandTest { } - @AfterEach + @After fun tearDown() { concurrentHandlerHolder.coreLooper.quitSafely() tearDownMobileEngageComponent() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/SilentNotificationInformationCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/SilentNotificationInformationCommandTest.kt index ddc0c5db8..074bcbede 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/SilentNotificationInformationCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/SilentNotificationInformationCommandTest.kt @@ -4,28 +4,34 @@ import com.emarsys.mobileengage.api.push.NotificationInformation import com.emarsys.mobileengage.api.push.NotificationInformationListener import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify -class SilentNotificationInformationCommandTest { +class SilentNotificationInformationCommandTest : AnnotationSpec() { @Test fun testRun() { val mockNotificationInformationListener: NotificationInformationListener = mock() - val mockSilentNotificationInformationListenerProvider: SilentNotificationInformationListenerProvider = mock { - on { silentNotificationInformationListener } doReturn mockNotificationInformationListener - } + val mockSilentNotificationInformationListenerProvider: SilentNotificationInformationListenerProvider = + mock { + on { silentNotificationInformationListener } doReturn mockNotificationInformationListener + } val testNotificationInformation = NotificationInformation("testCampaignId") - val silentNotificationInformationCommand = SilentNotificationInformationCommand(mockSilentNotificationInformationListenerProvider, testNotificationInformation) + val silentNotificationInformationCommand = SilentNotificationInformationCommand( + mockSilentNotificationInformationListenerProvider, + testNotificationInformation + ) silentNotificationInformationCommand.run() verify(mockSilentNotificationInformationListenerProvider).silentNotificationInformationListener - verify(mockNotificationInformationListener).onNotificationInformationReceived(testNotificationInformation) + verify(mockNotificationInformationListener).onNotificationInformationReceived( + testNotificationInformation + ) } } \ No newline at end of file diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackActionClickCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackActionClickCommandTest.kt index 0ebadec7b..34cc71927 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackActionClickCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackActionClickCommandTest.kt @@ -1,11 +1,11 @@ package com.emarsys.mobileengage.notification.command import com.emarsys.mobileengage.event.EventServiceInternal +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow -import org.junit.jupiter.api.Test import org.mockito.Mockito -class TrackActionClickCommandTest { +class TrackActionClickCommandTest : AnnotationSpec() { @Test fun testConstructor_eventServiceInternal_mustNotBeNull() { shouldThrow { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackMessageOpenCommandTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackMessageOpenCommandTest.kt index 1af30f9d0..bffe477dd 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackMessageOpenCommandTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/notification/command/TrackMessageOpenCommandTest.kt @@ -2,12 +2,12 @@ package com.emarsys.mobileengage.notification.command import com.emarsys.mobileengage.push.PushInternal -import org.junit.jupiter.api.Test +import com.emarsys.testUtil.AnnotationSpec import org.mockito.Mockito.mock import org.mockito.Mockito.verify -class TrackMessageOpenCommandTest { +class TrackMessageOpenCommandTest : AnnotationSpec() { @Test diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushInternalTest.kt index d9b8367ff..439294b05 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushInternalTest.kt @@ -15,12 +15,11 @@ import com.emarsys.mobileengage.event.CacheableEventHandler import com.emarsys.mobileengage.event.EventServiceInternal import com.emarsys.mobileengage.fake.FakeCompletionListener import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.ThreadSpy import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.argumentCaptor @@ -33,7 +32,7 @@ import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.verifyNoMoreInteractions import java.util.concurrent.CountDownLatch -class DefaultPushInternalTest { +class DefaultPushInternalTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 123456789L @@ -69,7 +68,7 @@ class DefaultPushInternalTest { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushTokenProviderTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushTokenProviderTest.kt index 5e54b2dcc..d4ef05202 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushTokenProviderTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/push/DefaultPushTokenProviderTest.kt @@ -2,14 +2,12 @@ package com.emarsys.mobileengage.push import com.emarsys.core.storage.Storage import com.emarsys.core.storage.StringStorage +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class DefaultPushTokenProviderTest { +class DefaultPushTokenProviderTest : AnnotationSpec() { private companion object { const val PUSH_TOKEN = "pushToken" } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyProviderTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyProviderTest.kt index 8d53bf0ce..a1999a765 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyProviderTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyProviderTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.request + import com.emarsys.core.CoreCompletionHandler import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.request.RestClient @@ -9,16 +10,13 @@ import com.emarsys.core.worker.CoreCompletionHandlerMiddleware import com.emarsys.core.worker.Worker import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock import org.mockito.kotlin.mock -class CoreCompletionHandlerRefreshTokenProxyProviderTest { +class CoreCompletionHandlerRefreshTokenProxyProviderTest : AnnotationSpec() { private lateinit var mockCoreCompletionHandlerMiddlewareProvider: CoreCompletionHandlerMiddlewareProvider private lateinit var mockCoreCompletionHandlerMiddleware: CoreCompletionHandlerMiddleware private lateinit var mockRestClient: RestClient @@ -36,7 +34,7 @@ class CoreCompletionHandlerRefreshTokenProxyProviderTest { private lateinit var mockRequestModelFactory: MobileEngageRequestModelFactory - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockCoreCompletionHandlerMiddlewareProvider = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyTest.kt index e94151737..b379c9055 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/CoreCompletionHandlerRefreshTokenProxyTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.request + import com.emarsys.core.CoreCompletionHandler import com.emarsys.core.request.RestClient import com.emarsys.core.request.model.RequestMethod @@ -8,11 +9,8 @@ import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.Storage import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq @@ -21,8 +19,7 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify import java.net.URL -class CoreCompletionHandlerRefreshTokenProxyTest { - +class CoreCompletionHandlerRefreshTokenProxyTest : AnnotationSpec() { companion object { @@ -41,7 +38,7 @@ class CoreCompletionHandlerRefreshTokenProxyTest { private lateinit var mockRequestModelHelper: RequestModelHelper private lateinit var mockRequestModelFactory: MobileEngageRequestModelFactory - @BeforeEach + @Before fun setUp() { mockRequestModel = mock { on { url } doReturn URL(CLIENT_HOST) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt index 34013684c..9179e6eba 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.request + import com.emarsys.common.feature.InnerFeature import com.emarsys.core.api.notification.NotificationSettings import com.emarsys.core.device.DeviceInfo @@ -14,17 +15,14 @@ import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClickedRepository import com.emarsys.mobileengage.util.RequestPayloadUtils +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class MobileEngageRequestModelFactoryTest { +class MobileEngageRequestModelFactoryTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 123456789L @@ -59,7 +57,7 @@ class MobileEngageRequestModelFactoryTest { lateinit var mockButtonClickedRepository: ButtonClickedRepository - @BeforeEach + @Before fun setUp() { mockEventServiceProvider = mock { on { provideEndpointHost() } doReturn EVENT_HOST diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt index b4628f68d..557510880 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.request.mapper + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider @@ -10,18 +11,15 @@ import com.emarsys.core.storage.StringStorage import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.util.RequestModelHelper import com.emarsys.mobileengage.util.RequestPayloadUtils +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class ContactTokenHeaderMapperTest { +class ContactTokenHeaderMapperTest : AnnotationSpec() { private companion object { const val CONTACT_TOKEN = "contactToken" const val REFRESH_TOKEN = "refreshToken" @@ -41,7 +39,7 @@ class ContactTokenHeaderMapperTest { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockContactTokenStorage = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt index 7c7a359bc..ad737ebe0 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt @@ -1,20 +1,18 @@ package com.emarsys.mobileengage.request.mapper + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.mobileengage.MobileEngageRequestContext +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class DefaultRequestHeaderMapperTest { +class DefaultRequestHeaderMapperTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 234123L @@ -29,7 +27,7 @@ class DefaultRequestHeaderMapperTest { private lateinit var mockDeviceInfo: DeviceInfo - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockDeviceInfo = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt index 799470ca0..a58fcf4b0 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt @@ -8,16 +8,15 @@ import com.emarsys.core.request.model.RequestModel import com.emarsys.core.storage.Storage import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class DeviceEventStateRequestMapperTest { +class DeviceEventStateRequestMapperTest : AnnotationSpec() { companion object { const val DEVICE_EVENT_STATE: String = """{"device-event-state":true}""" val DEVICE_EVENT_STATE_JSON: JSONObject = JSONObject("""{"device-event-state":true}""") @@ -32,7 +31,7 @@ class DeviceEventStateRequestMapperTest { private lateinit var mockDeviceEventStateStorage: Storage private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { FeatureRegistry.enableFeature(InnerFeature.EVENT_SERVICE_V4) val mockDeviceInfo: DeviceInfo = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt index 5639db0ee..931c52e1f 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.request.mapper + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider @@ -9,19 +10,16 @@ import com.emarsys.core.request.model.RequestModel import com.emarsys.core.storage.StringStorage import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock class -MobileEngageHeaderMapperTest { +MobileEngageHeaderMapperTest : AnnotationSpec() { private companion object { const val CLIENT_STATE = "client-state" const val TIMESTAMP = 123456789L @@ -39,7 +37,7 @@ MobileEngageHeaderMapperTest { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockClientStateStorage = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt index 65b368e60..1049cd843 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.request.mapper + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider @@ -8,17 +9,14 @@ import com.emarsys.core.request.model.RequestMethod import com.emarsys.core.request.model.RequestModel import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class OpenIdTokenRequestMapperTest { +class OpenIdTokenRequestMapperTest : AnnotationSpec() { private companion object { const val OPEN_ID_TOKEN = "openIdToken" const val TIMESTAMP = 123456789L @@ -35,7 +33,7 @@ class OpenIdTokenRequestMapperTest { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { mockDeviceInfo = mock { on { hardwareId } doReturn HARDWARE_ID diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/ClientInfoResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/ClientInfoResponseHandlerTest.kt index 355bb19da..422b2d15f 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/ClientInfoResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/ClientInfoResponseHandlerTest.kt @@ -1,35 +1,32 @@ package com.emarsys.mobileengage.responsehandler + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.StringStorage +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock import org.mockito.Mockito.verify import java.net.URL -class ClientInfoResponseHandlerTest { +class ClientInfoResponseHandlerTest : AnnotationSpec() { companion object { val URL: URL = URL("https://me-client.eservice.emarsys.net/v3/apps/12341/client") } - private lateinit var clientInfoResponseHandler: ClientInfoResponseHandler private lateinit var mockDeviceInfo: DeviceInfo - private lateinit var mockDeviceInfoPayloadStorage:StringStorage + private lateinit var mockDeviceInfoPayloadStorage: StringStorage private lateinit var mockResponseModel: ResponseModel private lateinit var mockRequestModel: RequestModel - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockDeviceInfo = mock(DeviceInfo::class.java) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/DeviceEventStateResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/DeviceEventStateResponseHandlerTest.kt index 43f9fe871..4f6fd4e98 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/DeviceEventStateResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/DeviceEventStateResponseHandlerTest.kt @@ -6,9 +6,8 @@ import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.StringStorage import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -16,7 +15,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.net.URL -class DeviceEventStateResponseHandlerTest { +class DeviceEventStateResponseHandlerTest : AnnotationSpec() { companion object { private const val EVENT_HOST = "https://mobile-events.eservice.emarsys.net" private const val EVENT_BASE = "$EVENT_HOST/v4/apps/%s/events" @@ -28,7 +27,7 @@ class DeviceEventStateResponseHandlerTest { private lateinit var handler: DeviceEventStateResponseHandler private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setup() { mockRequestModel = mock { on { url } doReturn URL(EVENT_BASE) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerTest.kt index 91f72c7a1..f3449c63d 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.responsehandler + import com.emarsys.common.feature.InnerFeature import com.emarsys.core.database.repository.Repository import com.emarsys.core.database.repository.SqlSpecification @@ -10,20 +11,17 @@ import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam import com.emarsys.mobileengage.iam.model.specification.FilterByCampaignId import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify import java.net.URL -class InAppCleanUpResponseHandlerTest { +class InAppCleanUpResponseHandlerTest : AnnotationSpec() { companion object { private const val EVENT_HOST = "https://mobile-events.eservice.emarsys.net" private const val EVENT_BASE = "$EVENT_HOST/v3/apps/%s/client/events" @@ -36,7 +34,7 @@ class InAppCleanUpResponseHandlerTest { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { mockRequestModel = mock { on { url } doReturn URL(EVENT_BASE) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerV4Test.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerV4Test.kt index d15883bc0..100e6f1fa 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerV4Test.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppCleanUpResponseHandlerV4Test.kt @@ -10,12 +10,11 @@ import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam import com.emarsys.mobileengage.iam.model.specification.FilterByCampaignId import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -24,7 +23,7 @@ import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever import java.net.URL -class InAppCleanUpResponseHandlerV4Test { +class InAppCleanUpResponseHandlerV4Test : AnnotationSpec() { companion object { private const val EVENT_HOST = "https://mobile-events.eservice.emarsys.net" private const val EVENT_BASE = "$EVENT_HOST/v4/apps/%s/events" @@ -37,7 +36,7 @@ class InAppCleanUpResponseHandlerV4Test { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { mockRequestModel = mock { on { url } doReturn URL(EVENT_BASE) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppMessageResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppMessageResponseHandlerTest.kt index 1b83cf03e..a7148c56e 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppMessageResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/InAppMessageResponseHandlerTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.responsehandler + import android.content.ClipboardManager import androidx.test.core.app.ActivityScenario import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory @@ -14,11 +15,9 @@ import com.emarsys.mobileengage.iam.dialog.IamDialog import com.emarsys.mobileengage.iam.dialog.IamDialogProvider import com.emarsys.mobileengage.iam.jsbridge.IamJsBridge import com.emarsys.mobileengage.iam.jsbridge.IamJsBridgeFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.fake.FakeActivity import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doReturn @@ -26,7 +25,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.verify -class InAppMessageResponseHandlerTest { +class InAppMessageResponseHandlerTest : AnnotationSpec() { private lateinit var handler: InAppMessageResponseHandler private lateinit var presenter: OverlayInAppPresenter @@ -38,7 +37,7 @@ class InAppMessageResponseHandlerTest { private lateinit var mockCurrentActivityProvider: CurrentActivityProvider private lateinit var scenario: ActivityScenario - @BeforeEach + @Before fun init() { scenario = ActivityScenario.launch(FakeActivity::class.java) scenario.onActivity { activity -> @@ -75,7 +74,7 @@ class InAppMessageResponseHandlerTest { } } - @AfterEach + @After fun tearDown() { scenario.close() } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageClientStateResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageClientStateResponseHandlerTest.kt index 4fffeade0..20b392a2b 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageClientStateResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageClientStateResponseHandlerTest.kt @@ -1,25 +1,24 @@ package com.emarsys.mobileengage.responsehandler + import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.StringStorage import com.emarsys.mobileengage.endpoint.Endpoint import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify import java.net.URL -class MobileEngageClientStateResponseHandlerTest { +class MobileEngageClientStateResponseHandlerTest : AnnotationSpec() { private companion object { - const val X_CLIENT_STATE_VALUE = "TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQgb2YgdGhlIHByaW50aW5nIGFuZCB0" + const val X_CLIENT_STATE_VALUE = + "TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQgb2YgdGhlIHByaW50aW5nIGFuZCB0" const val APPLICATION_CODE = "applicationCode" const val CLIENT_HOST = "https://mobile-events.eservice.emarsys.net/v3" } @@ -30,7 +29,7 @@ class MobileEngageClientStateResponseHandlerTest { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { mockStorage = mock() requestModelMock = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageTokenResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageTokenResponseHandlerTest.kt index d994abd3b..6a1c47e2a 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageTokenResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/MobileEngageTokenResponseHandlerTest.kt @@ -1,22 +1,20 @@ package com.emarsys.mobileengage.responsehandler + import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.StringStorage import com.emarsys.mobileengage.util.RequestModelHelper +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.verify import java.net.URL -class MobileEngageTokenResponseHandlerTest { +class MobileEngageTokenResponseHandlerTest : AnnotationSpec() { private companion object { const val CLIENT_HOST = "https://mobile-events.eservice.emarsys.net" const val CLIENT_BASE = "$CLIENT_HOST/v3/apps/%s/client" @@ -30,7 +28,7 @@ class MobileEngageTokenResponseHandlerTest { private lateinit var mockRequestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ4IjoieSJ9.bKXKVZCwf8J55WzWagrg2S0o2k_xZQ-HYfHIIj_2Z_U" diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/OnEventActionResponseHandlerTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/OnEventActionResponseHandlerTest.kt index d983f9e0b..83f56563c 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/OnEventActionResponseHandlerTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/responsehandler/OnEventActionResponseHandlerTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.responsehandler + import android.os.Looper import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.database.repository.Repository @@ -13,14 +14,12 @@ import com.emarsys.mobileengage.event.EventServiceInternal import com.emarsys.mobileengage.iam.model.displayediam.DisplayedIam import com.emarsys.mobileengage.notification.ActionCommandFactory import com.emarsys.mobileengage.notification.command.AppEventCommand +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.anyNotNull import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.doReturn @@ -29,7 +28,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.timeout import org.mockito.kotlin.verify -class OnEventActionResponseHandlerTest { +class OnEventActionResponseHandlerTest : AnnotationSpec() { private lateinit var responseHandler: OnEventActionResponseHandler private lateinit var mockActionCommandFactory: ActionCommandFactory @@ -40,7 +39,7 @@ class OnEventActionResponseHandlerTest { private lateinit var concurrentHandlerHolder: ConcurrentHandlerHolder - @BeforeEach + @Before fun setUp() { mockAppEventCommand = mock() mockActionCommandFactory = mock() @@ -59,7 +58,7 @@ class OnEventActionResponseHandlerTest { ) } - @AfterEach + @After fun tearDown() { try { val looper: Looper? = concurrentHandlerHolder.coreLooper diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/IntentUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/IntentUtilsTest.kt index 6a277b9c6..9f1abdc4f 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/IntentUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/IntentUtilsTest.kt @@ -9,15 +9,14 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.service.IntentUtils.createLaunchIntent import com.emarsys.mobileengage.service.IntentUtils.createNotificationHandlerServiceIntent +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -class IntentUtilsTest { +class IntentUtilsTest : AnnotationSpec() { private companion object { const val TITLE = "title" const val BODY = "body" @@ -47,7 +46,7 @@ class IntentUtilsTest { private lateinit var context: Context - @BeforeEach + @Before fun init() { setupMobileEngageComponent(FakeMobileEngageDependencyContainer()) context = getTargetContext() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt index 70d49a497..a70fbcd1a 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.service + import android.R import android.app.Notification import android.content.Context @@ -27,17 +28,13 @@ import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvid import com.emarsys.mobileengage.service.MessagingServiceUtils.styleNotification import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperV1 +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.copyInputStreamToFile import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONArray import org.json.JSONObject -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.kotlin.any import org.mockito.kotlin.doReturn @@ -47,7 +44,7 @@ import org.mockito.kotlin.whenever import java.io.File import java.util.Locale -class MessagingServiceUtilsTest { +class MessagingServiceUtilsTest : AnnotationSpec() { private companion object { const val TITLE = "title" const val BODY = "body" @@ -93,7 +90,7 @@ class MessagingServiceUtilsTest { private lateinit var mockRemoteMessageMapperV1: RemoteMessageMapperV1 - @BeforeEach + @Before fun init() { context = getTargetContext() val mockNotificationSettings: NotificationSettings = mock() @@ -150,7 +147,7 @@ class MessagingServiceUtilsTest { ) } - @AfterEach + @After fun tearDown() { mobileEngage().concurrentHandlerHolder.coreLooper.quitSafely() tearDownMobileEngageComponent() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/NotificationActionUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/NotificationActionUtilsTest.kt index b25ad1416..a2a346cf0 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/NotificationActionUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/NotificationActionUtilsTest.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.service + import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat @@ -8,21 +9,18 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.notification.NotificationCommandFactory +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext import com.emarsys.testUtil.mockito.ThreadSpy import io.kotest.matchers.shouldBe import org.json.JSONArray import org.json.JSONException import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test - import org.mockito.Mockito import org.mockito.kotlin.whenever import java.util.concurrent.CountDownLatch -class NotificationActionUtilsTest { +class NotificationActionUtilsTest : AnnotationSpec() { private companion object { const val SMALL_RESOURCE_ID = 123 const val COLOR_RESOURCE_ID = 456 @@ -44,13 +42,13 @@ class NotificationActionUtilsTest { private lateinit var context: Context - @BeforeEach + @Before fun init() { context = getTargetContext().applicationContext setupMobileEngageComponent(FakeMobileEngageDependencyContainer()) } - @AfterEach + @After fun tearDown() { mobileEngage().concurrentHandlerHolder.coreLooper.quitSafely() tearDownMobileEngageComponent() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV1Test.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV1Test.kt index 5e8ab8393..47f53668b 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV1Test.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV1Test.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.service + import android.content.Context import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.resource.MetaDataReader @@ -9,17 +10,15 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperV1 +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class RemoteMessageMapperV1Test { +class RemoteMessageMapperV1Test : AnnotationSpec() { private companion object { const val TITLE = "title" const val BODY = "body" @@ -40,7 +39,7 @@ class RemoteMessageMapperV1Test { private lateinit var remoteMessageMapperV1: RemoteMessageMapperV1 - @BeforeEach + @Before fun setUp() { context = InstrumentationRegistry.getTargetContext() @@ -58,7 +57,7 @@ class RemoteMessageMapperV1Test { ) } - @AfterEach + @After fun tearDown() { mobileEngage().concurrentHandlerHolder.coreLooper.quitSafely() tearDownMobileEngageComponent() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt index 0aa61d334..c2080c6fe 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt @@ -1,5 +1,6 @@ package com.emarsys.mobileengage.service + import android.content.Context import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.resource.MetaDataReader @@ -9,19 +10,17 @@ import com.emarsys.mobileengage.di.setupMobileEngageComponent import com.emarsys.mobileengage.di.tearDownMobileEngageComponent import com.emarsys.mobileengage.fake.FakeMobileEngageDependencyContainer import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperV2 +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.json.JSONArray import org.json.JSONObject -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class RemoteMessageMapperV2Test { +class RemoteMessageMapperV2Test : AnnotationSpec() { private companion object { const val TITLE = "title" const val BODY = "body" @@ -41,7 +40,7 @@ class RemoteMessageMapperV2Test { private lateinit var remoteMessageMapperV2: RemoteMessageMapperV2 - @BeforeEach + @Before fun init() { context = InstrumentationRegistry.getTargetContext() @@ -60,7 +59,7 @@ class RemoteMessageMapperV2Test { ) } - @AfterEach + @After fun tearDown() { mobileEngage().concurrentHandlerHolder.coreLooper.quitSafely() tearDownMobileEngageComponent() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/session/MobileEngageSessionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/session/MobileEngageSessionTest.kt index 902056415..2f1c6c31d 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/session/MobileEngageSessionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/session/MobileEngageSessionTest.kt @@ -5,8 +5,8 @@ import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.storage.Storage import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.event.EventServiceInternal -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test + +import com.emarsys.testUtil.AnnotationSpec import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq @@ -16,7 +16,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever -class MobileEngageSessionTest { +class MobileEngageSessionTest : AnnotationSpec() { private companion object { const val SESSION_ID = "testSessionId" @@ -30,7 +30,7 @@ class MobileEngageSessionTest { private lateinit var mockContactTokenStorage: Storage private lateinit var mockMobileEngageRequestContext: MobileEngageRequestContext - @BeforeEach + @Before fun setUp() { mockMobileEngageRequestContext = mock { on { applicationCode } doReturn "testApplicationCode" diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/storage/MobileEngageStorageKeyTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/storage/MobileEngageStorageKeyTest.kt index 0d96fd99c..49dce7ce4 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/storage/MobileEngageStorageKeyTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/storage/MobileEngageStorageKeyTest.kt @@ -1,13 +1,13 @@ package com.emarsys.mobileengage.storage +import com.emarsys.testUtil.AnnotationSpec import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Test -class MobileEngageStorageKeyTest { +class MobileEngageStorageKeyTest : AnnotationSpec() { @Test diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestModelHelperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestModelHelperTest.kt index 6cf1b32f2..2406ad802 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestModelHelperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestModelHelperTest.kt @@ -1,19 +1,17 @@ package com.emarsys.mobileengage.util + import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.request.model.RequestModel +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import java.net.URL -class RequestModelHelperTest { +class RequestModelHelperTest : AnnotationSpec() { private companion object { const val CLIENT_HOST = "https://me-client.eservice.emarsys.net/v3" @@ -34,7 +32,7 @@ class RequestModelHelperTest { private lateinit var mockRequestModel: RequestModel private lateinit var requestModelHelper: RequestModelHelper - @BeforeEach + @Before fun setUp() { mockRequestModel = mock() diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt index 20f4dbcec..aaa5d63c9 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt @@ -14,17 +14,14 @@ import com.emarsys.mobileengage.iam.model.IamConversionUtils import com.emarsys.mobileengage.iam.model.buttonclicked.ButtonClicked import com.emarsys.mobileengage.session.SessionIdHolder import com.emarsys.mobileengage.testUtil.RandomMETestUtils +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.RandomTestUtils import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -class RequestPayloadUtilsTest { +class RequestPayloadUtilsTest : AnnotationSpec() { private companion object { const val PUSH_TOKEN = "pushToken" const val APPLICATION_CODE = "applicationCode" @@ -58,7 +55,7 @@ class RequestPayloadUtilsTest { private lateinit var mockSessionIdHolder: SessionIdHolder - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun setUp() { mockChannelSettings = listOf( diff --git a/predict-api/build.gradle.kts b/predict-api/build.gradle.kts index 20a8c2a6d..d8b5ebe30 100644 --- a/predict-api/build.gradle.kts +++ b/predict-api/build.gradle.kts @@ -20,15 +20,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationFilterTest.kt b/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationFilterTest.kt index a07940bf8..58eb6d7f6 100644 --- a/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationFilterTest.kt +++ b/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationFilterTest.kt @@ -2,12 +2,11 @@ package com.emarsys.predict.api.model import com.emarsys.predict.api.model.RecommendationFilter.Companion.exclude import com.emarsys.predict.api.model.RecommendationFilter.Companion.include +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import java.util.Arrays -class RecommendationFilterTest { +class RecommendationFilterTest : AnnotationSpec() { companion object { private const val FIELD = "field" @@ -21,7 +20,7 @@ class RecommendationFilterTest { lateinit var include: RecommendationFilter.Include - @BeforeEach + @Before fun setUp() { exclude = exclude(FIELD) include = include(FIELD) diff --git a/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationLogicTest.kt b/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationLogicTest.kt index 455aa8166..8b84a1409 100644 --- a/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationLogicTest.kt +++ b/predict-api/src/androidTest/java/com/emarsys/predict/api/model/RecommendationLogicTest.kt @@ -8,11 +8,11 @@ import com.emarsys.predict.api.model.RecommendationLogic.Companion.personal import com.emarsys.predict.api.model.RecommendationLogic.Companion.popular import com.emarsys.predict.api.model.RecommendationLogic.Companion.related import com.emarsys.predict.api.model.RecommendationLogic.Companion.search +import com.emarsys.testUtil.AnnotationSpec import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test -class RecommendationLogicTest { +class RecommendationLogicTest : AnnotationSpec() { @Test fun testConstructor_variants_mustBeEmptyList_withoutVariantsParam() { diff --git a/predict/build.gradle.kts b/predict/build.gradle.kts index 1145c55e1..457ed8fa9 100644 --- a/predict/build.gradle.kts +++ b/predict/build.gradle.kts @@ -23,15 +23,21 @@ android { multiDexEnabled = true testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } compileOptions { isCoreLibraryDesugaringEnabled = true } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } diff --git a/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt b/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt index c274bce25..b380b37f3 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt @@ -30,14 +30,13 @@ import com.emarsys.predict.model.LastTrackedItemContainer import com.emarsys.predict.provider.PredictRequestModelBuilderProvider import com.emarsys.predict.request.PredictRequestContext import com.emarsys.predict.request.PredictRequestModelBuilder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.ReflectionTestUtils import com.emarsys.testUtil.mockito.ThreadSpy import com.emarsys.testUtil.mockito.anyNotNull import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.argumentCaptor @@ -49,7 +48,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.verify import java.util.concurrent.CountDownLatch -class DefaultPredictInternalTest { +class DefaultPredictInternalTest : AnnotationSpec() { companion object { const val TTL = Long.MAX_VALUE @@ -84,7 +83,7 @@ class DefaultPredictInternalTest { private lateinit var mockResultListener: ResultListener>> private lateinit var mockLastTrackedItemContainer: LastTrackedItemContainer - @BeforeEach + @Before @Suppress("UNCHECKED_CAST") fun init() { latch = CountDownLatch(1) diff --git a/predict/src/androidTest/java/com/emarsys/predict/PredictResponseMapperTest.kt b/predict/src/androidTest/java/com/emarsys/predict/PredictResponseMapperTest.kt index 2e0cec137..4d3b40fc2 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/PredictResponseMapperTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/PredictResponseMapperTest.kt @@ -1,24 +1,22 @@ package com.emarsys.predict + import com.emarsys.core.response.ResponseModel import com.emarsys.predict.api.model.Product +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.collections.shouldContainAll import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito -class PredictResponseMapperTest { +class PredictResponseMapperTest : AnnotationSpec() { private lateinit var predictResponseMapper: PredictResponseMapper private lateinit var mockResponseModel: ResponseModel private lateinit var expectedResult: List - @BeforeEach + @Before fun setUp() { predictResponseMapper = PredictResponseMapper() mockResponseModel = Mockito.mock(ResponseModel::class.java) diff --git a/predict/src/androidTest/java/com/emarsys/predict/provider/PredictRequestModelBuilderProviderTest.kt b/predict/src/androidTest/java/com/emarsys/predict/provider/PredictRequestModelBuilderProviderTest.kt index 255a3e99e..e7f5595d0 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/provider/PredictRequestModelBuilderProviderTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/provider/PredictRequestModelBuilderProviderTest.kt @@ -1,27 +1,25 @@ package com.emarsys.predict.provider + import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.predict.request.PredictHeaderFactory import com.emarsys.predict.request.PredictRequestContext import com.emarsys.predict.request.PredictRequestModelBuilder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class PredictRequestModelBuilderProviderTest { +class PredictRequestModelBuilderProviderTest : AnnotationSpec() { private lateinit var mockRequestContext: PredictRequestContext private lateinit var mockHeaderFactory: PredictHeaderFactory private lateinit var mockServiceProvider: ServiceEndpointProvider - @BeforeEach + @Before fun setUp() { mockRequestContext = mock(PredictRequestContext::class.java) mockHeaderFactory = mock(PredictHeaderFactory::class.java) diff --git a/predict/src/androidTest/java/com/emarsys/predict/request/PredictHeaderFactoryTest.kt b/predict/src/androidTest/java/com/emarsys/predict/request/PredictHeaderFactoryTest.kt index aeed55e1b..ccec297bd 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/request/PredictHeaderFactoryTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/request/PredictHeaderFactoryTest.kt @@ -1,17 +1,15 @@ package com.emarsys.predict.request + import com.emarsys.core.device.DeviceInfo import com.emarsys.core.storage.KeyValueStore +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito -class PredictHeaderFactoryTest { +class PredictHeaderFactoryTest : AnnotationSpec() { private companion object { const val OS_VERSION = "1.0.0" const val PLATFORM = "android" @@ -23,7 +21,7 @@ class PredictHeaderFactoryTest { private lateinit var mockKeyValueStore: KeyValueStore - @BeforeEach + @Before fun setUp() { mockKeyValueStore = Mockito.mock(KeyValueStore::class.java) diff --git a/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt b/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt index ee4a63798..fd19609ff 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt @@ -14,6 +14,7 @@ import com.emarsys.predict.api.model.PredictCartItem import com.emarsys.predict.api.model.RecommendationFilter import com.emarsys.predict.api.model.RecommendationLogic import com.emarsys.predict.model.LastTrackedItemContainer +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.data.forAll @@ -22,11 +23,9 @@ import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking import org.json.JSONArray import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.mock -class PredictRequestModelBuilderTest { +class PredictRequestModelBuilderTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 123456789L @@ -62,7 +61,7 @@ class PredictRequestModelBuilderTest { private lateinit var mockServiceProvider: ServiceEndpointProvider - @BeforeEach + @Before fun setUp() { mockKeyValueStore = mock(KeyValueStore::class.java).apply { whenever(getString(PREDICT_VISITOR_ID_KEY)).thenReturn("visitorId") diff --git a/predict/src/androidTest/java/com/emarsys/predict/response/VisitorIdResponseHandlerTest.kt b/predict/src/androidTest/java/com/emarsys/predict/response/VisitorIdResponseHandlerTest.kt index e95c2b7d9..2df7dc6e0 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/response/VisitorIdResponseHandlerTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/response/VisitorIdResponseHandlerTest.kt @@ -1,31 +1,27 @@ package com.emarsys.predict.response + import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.KeyValueStore +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock import org.mockito.Mockito.verify -class VisitorIdResponseHandlerTest { - +class VisitorIdResponseHandlerTest : AnnotationSpec() { private lateinit var keyValueStore: KeyValueStore private lateinit var mockServiceEndpointProvider: ServiceEndpointProvider private lateinit var responseHandler: VisitorIdResponseHandler - @BeforeEach + @Before fun init() { keyValueStore = mock(KeyValueStore::class.java) mockServiceEndpointProvider = mock(ServiceEndpointProvider::class.java).apply { diff --git a/predict/src/androidTest/java/com/emarsys/predict/response/XPResponseHandlerTest.kt b/predict/src/androidTest/java/com/emarsys/predict/response/XPResponseHandlerTest.kt index 3e596ca51..0475370b9 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/response/XPResponseHandlerTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/response/XPResponseHandlerTest.kt @@ -1,29 +1,26 @@ package com.emarsys.predict.response + import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.model.RequestModel import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.KeyValueStore +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito import org.mockito.Mockito.mock -class XPResponseHandlerTest { +class XPResponseHandlerTest : AnnotationSpec() { private lateinit var keyValueStore: KeyValueStore private lateinit var responseHandler: XPResponseHandler private lateinit var mockPredictServiceProvider: ServiceEndpointProvider - @BeforeEach + @Before fun init() { mockPredictServiceProvider = mock(ServiceEndpointProvider::class.java).apply { whenever(provideEndpointHost()).thenReturn("https://recommender.scarabresearch.com") diff --git a/predict/src/androidTest/java/com/emarsys/predict/shard/PredictShardListMergerTest.kt b/predict/src/androidTest/java/com/emarsys/predict/shard/PredictShardListMergerTest.kt index 9eef87afc..7a8661359 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/shard/PredictShardListMergerTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/shard/PredictShardListMergerTest.kt @@ -9,17 +9,16 @@ import com.emarsys.core.storage.KeyValueStore import com.emarsys.predict.provider.PredictRequestModelBuilderProvider import com.emarsys.predict.request.PredictRequestContext import com.emarsys.predict.request.PredictRequestModelBuilder +import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.mockito.whenever import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.mockito.Mockito.any import org.mockito.Mockito.anyMap import org.mockito.Mockito.mock import org.mockito.Mockito.verify -class PredictShardListMergerTest { +class PredictShardListMergerTest : AnnotationSpec() { private companion object { const val ID = "id" @@ -47,7 +46,7 @@ class PredictShardListMergerTest { private lateinit var shard3: ShardModel - @BeforeEach + @Before fun init() { mockStore = mock(KeyValueStore::class.java) mockTimestampProvider = mock(TimestampProvider::class.java) diff --git a/predict/src/androidTest/java/com/emarsys/predict/storage/PredictStorageKeyTest.kt b/predict/src/androidTest/java/com/emarsys/predict/storage/PredictStorageKeyTest.kt index 863ca74ac..f1ec63eb9 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/storage/PredictStorageKeyTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/storage/PredictStorageKeyTest.kt @@ -1,13 +1,13 @@ package com.emarsys.predict.storage +import com.emarsys.testUtil.AnnotationSpec import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Test -class PredictStorageKeyTest { +class PredictStorageKeyTest : AnnotationSpec() { @Test diff --git a/predict/src/androidTest/java/com/emarsys/predict/util/CartItemUtilsTest.kt b/predict/src/androidTest/java/com/emarsys/predict/util/CartItemUtilsTest.kt index c653478bb..d51d517d5 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/util/CartItemUtilsTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/util/CartItemUtilsTest.kt @@ -1,24 +1,21 @@ package com.emarsys.predict.util + import com.emarsys.predict.api.model.CartItem import com.emarsys.predict.api.model.PredictCartItem +import com.emarsys.testUtil.AnnotationSpec import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe - -import org.junit.jupiter.api.BeforeEach - -import org.junit.jupiter.api.Test - import org.mockito.Mockito.mock -class CartItemUtilsTest { +class CartItemUtilsTest : AnnotationSpec() { private lateinit var cartItem1: CartItem private lateinit var cartItem2: CartItem private lateinit var cartItem3: CartItem - @BeforeEach + @Before fun init() { cartItem1 = PredictCartItem("1", 100.0, 2.0) cartItem2 = PredictCartItem("2", 200.0, 4.0) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 77d47c5b0..586dc39fa 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -31,7 +31,12 @@ android { buildConfigField( "String", "GOOGLE_OAUTH_SERVER_CLIENT_ID", - "\"${env.fetch("GOOGLE_OAUTH_SERVER_CLIENT_ID", System.getenv("GOOGLE_OAUTH_SERVER_CLIENT_ID") ?: "")}\"" + "\"${ + env.fetch( + "GOOGLE_OAUTH_SERVER_CLIENT_ID", + System.getenv("GOOGLE_OAUTH_SERVER_CLIENT_ID") ?: "" + ) + }\"" ) } @@ -58,10 +63,24 @@ android { if (env.fetch("RELEASE_MODE", (System.getenv("RELEASE_MODE") ?: "false")) == "true") { signingConfigs { create("release") { - storePassword = env.fetch( "ANDROID_RELEASE_STORE_PASSWORD", (System.getenv("ANDROID_RELEASE_STORE_PASSWORD") ?: "")) - keyAlias = env.fetch("ANDROID_RELEASE_KEY_ALIAS", (System.getenv("ANDROID_RELEASE_KEY_ALIAS") ?: "")) - keyPassword = env.fetch("ANDROID_RELEASE_KEY_PASSWORD", (System.getenv("ANDROID_RELEASE_KEY_PASSWORD") ?: "")) - storeFile = file(env.fetch("ANDROID_RELEASE_STORE_FILE_BASE64", (System.getenv("ANDROID_RELEASE_STORE_FILE_BASE64") ?: ""))) + storePassword = env.fetch( + "ANDROID_RELEASE_STORE_PASSWORD", + (System.getenv("ANDROID_RELEASE_STORE_PASSWORD") ?: "") + ) + keyAlias = env.fetch( + "ANDROID_RELEASE_KEY_ALIAS", + (System.getenv("ANDROID_RELEASE_KEY_ALIAS") ?: "") + ) + keyPassword = env.fetch( + "ANDROID_RELEASE_KEY_PASSWORD", + (System.getenv("ANDROID_RELEASE_KEY_PASSWORD") ?: "") + ) + storeFile = file( + env.fetch( + "ANDROID_RELEASE_STORE_FILE_BASE64", + (System.getenv("ANDROID_RELEASE_STORE_FILE_BASE64") ?: "") + ) + ) } } buildTypes { @@ -81,13 +100,25 @@ android { } packaging { resources { - excludes += arrayOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } } dependencies { - if (env.fetch("USE_LOCAL_DEPENDENCY", (System.getenv("USE_LOCAL_DEPENDENCY") ?: "false")) == "true") { + if (env.fetch( + "USE_LOCAL_DEPENDENCY", + (System.getenv("USE_LOCAL_DEPENDENCY") ?: "false") + ) == "true" + ) { implementation(project(":emarsys-sdk")) implementation(project(":emarsys-firebase")) implementation(project(":emarsys-huawei")) diff --git a/testUtils/build.gradle.kts b/testUtils/build.gradle.kts index 95269230d..b75b1368b 100644 --- a/testUtils/build.gradle.kts +++ b/testUtils/build.gradle.kts @@ -15,8 +15,6 @@ android { targetSdk = libs.versions.android.targetSdk.get().toInt() } testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments["runnerBuilder"] = - "de.mannodermaus.junit5.AndroidJUnit5Builder" } buildTypes { @@ -30,7 +28,15 @@ android { } packaging { resources { - excludes += arrayOf("README.txt", "META-INF/LICENSE.md", "META-INF/LICENSE-notice.md") + excludes += arrayOf( + "README.txt", + "META-INF/LICENSE.md", + "META-INF/LICENSE-notice.md", + "**/attach_hotspot_windows.dll", + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/licenses/ASM" + ) } } compileOptions { @@ -54,7 +60,9 @@ dependencies { api(libs.kotlin.stdlib) implementation(libs.kotlin.reflect) + api(libs.junit) api(libs.kotest.assertions.core) + api(libs.kotest.runner.junit4) api(libs.mockito.android) api(libs.mockito.kotlin) api(libs.androidx.test.rules) @@ -63,21 +71,10 @@ dependencies { api(libs.mockk.android) api(libs.mockk.agent) - api("de.mannodermaus.junit5:android-test-core:1.4.0") - api("de.mannodermaus.junit5:android-test-runner:1.4.0") - api("de.mannodermaus.junit5:android-test-extensions:1.4.0") - api("org.junit.jupiter:junit-jupiter-api:5.10.0") - api("org.junit.jupiter:junit-jupiter:5.10.0") - api("org.junit-pioneer:junit-pioneer:2.2.0") - runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0") - androidTestApi("org.junit.jupiter:junit-jupiter-api:5.10.0") - androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:1.4.0") - coreLibraryDesugaring(libs.android.tools.desugar) } configurations { api { exclude(group = "io.mockk", module = "mockk-agent-jvm") } -} -junitPlatform {} \ No newline at end of file +} \ No newline at end of file diff --git a/testUtils/src/main/java/com/emarsys/testUtil/JUnitTestEngineListener.kt b/testUtils/src/main/java/com/emarsys/testUtil/JUnitTestEngineListener.kt new file mode 100644 index 000000000..954a84105 --- /dev/null +++ b/testUtils/src/main/java/com/emarsys/testUtil/JUnitTestEngineListener.kt @@ -0,0 +1,41 @@ +package com.emarsys.testUtil + + +import io.kotest.core.config.ProjectConfiguration +import io.kotest.core.test.TestCase +import io.kotest.core.test.TestResult +import io.kotest.engine.listener.AbstractTestEngineListener +import io.kotest.engine.test.names.DefaultDisplayNameFormatter +import org.junit.runner.Description +import org.junit.runner.Description.createTestDescription +import org.junit.runner.notification.Failure +import org.junit.runner.notification.RunNotifier + +class JUnitTestEngineListener( + private val notifier: RunNotifier, +) : AbstractTestEngineListener() { + + private val formatter = DefaultDisplayNameFormatter(ProjectConfiguration()) + + override suspend fun testStarted(testCase: TestCase) { + notifier.fireTestStarted(describeTestCase(testCase, formatter.format(testCase))) + } + + override suspend fun testFinished(testCase: TestCase, result: TestResult) { + val desc = describeTestCase(testCase, formatter.format(testCase)) + when (result) { + is TestResult.Success -> notifier.fireTestFinished(desc) + is TestResult.Error -> notifyFailure(desc, result) + is TestResult.Ignored -> notifier.fireTestIgnored(desc) + is TestResult.Failure -> notifyFailure(desc, result) + } + } + + private fun notifyFailure(desc: Description, result: TestResult) { + notifier.fireTestFailure(Failure(desc, result.errorOrNull)) + notifier.fireTestFinished(desc) + } +} + +internal fun describeTestCase(testCase: TestCase, displayName: String) = + createTestDescription(testCase.spec::class.java, displayName) \ No newline at end of file diff --git a/testUtils/src/main/java/com/emarsys/testUtil/KotestRunnerAndroid.kt b/testUtils/src/main/java/com/emarsys/testUtil/KotestRunnerAndroid.kt new file mode 100644 index 000000000..3820e3311 --- /dev/null +++ b/testUtils/src/main/java/com/emarsys/testUtil/KotestRunnerAndroid.kt @@ -0,0 +1,45 @@ +package com.emarsys.testUtil + +import io.kotest.core.config.EmptyExtensionRegistry +import io.kotest.core.config.ProjectConfiguration +import io.kotest.core.spec.Spec +import io.kotest.engine.TestEngineLauncher +import io.kotest.engine.spec.Materializer +import io.kotest.engine.spec.createAndInitializeSpec +import io.kotest.engine.test.names.DefaultDisplayNameFormatter +import kotlinx.coroutines.runBlocking +import org.junit.runner.Description +import org.junit.runner.Runner +import org.junit.runner.notification.RunNotifier + +class KotestRunnerAndroid( + private val kClass: Class +) : Runner() { + private val formatter = DefaultDisplayNameFormatter(ProjectConfiguration()) + + override fun run(notifier: RunNotifier) { + runBlocking { + val listener = JUnitTestEngineListener(notifier) + TestEngineLauncher(listener).withClasses(kClass.kotlin).launch() + } + } + + override fun getDescription(): Description { + val spec = runBlocking { + createAndInitializeSpec( + kClass.kotlin, + EmptyExtensionRegistry + ).getOrThrow() + } + val desc = Description.createSuiteDescription(spec::class.java) + Materializer(ProjectConfiguration()).materialize(spec).forEach { rootTest -> + desc.addChild( + describeTestCase( + rootTest, + formatter.format(rootTest) + ) + ) + } + return desc + } +} \ No newline at end of file diff --git a/testUtils/src/main/java/com/emarsys/testUtil/RetryUtils.kt b/testUtils/src/main/java/com/emarsys/testUtil/RetryUtils.kt new file mode 100644 index 000000000..54168b217 --- /dev/null +++ b/testUtils/src/main/java/com/emarsys/testUtil/RetryUtils.kt @@ -0,0 +1,9 @@ +package com.emarsys.testUtil + +import com.emarsys.testUtil.rules.RetryRule + +object RetryUtils { + @JvmStatic + val retryRule + get() = RetryRule(3) +} \ No newline at end of file diff --git a/testUtils/src/main/java/com/emarsys/testUtil/Specs.kt b/testUtils/src/main/java/com/emarsys/testUtil/Specs.kt new file mode 100644 index 000000000..9ed83223f --- /dev/null +++ b/testUtils/src/main/java/com/emarsys/testUtil/Specs.kt @@ -0,0 +1,44 @@ +package com.emarsys.testUtil + +import org.junit.runner.RunWith + + +@RunWith(KotestRunnerAndroid::class) +abstract class FunSpec(body: io.kotest.core.spec.style.FunSpec.() -> Unit = {}) : + io.kotest.core.spec.style.FunSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class AnnotationSpec : + io.kotest.core.spec.style.AnnotationSpec() + +@RunWith(KotestRunnerAndroid::class) +abstract class StringSpec(body: io.kotest.core.spec.style.StringSpec.() -> Unit = {}) : + io.kotest.core.spec.style.StringSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class ShouldSpec(body: io.kotest.core.spec.style.ShouldSpec.() -> Unit = {}) : + io.kotest.core.spec.style.ShouldSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class DescribeSpec(body: io.kotest.core.spec.style.DescribeSpec.() -> Unit = {}) : + io.kotest.core.spec.style.DescribeSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class ExpectSpec(body: io.kotest.core.spec.style.ExpectSpec.() -> Unit = {}) : + io.kotest.core.spec.style.ExpectSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class FeatureSpec(body: io.kotest.core.spec.style.FeatureSpec.() -> Unit = {}) : + io.kotest.core.spec.style.FeatureSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class FreeSpec(body: io.kotest.core.spec.style.FreeSpec.() -> Unit = {}) : + io.kotest.core.spec.style.FreeSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class WordSpec(body: io.kotest.core.spec.style.WordSpec.() -> Unit = {}) : + io.kotest.core.spec.style.WordSpec(body) + +@RunWith(KotestRunnerAndroid::class) +abstract class BehaviorSpec(body: io.kotest.core.spec.style.BehaviorSpec.() -> Unit = {}) : + io.kotest.core.spec.style.BehaviorSpec(body) \ No newline at end of file diff --git a/testUtils/src/main/java/com/emarsys/testUtil/rules/ConnectionRule.kt b/testUtils/src/main/java/com/emarsys/testUtil/rules/ConnectionRule.kt index 0eec0aca7..fab45427c 100644 --- a/testUtils/src/main/java/com/emarsys/testUtil/rules/ConnectionRule.kt +++ b/testUtils/src/main/java/com/emarsys/testUtil/rules/ConnectionRule.kt @@ -2,12 +2,20 @@ package com.emarsys.testUtil.rules import android.app.Application import com.emarsys.testUtil.ConnectionTestUtils -import org.junit.jupiter.api.extension.BeforeEachCallback -import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement -class ConnectionExtension(private val application: Application) : BeforeEachCallback { - override fun beforeEach(p0: ExtensionContext?) { - ConnectionTestUtils.checkConnection(application) +class ConnectionRule(private val application: Application) : TestRule { + + override fun apply(base: Statement?, description: Description?): Statement { + return object : Statement() { + override fun evaluate() { + ConnectionTestUtils.checkConnection(application) + base?.evaluate() + return + } + } } diff --git a/testUtils/src/main/java/com/emarsys/testUtil/rules/DuplicatedThreadRule.kt b/testUtils/src/main/java/com/emarsys/testUtil/rules/DuplicatedThreadRule.kt index 592bc89b6..3454c3d29 100644 --- a/testUtils/src/main/java/com/emarsys/testUtil/rules/DuplicatedThreadRule.kt +++ b/testUtils/src/main/java/com/emarsys/testUtil/rules/DuplicatedThreadRule.kt @@ -1,17 +1,22 @@ package com.emarsys.testUtil.rules +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement -import org.junit.jupiter.api.extension.BeforeEachCallback -import org.junit.jupiter.api.extension.ExtensionContext +class DuplicatedThreadRule(private val threadName: String) : TestRule { -class DuplicatedThreadExtension(private val threadName: String = "CoreSDKHandlerThread") : - BeforeEachCallback { - - override fun beforeEach(p0: ExtensionContext?) { - val threads = - Thread.getAllStackTraces().keys.map { it.name }.filter { it.startsWith(threadName) } - if (threads.size > 1) { - throw Throwable("TEST: $threadName thread is duplicated") + override fun apply(base: Statement?, description: Description?): Statement { + return object : Statement() { + override fun evaluate() { + val threads = Thread.getAllStackTraces().keys.map { it.name } + .filter { it.startsWith(threadName) } + if (threads.size > 1) { + throw Throwable("TEST: $threadName thread is duplicated") + } + base?.evaluate() + return + } } } diff --git a/testUtils/src/main/java/com/emarsys/testUtil/rules/RetryRule.kt b/testUtils/src/main/java/com/emarsys/testUtil/rules/RetryRule.kt new file mode 100644 index 000000000..b0bba3e98 --- /dev/null +++ b/testUtils/src/main/java/com/emarsys/testUtil/rules/RetryRule.kt @@ -0,0 +1,32 @@ +package com.emarsys.testUtil.rules + +import android.util.Log +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement + + +class RetryRule(private val retryCount: Int) : TestRule { + + override fun apply(base: Statement, description: Description) = statement(base, description) + + private fun statement(base: Statement, description: Description): Statement { + return object : Statement() { + override fun evaluate() { + var caughtThrowable: Throwable? = null + + for (i in 0..retryCount) { + try { + base.evaluate() + return + } catch (t: Throwable) { + caughtThrowable = t + Log.e("TEST", "${description.displayName}: run ${(i + 1)} failed.") + } + } + Log.e("TEST", "${description.displayName}: giving up after $retryCount failures.") + throw caughtThrowable!! + } + } + } +} \ No newline at end of file