Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / library / locationprovider / src / test / java / com / android / location / provider / LocationStubReflectionTest.kt

LocationStubReflectionTest.kt32 lines · 1.0 KiBRaw
1package com.android.location.provider
2
3import kotlin.test.Test
4import kotlin.test.assertEquals
5import kotlin.test.assertFailsWith
6import org.junit.runner.RunWith
7import org.robolectric.RobolectricTestRunner
8
9/**
10 * The platform-only value types have private constructors (mirroring AOSP):
11 * their accessors exist purely as compile-time signatures and must throw the
12 * stub exception if ever invoked on the stub class itself.
13 */
14@RunWith(RobolectricTestRunner::class)
15class LocationStubReflectionTest {
16
17 private fun <T> instantiate(type: Class<T>): T {
18 val ctor = type.getDeclaredConstructor()
19 ctor.isAccessible = true
20 return ctor.newInstance()
21 }
22
23 @Test
24 fun providerRequestAccessorsThrowStub() {
25 val request = instantiate(ProviderRequestUnbundled::class.java)
26 val report = assertFailsWith<RuntimeException> { request.reportLocation }
27 assertEquals("stub", report.message)
28 val interval = assertFailsWith<RuntimeException> { request.interval }
29 assertEquals("stub", interval.message)
30 }
31
32}