From ec88dfc99f3406891b749718c898188ddeee45ba Mon Sep 17 00:00:00 2001 From: Rehan Date: Fri, 15 Sep 2023 02:20:45 +0500 Subject: [PATCH] fixed sdk tests --- .../io/customer/sdk/CustomerIOSharedTest.kt | 61 +--- .../java/io/customer/sdk/CustomerIOTest.kt | 262 +--------------- .../customer/sdk/api/HttpRequestRunnerTest.kt | 4 +- .../sdk/data/store/FileStorageTest.kt | 4 +- .../sdk/queue/QueueIntegrationTests.kt | 4 +- .../sdk/queue/QueueStorageIntegrationTest.kt | 4 +- .../sdk/repository/DeviceRepositoryTest.kt | 4 +- .../sdk/repository/ProfileRepositoryTest.kt | 4 +- .../SharedPreferenceRepositoryTest.kt | 4 +- .../SitePreferenceRepositoryTest.kt | 4 +- .../sdk/repository/TrackRepositoryTest.kt | 4 +- .../io/customer/sdk/util/SimpleTimerTest.kt | 4 +- .../io/customer/sdk/CustomerIOSharedTest.kt | 66 ++++ .../java/io/customer/sdk/CustomerIOTest.kt | 286 ++++++++++++++++++ .../customer/sdk/api/HttpRetryPolicyTest.kt | 7 +- .../adapter/CustomAttributesAdapterTest.kt | 7 +- .../io/customer/sdk/data/store/ClientTest.kt | 7 +- .../sdk/data/store/DeviceStoreTest.kt | 7 +- .../customer/sdk/data/store/FileTypeTest.kt | 7 +- .../io/customer/sdk/hook/HookManagerTest.kt | 7 +- .../sdk/queue/QueueQueryRunnerTest.kt | 7 +- .../customer/sdk/queue/QueueRunRequestTest.kt | 23 +- .../java/io/customer/sdk/queue/QueueTest.kt | 16 +- .../io/customer/sdk/util/JsonAdapterTest.kt | 7 +- .../java/io/customer/sdk/util/LoggerTest.kt | 7 +- .../java/io/customer/sdk/util/SecondsTest.kt | 10 +- 26 files changed, 422 insertions(+), 405 deletions(-) create mode 100644 sdk/src/test/java/io/customer/sdk/CustomerIOSharedTest.kt create mode 100644 sdk/src/test/java/io/customer/sdk/CustomerIOTest.kt diff --git a/sdk/src/androidTest/java/io/customer/sdk/CustomerIOSharedTest.kt b/sdk/src/androidTest/java/io/customer/sdk/CustomerIOSharedTest.kt index b8decb82a..28541cd64 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/CustomerIOSharedTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/CustomerIOSharedTest.kt @@ -1,49 +1,18 @@ package io.customer.sdk import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest -import io.customer.sdk.di.CustomerIOSharedComponent +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.di.CustomerIOStaticComponent -import io.customer.sdk.repository.preference.CustomerIOStoredValues -import io.customer.sdk.repository.preference.SharedPreferenceRepository import io.customer.sdk.util.LogcatLogger import io.customer.sdk.util.StaticSettingsProvider import org.amshove.kluent.shouldBeEqualTo -import org.amshove.kluent.shouldNotBe import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock -import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) -class CustomerIOSharedTest : BaseTest() { - @Test - fun verifyInstanceAccessedMultipleTimes_givenNoSpecialCondition_expectSameInstance() { - val instance1 = CustomerIOShared.instance() - val instance2 = CustomerIOShared.instance() - - instance1 shouldBeEqualTo instance2 - } - - @Test - fun verifySharedComponentInstanceAccessedMultipleTimes_givenNoSpecialCondition_expectSameInstance() { - val instance1 = CustomerIOShared.instance().initializeAndGetSharedComponent(context) - val instance2 = CustomerIOShared.instance().initializeAndGetSharedComponent(context) - - instance1 shouldBeEqualTo instance2 - } - - @Test - fun verifyDIGraphProvided_givenInstanceNotInitializedBefore_expectProvidedDIGraph() { - val instance = with(CustomerIOShared) { - clearInstance() - createInstance(diStaticGraph = staticDIComponent) - } - - instance.diStaticGraph shouldBeEqualTo staticDIComponent - } - +class CustomerIOSharedTest : BaseIntegrationTest() { @Test fun verifyAttachedWithSDK_givenNoSpecificEnvironment_expectProvidedLogLevel() { val diGraph = CustomerIOStaticComponent() @@ -57,30 +26,4 @@ class CustomerIOSharedTest : BaseTest() { (instance.diStaticGraph.logger as LogcatLogger).logLevel shouldBeEqualTo cioConfig.logLevel } - - @Test - fun verifyAttachedWithSDK_givenNoSpecificEnvironment_expectSharedComponentToBeInitialized() { - val diGraph = CustomerIOStaticComponent() - - val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) - instance.attachSDKConfig(sdkConfig = cioConfig, context = context) - - val sharedGraph = instance.diSharedGraph - sharedGraph shouldNotBe null - } - - @Test - fun verifyAttachedWithSDK_givenSharedComponentIsInitialized_expectConfigValuesToBeStored() { - val diGraph = CustomerIOStaticComponent() - val diIOSharedComponent = CustomerIOSharedComponent(context) - - val sharedPreferenceRepository: SharedPreferenceRepository = mock() - diIOSharedComponent.overrideDependency(SharedPreferenceRepository::class.java, sharedPreferenceRepository) - - val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) - instance.diSharedGraph = diIOSharedComponent - instance.attachSDKConfig(sdkConfig = cioConfig, context = context) - - verify(sharedPreferenceRepository).saveSettings(CustomerIOStoredValues(cioConfig)) - } } diff --git a/sdk/src/androidTest/java/io/customer/sdk/CustomerIOTest.kt b/sdk/src/androidTest/java/io/customer/sdk/CustomerIOTest.kt index 02314fad1..8dff4ff38 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/CustomerIOTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/CustomerIOTest.kt @@ -1,35 +1,20 @@ package io.customer.sdk import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest -import io.customer.sdk.data.model.Region -import io.customer.sdk.data.store.Client -import io.customer.sdk.di.CustomerIOSharedComponent -import io.customer.sdk.di.CustomerIOStaticComponent +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.extensions.random -import io.customer.sdk.module.CustomerIOGenericModule import io.customer.sdk.repository.CleanupRepository import io.customer.sdk.repository.DeviceRepository import io.customer.sdk.repository.ProfileRepository -import io.customer.sdk.repository.preference.CustomerIOStoredValues -import io.customer.sdk.repository.preference.SharedPreferenceRepository -import io.customer.sdk.util.CioLogLevel -import io.customer.sdk.util.Seconds -import kotlinx.coroutines.runBlocking import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBeEqualTo -import org.amshove.kluent.shouldNotBe -import org.amshove.kluent.shouldNotBeNull import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock -import org.mockito.kotlin.never -import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) -class CustomerIOTest : BaseTest() { +class CustomerIOTest : BaseIntegrationTest() { private val cleanupRepositoryMock: CleanupRepository = mock() private val deviceRepositoryMock: DeviceRepository = mock() @@ -44,76 +29,6 @@ class CustomerIOTest : BaseTest() { di.overrideDependency(ProfileRepository::class.java, profileRepositoryMock) } - @Test - fun verifySDKConfigurationSetAfterBuild() { - val givenSiteId = String.random - val givenApiKey = String.random - val builder = CustomerIO.Builder( - siteId = givenSiteId, - apiKey = givenApiKey, - region = Region.EU, - appContext = application - ) - - val client = builder.build() - - val actual = client.diGraph.sdkConfig - - actual.siteId shouldBeEqualTo givenSiteId - actual.apiKey shouldBeEqualTo givenApiKey - actual.timeout.shouldNotBeNull() - actual.region shouldBeEqualTo Region.EU - actual.autoTrackScreenViews shouldBeEqualTo false - actual.trackingApiUrl shouldBeEqualTo null - actual.trackingApiHostname shouldBeEqualTo "https://track-sdk-eu.customer.io/" - actual.backgroundQueueTaskExpiredSeconds shouldBeEqualTo Seconds.fromDays(3).value - actual.backgroundQueueMinNumberOfTasks shouldBeEqualTo 10 - actual.backgroundQueueSecondsDelay shouldBeEqualTo 30.0 - actual.logLevel shouldBeEqualTo CioLogLevel.ERROR - } - - @Test - fun verifyTrackingApiHostnameUpdateAfterUpdatingTrackingApiUrl() { - val givenSiteId = String.random - val givenApiKey = String.random - val givenTrackingApiUrl = "https://local/track/" - val builder = CustomerIO.Builder( - siteId = givenSiteId, - apiKey = givenApiKey, - region = Region.EU, - appContext = application - ).autoTrackScreenViews(true) - - val client = builder.build() - - val actual = client.diGraph.sdkConfig - actual.region shouldBeEqualTo Region.EU - actual.trackingApiUrl shouldBeEqualTo null - actual.trackingApiHostname shouldBeEqualTo "https://track-sdk-eu.customer.io/" - - builder.setTrackingApiURL(givenTrackingApiUrl) - - val updatedClient = builder.build() - - val updatedConfig = updatedClient.diGraph.sdkConfig - - // region stays the same but doesn't effect trackingApiHostname - updatedConfig.region shouldBeEqualTo Region.EU - updatedConfig.trackingApiUrl shouldBeEqualTo givenTrackingApiUrl - updatedConfig.trackingApiHostname shouldBeEqualTo givenTrackingApiUrl - } - - @Test - fun deviceToken_givenGetValue_expectDeviceRepositoryGetDeviceToken() { - val givenDeviceToken = String.random - whenever(deviceRepositoryMock.getDeviceToken()).thenReturn(givenDeviceToken) - val customerIO = CustomerIO(di) - - val actual = customerIO.registeredDeviceToken - - actual shouldBeEqualTo givenDeviceToken - } - @Test fun deviceToken_testRegisterDeviceTokenWhenPreviouslyNull() { val givenDeviceToken = String.random @@ -124,177 +39,4 @@ class CustomerIOTest : BaseTest() { CustomerIO.instance().registeredDeviceToken shouldBeEqualTo givenDeviceToken } - - @Test - fun deviceAttributes_givenSetValue_expectMakeRequestToAddAttributes() { - val givenAttributes = mapOf(String.random to String.random) - val customerIO = CustomerIO(di) - - customerIO.deviceAttributes = givenAttributes - - verify(deviceRepositoryMock).addCustomDeviceAttributes(givenAttributes) - } - - @Test - fun profileAttributes_givenSetValue_expectMakeRequestToAddAttributes() { - val givenAttributes = mapOf(String.random to String.random) - val customerIO = CustomerIO(di) - customerIO.profileAttributes = givenAttributes - - verify(profileRepositoryMock).addCustomProfileAttributes(givenAttributes) - } - - @Test - fun build_givenModule_expectInitializeModule() { - val givenModule: CustomerIOGenericModule = mock().apply { - whenever(this.moduleName).thenReturn(String.random) - } - - CustomerIO.Builder( - siteId = String.random, - apiKey = String.random, - appContext = application - ).addCustomerIOModule(givenModule).build() - - verify(givenModule).initialize() - } - - @Test - fun build_givenMultipleModules_expectInitializeAllModules() { - val givenModule1: CustomerIOGenericModule = mock().apply { - whenever(this.moduleName).thenReturn(String.random) - } - val givenModule2: CustomerIOGenericModule = mock().apply { - whenever(this.moduleName).thenReturn(String.random) - } - - CustomerIO.Builder( - siteId = String.random, - apiKey = String.random, - appContext = application - ).addCustomerIOModule(givenModule1).addCustomerIOModule(givenModule2).build() - - verify(givenModule1).initialize() - verify(givenModule2).initialize() - } - - @Test - fun build_givenMultipleModulesOfSameType_expectOnlyInitializeOneModuleInstance() { - val givenModule1: CustomerIOGenericModule = mock().apply { - whenever(this.moduleName).thenReturn("shared-module-name") - } - val givenModule2: CustomerIOGenericModule = mock().apply { - whenever(this.moduleName).thenReturn("shared-module-name") - } - - CustomerIO.Builder( - siteId = String.random, - apiKey = String.random, - appContext = application - ).addCustomerIOModule(givenModule1).addCustomerIOModule(givenModule2).build() - - verify(givenModule1, never()).initialize() - verify(givenModule2).initialize() - } - - @Test - fun initializeSdk_expectRunCleanup(): Unit = runBlocking { - getRandomCustomerIOBuilder().build() - - verify(cleanupRepositoryMock).cleanup() - } - - @Test - fun givenCustomerIONotInitialized_andConfigValuesNotStored_expectNullAsInstance() { - // clear current instance - CustomerIO.clearInstance() - - val diGraph = CustomerIOStaticComponent() - val diIOSharedComponent = CustomerIOSharedComponent(context) - - val sharedPreferenceRepository = mock().apply { - whenever(this.loadSettings()).thenReturn(CustomerIOStoredValues.empty) - } - diIOSharedComponent.overrideDependency( - SharedPreferenceRepository::class.java, - sharedPreferenceRepository - ) - - val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) - instance.diSharedGraph = diIOSharedComponent - - val customerIO = CustomerIO.instanceOrNull(context) - customerIO shouldBe null - } - - @Test - fun givenCustomerIONotInitialized_andConfigValuesStored_expectCorrectValuesFromInstance() { - // clear current instance - CustomerIO.clearInstance() - - val diGraph = CustomerIOStaticComponent() - val diIOSharedComponent = CustomerIOSharedComponent(context) - - val sharedPreferenceRepository = mock().apply { - whenever(this.loadSettings()).thenReturn(CustomerIOStoredValues(cioConfig)) - } - diIOSharedComponent.overrideDependency( - SharedPreferenceRepository::class.java, - sharedPreferenceRepository - ) - - val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) - instance.diSharedGraph = diIOSharedComponent - - val customerIO = CustomerIO.instanceOrNull(context) - customerIO shouldNotBe null - - val sdkConfig = customerIO!!.diGraph.sdkConfig - sdkConfig.siteId shouldBeEqualTo cioConfig.siteId - sdkConfig.apiKey shouldBeEqualTo cioConfig.apiKey - sdkConfig.region shouldBeEqualTo cioConfig.region - sdkConfig.client.toString() shouldBeEqualTo cioConfig.client.toString() - sdkConfig.trackingApiUrl shouldBeEqualTo cioConfig.trackingApiUrl - sdkConfig.autoTrackDeviceAttributes shouldBeEqualTo cioConfig.autoTrackDeviceAttributes - sdkConfig.logLevel shouldBeEqualTo cioConfig.logLevel - sdkConfig.backgroundQueueMinNumberOfTasks shouldBeEqualTo cioConfig.backgroundQueueMinNumberOfTasks - sdkConfig.backgroundQueueSecondsDelay shouldBeEqualTo cioConfig.backgroundQueueSecondsDelay - } - - @Test - fun test_sdkConfigMapping_givenConfigParamsMap_expectCorrectlyMappedConfigValues() { - val givenConfigMap = mapOf( - Pair(CustomerIOConfig.Companion.Keys.BACKGROUND_QUEUE_MIN_NUMBER_OF_TASKS, 3), - Pair(CustomerIOConfig.Companion.Keys.BACKGROUND_QUEUE_SECONDS_DELAY, 40.0), - Pair(CustomerIOConfig.Companion.Keys.AUTO_TRACK_DEVICE_ATTRIBUTES, false), - Pair(CustomerIOConfig.Companion.Keys.LOG_LEVEL, "none"), - Pair(CustomerIOConfig.Companion.Keys.SOURCE_SDK_SOURCE, "Flutter"), - Pair(CustomerIOConfig.Companion.Keys.SOURCE_SDK_VERSION, "1.0.0") - ) - val builder = CustomerIO.Builder( - siteId = String.random, - apiKey = String.random, - region = Region.EU, - appContext = application, - config = givenConfigMap - ).build() - - val actualConfig = builder.diGraph.sdkConfig - actualConfig.backgroundQueueMinNumberOfTasks shouldBeEqualTo 3 - actualConfig.backgroundQueueSecondsDelay shouldBeEqualTo 40.0 - actualConfig.autoTrackDeviceAttributes shouldBeEqualTo false - actualConfig.logLevel shouldBeEqualTo CioLogLevel.NONE - val actualClient = Client.Flutter("1.0.0") - actualConfig.client.source shouldBeEqualTo actualClient.source - actualConfig.client.sdkVersion shouldBeEqualTo actualClient.sdkVersion - } - - private fun getRandomCustomerIOBuilder(): CustomerIO.Builder = CustomerIO.Builder( - siteId = String.random, - apiKey = String.random, - region = Region.EU, - appContext = application - ).apply { - this.overrideDiGraph = di - } } diff --git a/sdk/src/androidTest/java/io/customer/sdk/api/HttpRequestRunnerTest.kt b/sdk/src/androidTest/java/io/customer/sdk/api/HttpRequestRunnerTest.kt index 079de205d..302f0c505 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/api/HttpRequestRunnerTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/api/HttpRequestRunnerTest.kt @@ -4,7 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import io.customer.base.extenstions.add import io.customer.base.extenstions.hasPassed import io.customer.base.extenstions.subtract -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.commontest.extensions.toResponseBody import io.customer.sdk.error.CustomerIOApiErrorResponse import io.customer.sdk.error.CustomerIOApiErrorsResponse @@ -31,7 +31,7 @@ import org.mockito.kotlin.whenever import retrofit2.Response @RunWith(AndroidJUnit4::class) -class HttpRequestRunnerTest : BaseTest() { +class HttpRequestRunnerTest : BaseIntegrationTest() { private lateinit var httpRunner: HttpRequestRunnerImpl diff --git a/sdk/src/androidTest/java/io/customer/sdk/data/store/FileStorageTest.kt b/sdk/src/androidTest/java/io/customer/sdk/data/store/FileStorageTest.kt index 8f6948297..a7c1e7b57 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/data/store/FileStorageTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/data/store/FileStorageTest.kt @@ -1,14 +1,14 @@ package io.customer.sdk.data.store import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.extensions.random import org.amshove.kluent.shouldBeEqualTo import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class FileStorageTest : BaseTest() { +class FileStorageTest : BaseIntegrationTest() { private lateinit var fileStorage: FileStorage diff --git a/sdk/src/androidTest/java/io/customer/sdk/queue/QueueIntegrationTests.kt b/sdk/src/androidTest/java/io/customer/sdk/queue/QueueIntegrationTests.kt index 5d0f8c726..57844a052 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/queue/QueueIntegrationTests.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/queue/QueueIntegrationTests.kt @@ -1,7 +1,7 @@ package io.customer.sdk.queue import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.commontest.extensions.enqueueNoInternetConnection import io.customer.sdk.data.model.EventType import io.customer.sdk.extensions.random @@ -13,7 +13,7 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class QueueIntegrationTests : BaseTest() { +class QueueIntegrationTests : BaseIntegrationTest() { private lateinit var queue: Queue private lateinit var queueStorage: QueueStorage diff --git a/sdk/src/androidTest/java/io/customer/sdk/queue/QueueStorageIntegrationTest.kt b/sdk/src/androidTest/java/io/customer/sdk/queue/QueueStorageIntegrationTest.kt index 2e49f7f95..5e396a08f 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/queue/QueueStorageIntegrationTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/queue/QueueStorageIntegrationTest.kt @@ -2,7 +2,7 @@ package io.customer.sdk.queue import androidx.test.ext.junit.runners.AndroidJUnit4 import io.customer.base.extenstions.subtract -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.extensions.random import io.customer.sdk.queue.type.* import java.util.* @@ -13,7 +13,7 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class QueueStorageIntegrationTest : BaseTest() { +class QueueStorageIntegrationTest : BaseIntegrationTest() { // using real instance of FileStorage to perform integration test private lateinit var queueStorage: QueueStorageImpl diff --git a/sdk/src/androidTest/java/io/customer/sdk/repository/DeviceRepositoryTest.kt b/sdk/src/androidTest/java/io/customer/sdk/repository/DeviceRepositoryTest.kt index 815010fba..0534bda10 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/repository/DeviceRepositoryTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/repository/DeviceRepositoryTest.kt @@ -1,7 +1,7 @@ package io.customer.sdk.repository import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.data.request.Device import io.customer.sdk.extensions.random import io.customer.sdk.queue.Queue @@ -16,7 +16,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions @RunWith(AndroidJUnit4::class) -class DeviceRepositoryTest : BaseTest() { +class DeviceRepositoryTest : BaseIntegrationTest() { private val prefRepository: SitePreferenceRepository get() = di.sitePreferenceRepository diff --git a/sdk/src/androidTest/java/io/customer/sdk/repository/ProfileRepositoryTest.kt b/sdk/src/androidTest/java/io/customer/sdk/repository/ProfileRepositoryTest.kt index 0c69510ae..c000718eb 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/repository/ProfileRepositoryTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/repository/ProfileRepositoryTest.kt @@ -1,7 +1,7 @@ package io.customer.sdk.repository import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.extensions.random import io.customer.sdk.hooks.HooksManager import io.customer.sdk.hooks.ModuleHook @@ -20,7 +20,7 @@ import org.mockito.Mockito.verifyNoInteractions import org.mockito.kotlin.* @RunWith(AndroidJUnit4::class) -class ProfileRepositoryTest : BaseTest() { +class ProfileRepositoryTest : BaseIntegrationTest() { private val prefRepository: SitePreferenceRepository get() = di.sitePreferenceRepository diff --git a/sdk/src/androidTest/java/io/customer/sdk/repository/SharedPreferenceRepositoryTest.kt b/sdk/src/androidTest/java/io/customer/sdk/repository/SharedPreferenceRepositoryTest.kt index 2356505b9..44aeb7690 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/repository/SharedPreferenceRepositoryTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/repository/SharedPreferenceRepositoryTest.kt @@ -1,7 +1,7 @@ package io.customer.sdk.repository import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.repository.preference.* import java.util.* import org.amshove.kluent.shouldBeEqualTo @@ -11,7 +11,7 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class SharedPreferenceRepositoryTest : BaseTest() { +class SharedPreferenceRepositoryTest : BaseIntegrationTest() { private lateinit var prefRepository: SharedPreferenceRepository diff --git a/sdk/src/androidTest/java/io/customer/sdk/repository/SitePreferenceRepositoryTest.kt b/sdk/src/androidTest/java/io/customer/sdk/repository/SitePreferenceRepositoryTest.kt index 93571fc90..ccf2fb420 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/repository/SitePreferenceRepositoryTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/repository/SitePreferenceRepositoryTest.kt @@ -2,7 +2,7 @@ package io.customer.sdk.repository import androidx.test.ext.junit.runners.AndroidJUnit4 import io.customer.base.extenstions.unixTimeToDate -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.repository.preference.SitePreferenceRepository import io.customer.sdk.repository.preference.SitePreferenceRepositoryImpl import java.util.* @@ -14,7 +14,7 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class SitePreferenceRepositoryTest : BaseTest() { +class SitePreferenceRepositoryTest : BaseIntegrationTest() { private lateinit var prefRepository: SitePreferenceRepository diff --git a/sdk/src/androidTest/java/io/customer/sdk/repository/TrackRepositoryTest.kt b/sdk/src/androidTest/java/io/customer/sdk/repository/TrackRepositoryTest.kt index 55d7cd0dd..3fedeb875 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/repository/TrackRepositoryTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/repository/TrackRepositoryTest.kt @@ -1,7 +1,7 @@ package io.customer.sdk.repository import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import io.customer.sdk.data.model.EventType import io.customer.sdk.data.request.MetricEvent import io.customer.sdk.extensions.random @@ -17,7 +17,7 @@ import org.junit.runner.RunWith import org.mockito.kotlin.* @RunWith(AndroidJUnit4::class) -class TrackRepositoryTest : BaseTest() { +class TrackRepositoryTest : BaseIntegrationTest() { private val prefRepository: SitePreferenceRepository get() = di.sitePreferenceRepository diff --git a/sdk/src/androidTest/java/io/customer/sdk/util/SimpleTimerTest.kt b/sdk/src/androidTest/java/io/customer/sdk/util/SimpleTimerTest.kt index 6eab82cfb..ab4c84513 100644 --- a/sdk/src/androidTest/java/io/customer/sdk/util/SimpleTimerTest.kt +++ b/sdk/src/androidTest/java/io/customer/sdk/util/SimpleTimerTest.kt @@ -2,7 +2,7 @@ package io.customer.sdk.util import androidx.test.annotation.UiThreadTest import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseIntegrationTest import org.amshove.kluent.shouldBeFalse import org.amshove.kluent.shouldBeTrue import org.junit.After @@ -14,7 +14,7 @@ import org.junit.runner.RunWith * Tests must be executed on Android device, only. Running on robolectric gave false positive results. */ @RunWith(AndroidJUnit4::class) -class SimpleTimerTest : BaseTest() { +class SimpleTimerTest : BaseIntegrationTest() { private lateinit var timer: AndroidSimpleTimer diff --git a/sdk/src/test/java/io/customer/sdk/CustomerIOSharedTest.kt b/sdk/src/test/java/io/customer/sdk/CustomerIOSharedTest.kt new file mode 100644 index 000000000..7ca62af34 --- /dev/null +++ b/sdk/src/test/java/io/customer/sdk/CustomerIOSharedTest.kt @@ -0,0 +1,66 @@ +package io.customer.sdk + +import io.customer.commontest.BaseUnitTest +import io.customer.sdk.di.CustomerIOSharedComponent +import io.customer.sdk.di.CustomerIOStaticComponent +import io.customer.sdk.repository.preference.CustomerIOStoredValues +import io.customer.sdk.repository.preference.SharedPreferenceRepository +import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldNotBe +import org.junit.Test +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify + +class CustomerIOSharedTest : BaseUnitTest() { + @Test + fun verifyInstanceAccessedMultipleTimes_givenNoSpecialCondition_expectSameInstance() { + val instance1 = CustomerIOShared.instance() + val instance2 = CustomerIOShared.instance() + + instance1 shouldBeEqualTo instance2 + } + + @Test + fun verifySharedComponentInstanceAccessedMultipleTimes_givenNoSpecialCondition_expectSameInstance() { + val instance1 = CustomerIOShared.instance().initializeAndGetSharedComponent(context) + val instance2 = CustomerIOShared.instance().initializeAndGetSharedComponent(context) + + instance1 shouldBeEqualTo instance2 + } + + @Test + fun verifyDIGraphProvided_givenInstanceNotInitializedBefore_expectProvidedDIGraph() { + val instance = with(CustomerIOShared) { + clearInstance() + createInstance(diStaticGraph = staticDIComponent) + } + + instance.diStaticGraph shouldBeEqualTo staticDIComponent + } + + @Test + fun verifyAttachedWithSDK_givenNoSpecificEnvironment_expectSharedComponentToBeInitialized() { + val diGraph = CustomerIOStaticComponent() + + val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) + instance.attachSDKConfig(sdkConfig = cioConfig, context = context) + + val sharedGraph = instance.diSharedGraph + sharedGraph shouldNotBe null + } + + @Test + fun verifyAttachedWithSDK_givenSharedComponentIsInitialized_expectConfigValuesToBeStored() { + val diGraph = CustomerIOStaticComponent() + val diIOSharedComponent = CustomerIOSharedComponent(context) + + val sharedPreferenceRepository: SharedPreferenceRepository = mock() + diIOSharedComponent.overrideDependency(SharedPreferenceRepository::class.java, sharedPreferenceRepository) + + val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) + instance.diSharedGraph = diIOSharedComponent + instance.attachSDKConfig(sdkConfig = cioConfig, context = context) + + verify(sharedPreferenceRepository).saveSettings(CustomerIOStoredValues(cioConfig)) + } +} diff --git a/sdk/src/test/java/io/customer/sdk/CustomerIOTest.kt b/sdk/src/test/java/io/customer/sdk/CustomerIOTest.kt new file mode 100644 index 000000000..7322c5a6b --- /dev/null +++ b/sdk/src/test/java/io/customer/sdk/CustomerIOTest.kt @@ -0,0 +1,286 @@ +package io.customer.sdk + +import io.customer.commontest.BaseUnitTest +import io.customer.sdk.data.model.Region +import io.customer.sdk.data.store.Client +import io.customer.sdk.di.CustomerIOSharedComponent +import io.customer.sdk.di.CustomerIOStaticComponent +import io.customer.sdk.extensions.random +import io.customer.sdk.module.CustomerIOGenericModule +import io.customer.sdk.repository.CleanupRepository +import io.customer.sdk.repository.DeviceRepository +import io.customer.sdk.repository.ProfileRepository +import io.customer.sdk.repository.preference.CustomerIOStoredValues +import io.customer.sdk.repository.preference.SharedPreferenceRepository +import io.customer.sdk.util.CioLogLevel +import io.customer.sdk.util.Seconds +import kotlinx.coroutines.runBlocking +import org.amshove.kluent.shouldBe +import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldNotBe +import org.amshove.kluent.shouldNotBeNull +import org.junit.Before +import org.junit.Test +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +class CustomerIOTest : BaseUnitTest() { + + private val cleanupRepositoryMock: CleanupRepository = mock() + private val deviceRepositoryMock: DeviceRepository = mock() + private val profileRepositoryMock: ProfileRepository = mock() + + @Before + fun setUp() { + super.setup() + + di.overrideDependency(CleanupRepository::class.java, cleanupRepositoryMock) + di.overrideDependency(DeviceRepository::class.java, deviceRepositoryMock) + di.overrideDependency(ProfileRepository::class.java, profileRepositoryMock) + } + + @Test + fun verifySDKConfigurationSetAfterBuild() { + val givenSiteId = String.random + val givenApiKey = String.random + val builder = CustomerIO.Builder( + siteId = givenSiteId, + apiKey = givenApiKey, + region = Region.EU, + appContext = application + ) + + val client = builder.build() + + val actual = client.diGraph.sdkConfig + + actual.siteId shouldBeEqualTo givenSiteId + actual.apiKey shouldBeEqualTo givenApiKey + actual.timeout.shouldNotBeNull() + actual.region shouldBeEqualTo Region.EU + actual.autoTrackScreenViews shouldBeEqualTo false + actual.trackingApiUrl shouldBeEqualTo null + actual.trackingApiHostname shouldBeEqualTo "https://track-sdk-eu.customer.io/" + actual.backgroundQueueTaskExpiredSeconds shouldBeEqualTo Seconds.fromDays(3).value + actual.backgroundQueueMinNumberOfTasks shouldBeEqualTo 10 + actual.backgroundQueueSecondsDelay shouldBeEqualTo 30.0 + actual.logLevel shouldBeEqualTo CioLogLevel.ERROR + } + + @Test + fun verifyTrackingApiHostnameUpdateAfterUpdatingTrackingApiUrl() { + val givenSiteId = String.random + val givenApiKey = String.random + val givenTrackingApiUrl = "https://local/track/" + val builder = CustomerIO.Builder( + siteId = givenSiteId, + apiKey = givenApiKey, + region = Region.EU, + appContext = application + ).autoTrackScreenViews(true) + + val client = builder.build() + + val actual = client.diGraph.sdkConfig + actual.region shouldBeEqualTo Region.EU + actual.trackingApiUrl shouldBeEqualTo null + actual.trackingApiHostname shouldBeEqualTo "https://track-sdk-eu.customer.io/" + + builder.setTrackingApiURL(givenTrackingApiUrl) + + val updatedClient = builder.build() + + val updatedConfig = updatedClient.diGraph.sdkConfig + + // region stays the same but doesn't effect trackingApiHostname + updatedConfig.region shouldBeEqualTo Region.EU + updatedConfig.trackingApiUrl shouldBeEqualTo givenTrackingApiUrl + updatedConfig.trackingApiHostname shouldBeEqualTo givenTrackingApiUrl + } + + @Test + fun deviceToken_givenGetValue_expectDeviceRepositoryGetDeviceToken() { + val givenDeviceToken = String.random + whenever(deviceRepositoryMock.getDeviceToken()).thenReturn(givenDeviceToken) + val customerIO = CustomerIO(di) + + val actual = customerIO.registeredDeviceToken + + actual shouldBeEqualTo givenDeviceToken + } + + @Test + fun deviceAttributes_givenSetValue_expectMakeRequestToAddAttributes() { + val givenAttributes = mapOf(String.random to String.random) + val customerIO = CustomerIO(di) + + customerIO.deviceAttributes = givenAttributes + + verify(deviceRepositoryMock).addCustomDeviceAttributes(givenAttributes) + } + + @Test + fun profileAttributes_givenSetValue_expectMakeRequestToAddAttributes() { + val givenAttributes = mapOf(String.random to String.random) + val customerIO = CustomerIO(di) + customerIO.profileAttributes = givenAttributes + + verify(profileRepositoryMock).addCustomProfileAttributes(givenAttributes) + } + + @Test + fun build_givenModule_expectInitializeModule() { + val givenModule: CustomerIOGenericModule = mock().apply { + whenever(this.moduleName).thenReturn(String.random) + } + + CustomerIO.Builder( + siteId = String.random, + apiKey = String.random, + appContext = application + ).addCustomerIOModule(givenModule).build() + + verify(givenModule).initialize() + } + + @Test + fun build_givenMultipleModules_expectInitializeAllModules() { + val givenModule1: CustomerIOGenericModule = mock().apply { + whenever(this.moduleName).thenReturn(String.random) + } + val givenModule2: CustomerIOGenericModule = mock().apply { + whenever(this.moduleName).thenReturn(String.random) + } + + CustomerIO.Builder( + siteId = String.random, + apiKey = String.random, + appContext = application + ).addCustomerIOModule(givenModule1).addCustomerIOModule(givenModule2).build() + + verify(givenModule1).initialize() + verify(givenModule2).initialize() + } + + @Test + fun build_givenMultipleModulesOfSameType_expectOnlyInitializeOneModuleInstance() { + val givenModule1: CustomerIOGenericModule = mock().apply { + whenever(this.moduleName).thenReturn("shared-module-name") + } + val givenModule2: CustomerIOGenericModule = mock().apply { + whenever(this.moduleName).thenReturn("shared-module-name") + } + + CustomerIO.Builder( + siteId = String.random, + apiKey = String.random, + appContext = application + ).addCustomerIOModule(givenModule1).addCustomerIOModule(givenModule2).build() + + verify(givenModule1, never()).initialize() + verify(givenModule2).initialize() + } + + @Test + fun initializeSdk_expectRunCleanup(): Unit = runBlocking { + getRandomCustomerIOBuilder().build() + + verify(cleanupRepositoryMock).cleanup() + } + + @Test + fun givenCustomerIONotInitialized_andConfigValuesNotStored_expectNullAsInstance() { + // clear current instance + CustomerIO.clearInstance() + + val diGraph = CustomerIOStaticComponent() + val diIOSharedComponent = CustomerIOSharedComponent(context) + + val sharedPreferenceRepository = mock().apply { + whenever(this.loadSettings()).thenReturn(CustomerIOStoredValues.empty) + } + diIOSharedComponent.overrideDependency( + SharedPreferenceRepository::class.java, + sharedPreferenceRepository + ) + + val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) + instance.diSharedGraph = diIOSharedComponent + + val customerIO = CustomerIO.instanceOrNull(context) + customerIO shouldBe null + } + + @Test + fun givenCustomerIONotInitialized_andConfigValuesStored_expectCorrectValuesFromInstance() { + // clear current instance + CustomerIO.clearInstance() + + val diGraph = CustomerIOStaticComponent() + val diIOSharedComponent = CustomerIOSharedComponent(context) + + val sharedPreferenceRepository = mock().apply { + whenever(this.loadSettings()).thenReturn(CustomerIOStoredValues(cioConfig)) + } + diIOSharedComponent.overrideDependency( + SharedPreferenceRepository::class.java, + sharedPreferenceRepository + ) + + val instance = CustomerIOShared.createInstance(diStaticGraph = diGraph) + instance.diSharedGraph = diIOSharedComponent + + val customerIO = CustomerIO.instanceOrNull(context) + customerIO shouldNotBe null + + val sdkConfig = customerIO!!.diGraph.sdkConfig + sdkConfig.siteId shouldBeEqualTo cioConfig.siteId + sdkConfig.apiKey shouldBeEqualTo cioConfig.apiKey + sdkConfig.region shouldBeEqualTo cioConfig.region + sdkConfig.client.toString() shouldBeEqualTo cioConfig.client.toString() + sdkConfig.trackingApiUrl shouldBeEqualTo cioConfig.trackingApiUrl + sdkConfig.autoTrackDeviceAttributes shouldBeEqualTo cioConfig.autoTrackDeviceAttributes + sdkConfig.logLevel shouldBeEqualTo cioConfig.logLevel + sdkConfig.backgroundQueueMinNumberOfTasks shouldBeEqualTo cioConfig.backgroundQueueMinNumberOfTasks + sdkConfig.backgroundQueueSecondsDelay shouldBeEqualTo cioConfig.backgroundQueueSecondsDelay + } + + @Test + fun test_sdkConfigMapping_givenConfigParamsMap_expectCorrectlyMappedConfigValues() { + val givenConfigMap = mapOf( + Pair(CustomerIOConfig.Companion.Keys.BACKGROUND_QUEUE_MIN_NUMBER_OF_TASKS, 3), + Pair(CustomerIOConfig.Companion.Keys.BACKGROUND_QUEUE_SECONDS_DELAY, 40.0), + Pair(CustomerIOConfig.Companion.Keys.AUTO_TRACK_DEVICE_ATTRIBUTES, false), + Pair(CustomerIOConfig.Companion.Keys.LOG_LEVEL, "none"), + Pair(CustomerIOConfig.Companion.Keys.SOURCE_SDK_SOURCE, "Flutter"), + Pair(CustomerIOConfig.Companion.Keys.SOURCE_SDK_VERSION, "1.0.0") + ) + val builder = CustomerIO.Builder( + siteId = String.random, + apiKey = String.random, + region = Region.EU, + appContext = application, + config = givenConfigMap + ).build() + + val actualConfig = builder.diGraph.sdkConfig + actualConfig.backgroundQueueMinNumberOfTasks shouldBeEqualTo 3 + actualConfig.backgroundQueueSecondsDelay shouldBeEqualTo 40.0 + actualConfig.autoTrackDeviceAttributes shouldBeEqualTo false + actualConfig.logLevel shouldBeEqualTo CioLogLevel.NONE + val actualClient = Client.Flutter("1.0.0") + actualConfig.client.source shouldBeEqualTo actualClient.source + actualConfig.client.sdkVersion shouldBeEqualTo actualClient.sdkVersion + } + + private fun getRandomCustomerIOBuilder(): CustomerIO.Builder = CustomerIO.Builder( + siteId = String.random, + apiKey = String.random, + region = Region.EU, + appContext = application + ).apply { + this.overrideDiGraph = di + } +} diff --git a/sdk/src/test/java/io/customer/sdk/api/HttpRetryPolicyTest.kt b/sdk/src/test/java/io/customer/sdk/api/HttpRetryPolicyTest.kt index f17605e9b..b3843b212 100644 --- a/sdk/src/test/java/io/customer/sdk/api/HttpRetryPolicyTest.kt +++ b/sdk/src/test/java/io/customer/sdk/api/HttpRetryPolicyTest.kt @@ -1,16 +1,13 @@ package io.customer.sdk.api -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.util.Seconds import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldNotBeEqualTo import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class HttpRetryPolicyTest : BaseTest() { +class HttpRetryPolicyTest : BaseUnitTest() { private lateinit var retryPolicy: CustomerIOApiRetryPolicy diff --git a/sdk/src/test/java/io/customer/sdk/data/moshi/adapter/CustomAttributesAdapterTest.kt b/sdk/src/test/java/io/customer/sdk/data/moshi/adapter/CustomAttributesAdapterTest.kt index 9021fd04d..da7d08b0b 100644 --- a/sdk/src/test/java/io/customer/sdk/data/moshi/adapter/CustomAttributesAdapterTest.kt +++ b/sdk/src/test/java/io/customer/sdk/data/moshi/adapter/CustomAttributesAdapterTest.kt @@ -1,16 +1,13 @@ package io.customer.sdk.data.moshi.adapter -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.utils.TestCustomAttributesDataSet import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeFalse import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class CustomAttributesAdapterTest : BaseTest() { +class CustomAttributesAdapterTest : BaseUnitTest() { private lateinit var adapter: CustomAttributesAdapter diff --git a/sdk/src/test/java/io/customer/sdk/data/store/ClientTest.kt b/sdk/src/test/java/io/customer/sdk/data/store/ClientTest.kt index b6f56315c..c8d7f78ff 100644 --- a/sdk/src/test/java/io/customer/sdk/data/store/ClientTest.kt +++ b/sdk/src/test/java/io/customer/sdk/data/store/ClientTest.kt @@ -1,13 +1,10 @@ package io.customer.sdk.data.store -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import org.amshove.kluent.shouldBeEqualTo import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class ClientTest : BaseTest() { +class ClientTest : BaseUnitTest() { @Test fun initialize_givenAndroid_expectAndroidClient() { val androidClient = Client.Android(sdkVersion = "2.6.3") diff --git a/sdk/src/test/java/io/customer/sdk/data/store/DeviceStoreTest.kt b/sdk/src/test/java/io/customer/sdk/data/store/DeviceStoreTest.kt index d62e8cf3e..597e7a177 100644 --- a/sdk/src/test/java/io/customer/sdk/data/store/DeviceStoreTest.kt +++ b/sdk/src/test/java/io/customer/sdk/data/store/DeviceStoreTest.kt @@ -1,13 +1,10 @@ package io.customer.sdk.data.store -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import org.amshove.kluent.shouldBeEqualTo import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class DeviceStoreTest : BaseTest() { +class DeviceStoreTest : BaseUnitTest() { @Test fun verifyBuildAttributesInDevice() { diff --git a/sdk/src/test/java/io/customer/sdk/data/store/FileTypeTest.kt b/sdk/src/test/java/io/customer/sdk/data/store/FileTypeTest.kt index 7f7c02565..7322d9bb6 100644 --- a/sdk/src/test/java/io/customer/sdk/data/store/FileTypeTest.kt +++ b/sdk/src/test/java/io/customer/sdk/data/store/FileTypeTest.kt @@ -1,15 +1,12 @@ package io.customer.sdk.data.store -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.extensions.random import java.io.File import org.amshove.kluent.shouldBeEqualTo import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class FileTypeTest : BaseTest() { +class FileTypeTest : BaseUnitTest() { val testPath = "/path/to/file/io.customer" val existingPath = File(testPath) diff --git a/sdk/src/test/java/io/customer/sdk/hook/HookManagerTest.kt b/sdk/src/test/java/io/customer/sdk/hook/HookManagerTest.kt index f62d46568..4a76a3df3 100644 --- a/sdk/src/test/java/io/customer/sdk/hook/HookManagerTest.kt +++ b/sdk/src/test/java/io/customer/sdk/hook/HookManagerTest.kt @@ -1,7 +1,6 @@ package io.customer.sdk.hook -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.extensions.random import io.customer.sdk.hooks.CioHooksManager import io.customer.sdk.hooks.HookModule @@ -11,10 +10,8 @@ import org.amshove.kluent.internal.assertEquals import org.amshove.kluent.shouldBeEqualTo import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -internal class HookManagerTest : BaseTest() { +internal class HookManagerTest : BaseUnitTest() { private lateinit var cioHooksManager: CioHooksManager diff --git a/sdk/src/test/java/io/customer/sdk/queue/QueueQueryRunnerTest.kt b/sdk/src/test/java/io/customer/sdk/queue/QueueQueryRunnerTest.kt index 430ec2e0f..ec932842d 100644 --- a/sdk/src/test/java/io/customer/sdk/queue/QueueQueryRunnerTest.kt +++ b/sdk/src/test/java/io/customer/sdk/queue/QueueQueryRunnerTest.kt @@ -1,7 +1,6 @@ package io.customer.sdk.queue -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.extensions.random import io.customer.sdk.queue.type.QueueTaskMetadata import org.amshove.kluent.shouldBeEqualTo @@ -9,10 +8,8 @@ import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldNotBeEqualTo import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class QueueQueryRunnerTest : BaseTest() { +class QueueQueryRunnerTest : BaseUnitTest() { private lateinit var queryRunner: QueueQueryRunnerImpl diff --git a/sdk/src/test/java/io/customer/sdk/queue/QueueRunRequestTest.kt b/sdk/src/test/java/io/customer/sdk/queue/QueueRunRequestTest.kt index 21dcc2019..cb4cfa950 100644 --- a/sdk/src/test/java/io/customer/sdk/queue/QueueRunRequestTest.kt +++ b/sdk/src/test/java/io/customer/sdk/queue/QueueRunRequestTest.kt @@ -1,18 +1,25 @@ package io.customer.sdk.queue -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.error.CustomerIOError import io.customer.sdk.extensions.random -import io.customer.sdk.queue.type.* +import io.customer.sdk.queue.type.QueueModifyResult +import io.customer.sdk.queue.type.QueueStatus +import io.customer.sdk.queue.type.QueueTask +import io.customer.sdk.queue.type.QueueTaskMetadata +import io.customer.sdk.queue.type.QueueTaskRunResults import kotlinx.coroutines.runBlocking import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.kotlin.* - -@RunWith(AndroidJUnit4::class) -class QueueRunRequestTest : BaseTest() { +import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull +import org.mockito.kotlin.eq +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +class QueueRunRequestTest : BaseUnitTest() { private lateinit var runRequest: QueueRunRequestImpl diff --git a/sdk/src/test/java/io/customer/sdk/queue/QueueTest.kt b/sdk/src/test/java/io/customer/sdk/queue/QueueTest.kt index ec44eac80..3e1ec6c6a 100644 --- a/sdk/src/test/java/io/customer/sdk/queue/QueueTest.kt +++ b/sdk/src/test/java/io/customer/sdk/queue/QueueTest.kt @@ -1,8 +1,7 @@ package io.customer.sdk.queue -import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.moshi.JsonClass -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import io.customer.sdk.extensions.random import io.customer.sdk.queue.type.QueueModifyResult import io.customer.sdk.queue.type.QueueStatus @@ -15,12 +14,17 @@ import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeNull import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.kotlin.* +import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull +import org.mockito.kotlin.eq +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.nullableArgumentCaptor +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever @ExperimentalCoroutinesApi -@RunWith(AndroidJUnit4::class) -class QueueTest : BaseTest() { +class QueueTest : BaseUnitTest() { private lateinit var queue: QueueImpl val storageMock: QueueStorage = mock() diff --git a/sdk/src/test/java/io/customer/sdk/util/JsonAdapterTest.kt b/sdk/src/test/java/io/customer/sdk/util/JsonAdapterTest.kt index 58e53ce99..5e3de2fd9 100644 --- a/sdk/src/test/java/io/customer/sdk/util/JsonAdapterTest.kt +++ b/sdk/src/test/java/io/customer/sdk/util/JsonAdapterTest.kt @@ -1,8 +1,7 @@ package io.customer.sdk.util -import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.moshi.JsonClass -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import org.amshove.kluent.AnyException import org.amshove.kluent.invoking import org.amshove.kluent.shouldBeEqualTo @@ -10,10 +9,8 @@ import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldNotBeNull import org.amshove.kluent.shouldThrow import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class JsonAdapterTest : BaseTest() { +class JsonAdapterTest : BaseUnitTest() { @JsonClass(generateAdapter = true) data class TestVo( diff --git a/sdk/src/test/java/io/customer/sdk/util/LoggerTest.kt b/sdk/src/test/java/io/customer/sdk/util/LoggerTest.kt index 72127c522..84e4fb19f 100644 --- a/sdk/src/test/java/io/customer/sdk/util/LoggerTest.kt +++ b/sdk/src/test/java/io/customer/sdk/util/LoggerTest.kt @@ -1,15 +1,12 @@ package io.customer.sdk.util -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import org.amshove.kluent.shouldBeEqualTo import org.junit.Test -import org.junit.runner.RunWith import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -@RunWith(AndroidJUnit4::class) -class LoggerTest : BaseTest() { +class LoggerTest : BaseUnitTest() { // Test log levels diff --git a/sdk/src/test/java/io/customer/sdk/util/SecondsTest.kt b/sdk/src/test/java/io/customer/sdk/util/SecondsTest.kt index f42bd3fe5..42f9cf12d 100644 --- a/sdk/src/test/java/io/customer/sdk/util/SecondsTest.kt +++ b/sdk/src/test/java/io/customer/sdk/util/SecondsTest.kt @@ -1,13 +1,10 @@ package io.customer.sdk.util -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.customer.commontest.BaseTest +import io.customer.commontest.BaseUnitTest import org.amshove.kluent.shouldBeEqualTo import org.junit.Test -import org.junit.runner.RunWith -@RunWith(AndroidJUnit4::class) -class SecondsTest : BaseTest() { +class SecondsTest : BaseUnitTest() { @Test fun toMilliseconds_givenNumberOfSeconds_expectGetMillis() { @@ -36,8 +33,7 @@ class SecondsTest : BaseTest() { } } -@RunWith(AndroidJUnit4::class) -class MillisecondsTest : BaseTest() { +class MillisecondsTest : BaseUnitTest() { @Test fun toSeconds_givenNumberOfMilliseconds_expectGetSeconds() {