-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK-3455] Unit tests for StoreProvider (#516)
* feat(inapp): add unit tests for provideInAppStore, provideImpressionStore and provideLegacyInAppStore * feat(inapp): add unit tests for constructStorePreferenceName method
- Loading branch information
1 parent
3ff037e
commit 2ced664
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/StoreProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.clevertap.android.sdk.inapp | ||
|
||
import android.content.Context | ||
import com.clevertap.android.sdk.Constants | ||
import com.clevertap.android.sdk.DeviceInfo | ||
import com.clevertap.android.sdk.STORE_TYPE_IMPRESSION | ||
import com.clevertap.android.sdk.STORE_TYPE_INAPP | ||
import com.clevertap.android.sdk.STORE_TYPE_LEGACY_INAPP | ||
import com.clevertap.android.sdk.StoreProvider | ||
import com.clevertap.android.sdk.cryption.CryptHandler | ||
import com.clevertap.android.sdk.inapp.store.preference.ImpressionStore | ||
import com.clevertap.android.sdk.inapp.store.preference.InAppStore | ||
import com.clevertap.android.sdk.inapp.store.preference.LegacyInAppStore | ||
import io.mockk.* | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class StoreProviderTest { | ||
|
||
private lateinit var mockContext: Context | ||
private lateinit var mockCryptHandler: CryptHandler | ||
private lateinit var mockDeviceInfo: DeviceInfo | ||
private lateinit var storeProvider: StoreProvider | ||
|
||
@Before | ||
fun setup() { | ||
mockContext = mockk(relaxed = true) | ||
mockCryptHandler = mockk() | ||
mockDeviceInfo = mockk(relaxed = true) | ||
storeProvider = spyk(StoreProvider.getInstance()) | ||
} | ||
|
||
@Test | ||
fun `provideInAppStore should create InAppStore with correct preferences`() { | ||
// Arrange | ||
val accountId = "testAccountId" | ||
val prefName = "${Constants.INAPP_KEY}:${mockDeviceInfo.deviceID}:$accountId" | ||
every { storeProvider.constructStorePreferenceName(STORE_TYPE_INAPP, mockDeviceInfo.deviceID, accountId) } returns prefName | ||
|
||
// Act | ||
val inAppStore = storeProvider.provideInAppStore(mockContext, mockCryptHandler, mockDeviceInfo, accountId) | ||
|
||
// Assert | ||
verify { storeProvider.getCTPreference(mockContext, prefName) } | ||
assertEquals(InAppStore::class.java, inAppStore.javaClass) | ||
} | ||
|
||
@Test | ||
fun `provideImpressionStore should create ImpressionStore with correct preferences`() { | ||
// Arrange | ||
val accountId = "testAccountId" | ||
val prefName = "${Constants.KEY_COUNTS_PER_INAPP}:${mockDeviceInfo.deviceID}:$accountId" | ||
every { storeProvider.constructStorePreferenceName(STORE_TYPE_IMPRESSION, mockDeviceInfo.deviceID, accountId) } returns prefName | ||
|
||
// Act | ||
val impressionStore = storeProvider.provideImpressionStore(mockContext, mockDeviceInfo, accountId) | ||
|
||
// Assert | ||
verify { storeProvider.getCTPreference(mockContext, prefName) } | ||
assertEquals(ImpressionStore::class.java, impressionStore.javaClass) | ||
} | ||
|
||
@Test | ||
fun `provideLegacyInAppStore should create LegacyInAppStore with correct preferences`() { | ||
// Arrange | ||
val accountId = "testAccountId" | ||
val prefName = Constants.CLEVERTAP_STORAGE_TAG | ||
every { storeProvider.constructStorePreferenceName(STORE_TYPE_LEGACY_INAPP) } returns prefName | ||
|
||
// Act | ||
val legacyInAppStore = storeProvider.provideLegacyInAppStore(mockContext, accountId) | ||
|
||
// Assert | ||
verify { storeProvider.getCTPreference(mockContext, prefName) } | ||
assertEquals(LegacyInAppStore::class.java, legacyInAppStore.javaClass) | ||
} | ||
|
||
@Test | ||
fun `constructStorePreferenceName should construct correct preference name for InApp`() { | ||
// Act | ||
val prefName = storeProvider.constructStorePreferenceName(STORE_TYPE_INAPP, "deviceId", "accountId") | ||
|
||
// Assert | ||
assertEquals("${Constants.INAPP_KEY}:deviceId:accountId", prefName) | ||
} | ||
|
||
@Test | ||
fun `constructStorePreferenceName should construct correct preference name for Impression`() { | ||
// Act | ||
val prefName = storeProvider.constructStorePreferenceName(STORE_TYPE_IMPRESSION, "deviceId", "accountId") | ||
|
||
// Assert | ||
assertEquals("${Constants.KEY_COUNTS_PER_INAPP}:deviceId:accountId", prefName) | ||
} | ||
|
||
@Test | ||
fun `constructStorePreferenceName should construct correct preference name for LegacyInApp`() { | ||
// Act | ||
val prefName = storeProvider.constructStorePreferenceName(STORE_TYPE_LEGACY_INAPP) | ||
|
||
// Assert | ||
assertEquals(Constants.CLEVERTAP_STORAGE_TAG, prefName) | ||
} | ||
} |