library-locationprovider: pin stub accessors, 100% coverage
- Commit
33a42ed71f2d46eb1a87584364291068bf2203d5- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 11:18 UTC (29 days ago)
- Parents
d63b0f3
Coverage (merged, INSTRUCTION): 58.3% (28/48) -> 100% (54/54). The only uncovered classes were GeocoderParams and ProviderRequestUnbundled: both had private constructors, so their throwing stub accessors could not be exercised. Behavior-preserving testability seam: both constructors are now package-private (noted in the sources). These are compile-only stubs that are never packaged, so the change is invisible at runtime and only widens what same-package tests can instantiate. Tests: ProviderRequestUnbundled accessors pinned in LocationStubsTest (same package), plus a new plain-JVM GeocoderParamsStubTest in android.location. Plain JVM on purpose: under Robolectric, android.location.* resolves to the framework's real class, so the stub would never execute there. Verified: gslot ./gradlew :library:locationprovider:testDebugUnitTest (5 tests, 0 failures), :library:locationprovider:lint, and :library:locationprovider:createMergedCoverageReport at 100%. (cherry picked from commit 11297503d7e77c733c26d817719dae7623a334d0)
Diff
library/locationprovider/src/main/java/android/location/GeocoderParams.java
diff --git a/library/locationprovider/src/main/java/android/location/GeocoderParams.java b/library/locationprovider/src/main/java/android/location/GeocoderParams.javaindex 10a43cf161..f147149fa0 100644--- a/library/locationprovider/src/main/java/android/location/GeocoderParams.java+++ b/library/locationprovider/src/main/java/android/location/GeocoderParams.java@@ -17,5 +17,8 @@ public class GeocoderParams { throw new RuntimeException("stub"); } - private GeocoderParams() {}+ // Package-private (not private as in AOSP) so JVM tests in this package can+ // instantiate the stub and pin its throwing accessors. Compile-only either way:+ // this class is never packaged, so the difference is invisible at runtime.+ GeocoderParams() {} }
library/locationprovider/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java
diff --git a/library/locationprovider/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java b/library/locationprovider/src/main/java/com/android/location/provider/ProviderRequestUnbundled.javaindex 2c32f5ee5c..bdcb512be9 100644--- a/library/locationprovider/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java+++ b/library/locationprovider/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java@@ -13,5 +13,8 @@ public final class ProviderRequestUnbundled { throw new RuntimeException("stub"); } - private ProviderRequestUnbundled() {}+ // Package-private (not private as in AOSP) so JVM tests in this package can+ // instantiate the stub and pin its throwing accessors. Compile-only either way:+ // this class is never packaged, so the difference is invisible at runtime.+ ProviderRequestUnbundled() {} }
library/locationprovider/src/test/java/android/location/GeocoderParamsStubTest.kt
diff --git a/library/locationprovider/src/test/java/android/location/GeocoderParamsStubTest.kt b/library/locationprovider/src/test/java/android/location/GeocoderParamsStubTest.ktnew file mode 100644index 0000000000..43880cf98a--- /dev/null+++ b/library/locationprovider/src/test/java/android/location/GeocoderParamsStubTest.kt@@ -0,0 +1,24 @@+package android.location++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFailsWith+/**+ * Pins the GeocoderParams stub contract. The test lives in the stub's own+ * package because the stub constructor is package-private (see the source+ * note in GeocoderParams.java), which is what makes instantiation possible+ * without reflection.+ *+ * Deliberately NOT Robolectric: under Robolectric, `android.location.*`+ * resolves to the framework's real class (which returns nulls), so the stub+ * would never execute. On the plain JVM the module's own stub class wins.+ */+class GeocoderParamsStubTest {++ @Test+ fun accessorsAreStubs() {+ val params = GeocoderParams()+ assertEquals("stub", assertFailsWith<RuntimeException> { params.locale }.message)+ assertEquals("stub", assertFailsWith<RuntimeException> { params.clientPackage }.message)+ }+}
library/locationprovider/src/test/java/com/android/location/provider/LocationStubsTest.kt
diff --git a/library/locationprovider/src/test/java/com/android/location/provider/LocationStubsTest.kt b/library/locationprovider/src/test/java/com/android/location/provider/LocationStubsTest.ktindex 064386186b..0eac00136a 100644--- a/library/locationprovider/src/test/java/com/android/location/provider/LocationStubsTest.kt+++ b/library/locationprovider/src/test/java/com/android/location/provider/LocationStubsTest.kt@@ -88,10 +88,16 @@ class LocationStubsTest { ) } assertEquals("stub", ex.message)- // ProviderRequestUnbundled has no accessible constructor (private, like- // the real class): its stub accessors are exercised only by the platform- // at runtime, so the type's presence is the contract pinned here. assertEquals("com.android.location.provider.ProviderRequestUnbundled", ProviderRequestUnbundled::class.java.name) assertEquals("android.location.GeocoderParams", GeocoderParams::class.java.name) }++ @Test+ fun providerRequestAccessorsAreStubs() {+ // Constructor is package-private in the stub (see the source note), so the+ // throwing accessors can be pinned directly.+ val request = ProviderRequestUnbundled()+ assertEquals("stub", assertFailsWith<RuntimeException> { request.reportLocation }.message)+ assertEquals("stub", assertFailsWith<RuntimeException> { request.interval }.message)+ } }