|
| 1 | +/* |
| 2 | + * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package com.amplifyframework.auth.cognito.asf |
| 17 | + |
| 18 | +import android.content.Context |
| 19 | +import androidx.test.core.app.ApplicationProvider |
| 20 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.DEVICE_AGENT |
| 21 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.DEVICE_HEIGHT |
| 22 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.DEVICE_LANGUAGE |
| 23 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.DEVICE_WIDTH |
| 24 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.PLATFORM_KEY |
| 25 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.THIRD_PARTY_DEVICE_AGENT |
| 26 | +import com.amplifyframework.auth.cognito.asf.DeviceDataCollector.Companion.TIMEZONE |
| 27 | +import io.kotest.matchers.maps.shouldContainExactly |
| 28 | +import io.mockk.every |
| 29 | +import io.mockk.mockkStatic |
| 30 | +import io.mockk.unmockkStatic |
| 31 | +import java.util.SimpleTimeZone |
| 32 | +import java.util.TimeZone |
| 33 | +import org.junit.After |
| 34 | +import org.junit.Before |
| 35 | +import org.junit.Test |
| 36 | +import org.junit.runner.RunWith |
| 37 | +import org.robolectric.RobolectricTestRunner |
| 38 | +import org.robolectric.annotation.Config |
| 39 | + |
| 40 | +@RunWith(RobolectricTestRunner::class) |
| 41 | +@Config(qualifiers = "en-rUS-w75dp-h150dp") |
| 42 | +class DeviceDataCollectorTest { |
| 43 | + |
| 44 | + @Before |
| 45 | + fun setup() { |
| 46 | + mockkStatic(TimeZone::class) |
| 47 | + every { TimeZone.getDefault() } returns SimpleTimeZone(0, "UTC") |
| 48 | + } |
| 49 | + |
| 50 | + @After |
| 51 | + fun teardown() { |
| 52 | + unmockkStatic(TimeZone::class) |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + fun `returns expected values`() { |
| 57 | + val context = ApplicationProvider.getApplicationContext<Context>() |
| 58 | + |
| 59 | + val collector = DeviceDataCollector("deviceId") |
| 60 | + val data = collector.collect(context) |
| 61 | + |
| 62 | + data shouldContainExactly mapOf( |
| 63 | + TIMEZONE to "00:00", |
| 64 | + PLATFORM_KEY to "ANDROID", |
| 65 | + THIRD_PARTY_DEVICE_AGENT to "android_id", |
| 66 | + DEVICE_AGENT to "deviceId", |
| 67 | + DEVICE_LANGUAGE to "en_US", |
| 68 | + DEVICE_HEIGHT to "150", |
| 69 | + DEVICE_WIDTH to "75" |
| 70 | + ) |
| 71 | + } |
| 72 | +} |
0 commit comments