Skip to content

Commit

Permalink
tests: add unit tests for AndroidDeviceInfoRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Nov 14, 2023
1 parent 3bcbb38 commit c6f68bf
Showing 1 changed file with 78 additions and 0 deletions.
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"
)
}
}

0 comments on commit c6f68bf

Please sign in to comment.