-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add unit tests for
AndroidDeviceInfoRepository
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
parsely/src/test/java/com/parsely/parselyandroid/AndroidDeviceInfoRepositoryTest.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,78 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.shadows.ShadowBuild | ||
|
||
private const val SDK_VERSION = 33 | ||
private const val MANUFACTURER = "test manufacturer" | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(sdk = [SDK_VERSION]) | ||
internal class AndroidDeviceInfoRepositoryTest { | ||
|
||
private lateinit var sut: AndroidDeviceInfoRepository | ||
|
||
@Before | ||
fun setUp() { | ||
ShadowBuild.setManufacturer(MANUFACTURER) | ||
} | ||
|
||
@Test | ||
fun `given the advertisement id exists, when collecting device info, then parsely site uuid is advertisement id`() { | ||
// given | ||
val advertisementId = "ad id" | ||
sut = AndroidDeviceInfoRepository( | ||
advertisementIdProvider = { advertisementId }, | ||
androidIdProvider = { "android id" }) | ||
|
||
// when | ||
val result = sut.collectDeviceInfo() | ||
|
||
// then | ||
assertThat(result).isEqualTo(expectedConstantDeviceInfo + ("parsely_site_uuid" to advertisementId)) | ||
} | ||
|
||
@Test | ||
fun `given the advertisement is null and android id is not, when collecting device info, then parsely id is android id`() { | ||
// given | ||
val androidId = "android id" | ||
sut = AndroidDeviceInfoRepository( | ||
advertisementIdProvider = { null }, | ||
androidIdProvider = { androidId } | ||
) | ||
|
||
// when | ||
val result = sut.collectDeviceInfo() | ||
|
||
// then | ||
assertThat(result).isEqualTo(expectedConstantDeviceInfo + ("parsely_site_uuid" to androidId)) | ||
} | ||
|
||
@Test | ||
fun `given both advertisement id and android id are null, when collecting device info, then parsely id is empty`() { | ||
// given | ||
sut = AndroidDeviceInfoRepository( | ||
advertisementIdProvider = { null }, | ||
androidIdProvider = { null } | ||
) | ||
|
||
// when | ||
val result = sut.collectDeviceInfo() | ||
|
||
// then | ||
assertThat(result).isEqualTo(expectedConstantDeviceInfo + ("parsely_site_uuid" to "")) | ||
} | ||
|
||
private companion object { | ||
val expectedConstantDeviceInfo = mapOf( | ||
"manufacturer" to MANUFACTURER, | ||
"os" to "android", | ||
"os_version" to "$SDK_VERSION" | ||
) | ||
} | ||
} |