From beee2e59afe52af27f57719de0b7c0181cb4db9a Mon Sep 17 00:00:00 2001 From: Rehan Date: Fri, 15 Sep 2023 18:23:10 +0500 Subject: [PATCH] added getCustomerIOBuilder --- .../commontest/BaseIntegrationTest.kt | 19 -------------- .../java/io/customer/commontest/BaseTest.kt | 26 +++++++++++++++++++ .../io/customer/commontest/BaseUnitTest.kt | 17 ------------ 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/common-test/src/main/java/io/customer/commontest/BaseIntegrationTest.kt b/common-test/src/main/java/io/customer/commontest/BaseIntegrationTest.kt index 995efaf8a..18b18fe60 100644 --- a/common-test/src/main/java/io/customer/commontest/BaseIntegrationTest.kt +++ b/common-test/src/main/java/io/customer/commontest/BaseIntegrationTest.kt @@ -4,10 +4,7 @@ import android.app.Application import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.platform.app.InstrumentationRegistry -import io.customer.sdk.CustomerIO import io.customer.sdk.CustomerIOConfig -import io.customer.sdk.data.model.Region -import io.customer.sdk.extensions.random /** * Base class for a integration test class to subclass. If you want to create unit tests, use [BaseTest]. @@ -31,20 +28,4 @@ abstract class BaseIntegrationTest : BaseTest() { di.fileStorage.deleteAllSdkFiles() di.sitePreferenceRepository.clearAll() } - - /** - * Create a new SDK instance with default configuration for integration tests. - */ - protected fun createSDKInstance() { - // Initialize the SDK but with an injected DI graph. - // Test setup should use the same SDK initialization that customers do to make test as close to production environment as possible. - CustomerIO.Builder( - siteId = siteId, - apiKey = String.random, - region = Region.US, - appContext = application - ).apply { - overrideDiGraph = di - }.build() - } } diff --git a/common-test/src/main/java/io/customer/commontest/BaseTest.kt b/common-test/src/main/java/io/customer/commontest/BaseTest.kt index 7d9054688..2da29dbc3 100644 --- a/common-test/src/main/java/io/customer/commontest/BaseTest.kt +++ b/common-test/src/main/java/io/customer/commontest/BaseTest.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.Application import android.content.Context import io.customer.commontest.util.DispatchersProviderStub +import io.customer.sdk.CustomerIO import io.customer.sdk.CustomerIOConfig import io.customer.sdk.CustomerIOShared import io.customer.sdk.data.model.Region @@ -12,6 +13,7 @@ import io.customer.sdk.data.store.DeviceStore import io.customer.sdk.di.CustomerIOComponent import io.customer.sdk.di.CustomerIOSharedComponent import io.customer.sdk.di.CustomerIOStaticComponent +import io.customer.sdk.extensions.random import io.customer.sdk.module.CustomerIOModule import io.customer.sdk.util.* import okhttp3.ResponseBody.Companion.toResponseBody @@ -133,4 +135,28 @@ abstract class BaseTest { sharedDIComponent.reset() di.reset() } + + /** + * Creates a new instance for SDK builder with default configuration for tests. + */ + protected fun getCustomerIOBuilder( + cioConfig: CustomerIOConfig = createConfig(), + siteId: String = this.siteId, + apiKey: String = String.random, + region: Region = Region.US, + application: Application = this.application + ): CustomerIO.Builder { + setup(cioConfig = cioConfig) + // Initialize the SDK but with an injected DI graph. + // Test setup should prefer using the same SDK initialization that customers do to + // make test as close to production environment as possible. + return CustomerIO.Builder( + siteId = siteId, + apiKey = apiKey, + region = region, + appContext = application + ).apply { + overrideDiGraph = di + } + } } diff --git a/common-test/src/main/java/io/customer/commontest/BaseUnitTest.kt b/common-test/src/main/java/io/customer/commontest/BaseUnitTest.kt index b9bfad0f2..c23750ec3 100644 --- a/common-test/src/main/java/io/customer/commontest/BaseUnitTest.kt +++ b/common-test/src/main/java/io/customer/commontest/BaseUnitTest.kt @@ -3,11 +3,8 @@ package io.customer.commontest import android.annotation.SuppressLint import android.app.Application import android.content.Context -import io.customer.sdk.CustomerIO import io.customer.sdk.CustomerIOConfig -import io.customer.sdk.data.model.Region import io.customer.sdk.data.store.DeviceStore -import io.customer.sdk.extensions.random import io.customer.sdk.repository.preference.SharedPreferenceRepository import io.customer.sdk.util.DateUtil import io.customer.sdk.util.DispatchersProvider @@ -41,18 +38,4 @@ abstract class BaseUnitTest : BaseTest() { di.overrideDependency(DeviceStore::class.java, deviceStore) di.overrideDependency(DispatchersProvider::class.java, dispatchersProviderStub) } - - /** - * Create a new SDK instance with default configuration for unit tests. - */ - protected fun createSDKInstance() { - CustomerIO.Builder( - siteId = siteId, - apiKey = String.random, - region = Region.US, - appContext = application - ).apply { - overrideDiGraph = di - }.build() - } }