@@ -15,7 +15,9 @@ import kotlin.test.BeforeTest
1515import kotlin.test.Test
1616import kotlin.test.assertEquals
1717import kotlin.test.assertNotNull
18+ import kotlin.test.assertNotSame
1819import kotlin.test.assertNull
20+ import kotlin.test.assertSame
1921import org.junit.runner.RunWith
2022import org.robolectric.annotation.Config
2123
@@ -32,7 +34,45 @@ class DeviceInfoUtilTest {
3234 .putExtra(BatteryManager .EXTRA_LEVEL , 75 )
3335 .putExtra(BatteryManager .EXTRA_PLUGGED , 0 )
3436 )
35- DeviceInfoUtil .resetInstance()
37+ }
38+
39+ @Test
40+ fun `same options reuse device info util` () {
41+ val options = SentryAndroidOptions ()
42+
43+ val first = DeviceInfoUtil .getInstance(context, options)
44+ val second = DeviceInfoUtil .getInstance(context, options)
45+
46+ assertSame(first, second)
47+ }
48+
49+ @Test
50+ fun `different options use isolated device info utils` () {
51+ val enabledOptions =
52+ SentryAndroidOptions ().apply {
53+ dataCollection.setUserInfo(true )
54+ isCollectAdditionalContext = true
55+ isEnableRootCheck = true
56+ }
57+ val disabledOptions =
58+ SentryAndroidOptions ().apply {
59+ dataCollection.setUserInfo(false )
60+ isCollectAdditionalContext = false
61+ isEnableRootCheck = false
62+ }
63+
64+ val enabled = DeviceInfoUtil .getInstance(context, enabledOptions)
65+ val disabled = DeviceInfoUtil .getInstance(context, disabledOptions)
66+ val enabledDevice = enabled.collectDeviceInformation(true , false )
67+ val disabledDevice = disabled.collectDeviceInformation(true , false )
68+
69+ assertNotSame(enabled, disabled)
70+ assertNotNull(enabledDevice.id)
71+ assertNotNull(enabledDevice.storageSize)
72+ assertNotNull(enabled.operatingSystem.isRooted)
73+ assertNull(disabledDevice.id)
74+ assertNull(disabledDevice.storageSize)
75+ assertNull(disabled.operatingSystem.isRooted)
3676 }
3777
3878 @Test
0 commit comments