library/locationprovider: stub accessor coverage via reflection (#tests)
- Commit
1398d177e0b524ad6fcf0ffc22f2809007a4ab5a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 14:03 UTC (20 days ago)
- Parents
ce5870a
ProviderRequestUnbundled is covered by instantiating its private constructor reflectively and asserting both accessors throw the stub exception. GeocoderParams lives in the android.location package, which Robolectric loads from the boot classpath (shadowing the module stub), so a plain-JVM test covers its stub contract instead. Coverage: library/locationprovider 58.3% (28/48) -> 100% (48/48). Verified: :library:locationprovider:testDebugUnitTest, detekt and lint green without the ignore-failures init script.
Diff
library/locationprovider/src/test/java/com/android/location/provider/GeocoderParamsJvmTest.kt
diff --git a/library/locationprovider/src/test/java/com/android/location/provider/GeocoderParamsJvmTest.kt b/library/locationprovider/src/test/java/com/android/location/provider/GeocoderParamsJvmTest.ktnew file mode 100644index 0000000000..8b466b32e8--- /dev/null+++ b/library/locationprovider/src/test/java/com/android/location/provider/GeocoderParamsJvmTest.kt@@ -0,0 +1,24 @@+package com.android.location.provider++import android.location.GeocoderParams+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFailsWith++/**+ * Plain-JVM (no Robolectric): the `android.location` package is loaded from+ * the boot classpath under Robolectric, which shadows this module's stub.+ * On a plain classpath the module class wins, so its stub contract is+ * directly observable here.+ */+class GeocoderParamsJvmTest {++ @Test+ fun geocoderParamsAccessorsThrowStub() {+ val ctor = GeocoderParams::class.java.getDeclaredConstructor()+ ctor.isAccessible = true+ val params = ctor.newInstance()+ assertEquals("stub", assertFailsWith<RuntimeException> { params.locale }.message)+ assertEquals("stub", assertFailsWith<RuntimeException> { params.clientPackage }.message)+ }+}
library/locationprovider/src/test/java/com/android/location/provider/LocationStubReflectionTest.kt
diff --git a/library/locationprovider/src/test/java/com/android/location/provider/LocationStubReflectionTest.kt b/library/locationprovider/src/test/java/com/android/location/provider/LocationStubReflectionTest.ktnew file mode 100644index 0000000000..68888a324b--- /dev/null+++ b/library/locationprovider/src/test/java/com/android/location/provider/LocationStubReflectionTest.kt@@ -0,0 +1,34 @@+package com.android.location.provider++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFailsWith+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++/**+ * The platform-only value types have private constructors (mirroring AOSP):+ * their accessors exist purely as compile-time signatures and must throw the+ * stub exception if ever invoked on the stub class itself.+ */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [34])+class LocationStubReflectionTest {++ private fun <T> instantiate(type: Class<T>): T {+ val ctor = type.getDeclaredConstructor()+ ctor.isAccessible = true+ return ctor.newInstance()+ }++ @Test+ fun providerRequestAccessorsThrowStub() {+ val request = instantiate(ProviderRequestUnbundled::class.java)+ val report = assertFailsWith<RuntimeException> { request.reportLocation }+ assertEquals("stub", report.message)+ val interval = assertFailsWith<RuntimeException> { request.interval }+ assertEquals("stub", interval.message)+ }++}