Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / locationprovider / src / test / java / com / android / location / provider / LocationStubReflectionTest.kt
LocationStubReflectionTest.kt32 lines · 1.0 KiBRaw
| 1 | package com.android.location.provider |
| 2 | |
| 3 | import kotlin.test.Test |
| 4 | import kotlin.test.assertEquals |
| 5 | import kotlin.test.assertFailsWith |
| 6 | import org.junit.runner.RunWith |
| 7 | import 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) |
| 15 | class 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 | } |