Modern Apps git

← Modern-Apps.git

maps: let the unit-test source set compile, pass and lint again (#planet4)

Commit
2d7c487c8fc1229a70ab828c9f5c9e7b759eac22
Author
Vayun Mathur <[email protected]>
When
2026-11-11 21:10 UTC (24 days ago)
Parents
868294a
:maps:compileDevUnitTestKotlin failed at HEAD, so none of the maps unit
tests could run (982f7b92a noted it): FrameworkLocationManager's update
callback gained a speed argument and MapPageScope a userSpeedMps field
that the tests never followed. Fixed the 22 lambdas in the
FrameworkLocation*Slice2 tests; the MapPageScope fixtures are in the
reviews commit. Once the tests compiled, lint and detekt could see them:
- six Robolectric fixtures construct ViewModels inside setContent on
  purpose (no ViewModelStoreOwner); ViewModelConstructorInComposable is
  suppressed on those classes with the reason;
- NavigationSessionSlice3ExtraTest: one break instead of two.

Verified: :maps:testDevUnitTest (1,000+ tests) green and ./check maps
green in the toolchain container.

Diff

maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetClicksSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetClicksSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetClicksSlice2Test.ktindex 15a7c9e4d1..716fba313b 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetClicksSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetClicksSlice2Test.kt@@ -24,6 +24,9 @@ import org.junit.runner.RunWith  * label, and the Departures row a transit-stop place carries.  * Slice-2 coverage for maps (basename B, outside the slice-1 dirs).  */+// Robolectric fixtures build real ViewModels inside setContent on purpose: these tests drive+// the composables against live VM state, with no ViewModelStoreOwner to obtain them from.+@Suppress("ViewModelConstructorInComposable") @RunWith(AndroidJUnit4::class) class BottomSheetClicksSlice2Test { 
maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentVmSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentVmSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentVmSlice2Test.ktindex f16faf7143..03203d22de 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentVmSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentVmSlice2Test.kt@@ -23,6 +23,9 @@ import org.junit.runner.RunWith  * restaurant and a transit-stop place.  * Slice-2 coverage for maps (basename B, outside the slice-1 dirs).  */+// Robolectric fixtures build real ViewModels inside setContent on purpose: these tests drive+// the composables against live VM state, with no ViewModelStoreOwner to obtain them from.+@Suppress("ViewModelConstructorInComposable") @RunWith(AndroidJUnit4::class) class BottomSheetContentVmSlice2Test { 
maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetHeaderDirectionsSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetHeaderDirectionsSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetHeaderDirectionsSlice2Test.ktindex e1438db8da..cc98669a49 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetHeaderDirectionsSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetHeaderDirectionsSlice2Test.kt@@ -24,6 +24,9 @@ import org.junit.runner.RunWith  * and both routable feature types.  * Slice-2 coverage for maps (basename B, outside the slice-1 dirs).  */+// Robolectric fixtures build real ViewModels inside setContent on purpose: these tests drive+// the composables against live VM state, with no ViewModelStoreOwner to obtain them from.+@Suppress("ViewModelConstructorInComposable") @RunWith(AndroidJUnit4::class) class BottomSheetHeaderDirectionsSlice2Test { 
maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.ktindex 76c412ad5c..db90f2c678 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt@@ -26,6 +26,9 @@ import kotlin.time.Duration.Companion.minutes  * (options, markers, overlays, effects) is ordinary Compose state work and  * must survive composition without a live renderer.  */+// Robolectric fixtures build real ViewModels inside setContent on purpose: these tests drive+// the composables against live VM state, with no ViewModelStoreOwner to obtain them from.+@Suppress("ViewModelConstructorInComposable") @RunWith(RobolectricTestRunner::class) class Slice1Pass2MapSurfaceProbeTest { 
maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationLiveSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationLiveSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationLiveSlice2Test.ktindex 41bc10872f..20ed0fc918 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationLiveSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationLiveSlice2Test.kt@@ -66,7 +66,7 @@ class FrameworkLocationLiveSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val updates = mutableListOf<Pair<com.vayunmathur.library.map.GeoPoint, Float?>>()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         val live = listeners(lm)         assertTrue(live.isNotEmpty(), "listener registered")         live.forEach { it.onLocationChanged(fix()) }@@ -84,7 +84,7 @@ class FrameworkLocationLiveSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val headings = mutableListOf<Float?>()-        manager.startUpdates(onUpdateReceived = { _, heading -> headings.add(heading) })+        manager.startUpdates(onUpdateReceived = { _, heading, _ -> headings.add(heading) })         listeners(lm).forEach { it.onLocationChanged(fix(bearing = 90f)) }         manager.stop()         assertEquals(listOf<Float?>(90f), headings)@@ -98,7 +98,7 @@ class FrameworkLocationLiveSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.NETWORK_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         val live = listeners(lm)         assertTrue(live.isNotEmpty())         // One GPS fix, then a network fix 1 s later claiming 2x accuracy โ€”@@ -130,7 +130,7 @@ class FrameworkLocationLiveSlice2Test {         )         val manager = FrameworkLocationManager(context)         val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         manager.stop()         // The network fix is fresher (larger elapsedRealtimeNanos): it seeds.         assertEquals(1, points.size)@@ -149,7 +149,7 @@ class FrameworkLocationLiveSlice2Test {         )         val manager = FrameworkLocationManager(context)         val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         manager.stop()         assertEquals(0, points.size)     }@@ -161,7 +161,7 @@ class FrameworkLocationLiveSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val updates = mutableListOf<Pair<com.vayunmathur.library.map.GeoPoint, Float?>>()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         val sm = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager         // Robolectric ships no accelerometer/magnetic-field sensors, so the         // manager registers nothing โ€” but the compass listeners it *would*@@ -178,7 +178,7 @@ class FrameworkLocationLiveSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         val live = listeners(lm)         // Same spot, 1 s apart, tight accuracy: the second fix coalesces         // into the hold and does not re-emit.@@ -195,7 +195,7 @@ class FrameworkLocationLiveSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         val live = listeners(lm)         live.forEach { it.onLocationChanged(fix(timeNanos = 1_000_000_000L, accuracy = 4f)) }         // 5 m/s: travel, not noise โ€” always emits.
maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationManagerSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationManagerSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationManagerSlice2Test.ktindex ed448f2086..4921932919 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationManagerSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationManagerSlice2Test.kt@@ -25,7 +25,7 @@ class FrameworkLocationManagerSlice2Test {         val updates = mutableListOf<Pair<com.vayunmathur.library.map.GeoPoint, Float?>>()         var accuracy = -1         val listener = manager.startUpdates(-            onUpdateReceived = { point, heading -> updates.add(point to heading) },+            onUpdateReceived = { point, heading, _ -> updates.add(point to heading) },             onAccuracyReceived = { accuracy = it },         )         assertTrue(listener != null)@@ -45,9 +45,9 @@ class FrameworkLocationManagerSlice2Test {     fun `a restart after stop emits nothing stale`() {         val manager = FrameworkLocationManager(context)         val updates = mutableListOf<Pair<com.vayunmathur.library.map.GeoPoint, Float?>>()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         manager.stop()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         assertEquals(0, updates.size)         manager.stop()     }@@ -56,7 +56,7 @@ class FrameworkLocationManagerSlice2Test {     fun `magnetometer accuracy reaches the accuracy callback`() {         val manager = FrameworkLocationManager(context)         var accuracy = -1-        manager.startUpdates(onUpdateReceived = { _, _ -> }, onAccuracyReceived = { accuracy = it })+        manager.startUpdates(onUpdateReceived = { _, _, _ -> }, onAccuracyReceived = { accuracy = it })         val sensorManager =             context.getSystemService(android.content.Context.SENSOR_SERVICE) as android.hardware.SensorManager         val mag = sensorManager.getDefaultSensor(android.hardware.Sensor.TYPE_MAGNETIC_FIELD)@@ -71,7 +71,7 @@ class FrameworkLocationManagerSlice2Test {     fun `accelerometer accuracy never reaches the callback`() {         val manager = FrameworkLocationManager(context)         var accuracy = -1-        manager.startUpdates(onUpdateReceived = { _, _ -> }, onAccuracyReceived = { accuracy = it })+        manager.startUpdates(onUpdateReceived = { _, _, _ -> }, onAccuracyReceived = { accuracy = it })         val sensorManager =             context.getSystemService(android.content.Context.SENSOR_SERVICE) as android.hardware.SensorManager         val acc = sensorManager.getDefaultSensor(android.hardware.Sensor.TYPE_ACCELEROMETER)@@ -86,7 +86,7 @@ class FrameworkLocationManagerSlice2Test {     fun `a null sensor never reaches the callback`() {         val manager = FrameworkLocationManager(context)         var accuracy = -1-        manager.startUpdates(onUpdateReceived = { _, _ -> }, onAccuracyReceived = { accuracy = it })+        manager.startUpdates(onUpdateReceived = { _, _, _ -> }, onAccuracyReceived = { accuracy = it })         manager.onAccuracyChanged(null, android.hardware.SensorManager.SENSOR_STATUS_ACCURACY_HIGH)         assertEquals(-1, accuracy)         manager.stop()
maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationNoAccuracySlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationNoAccuracySlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationNoAccuracySlice2Test.ktindex 1c6022a0b8..b95823b407 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationNoAccuracySlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationNoAccuracySlice2Test.kt@@ -50,7 +50,7 @@ class FrameworkLocationNoAccuracySlice2Test {         )         val manager = FrameworkLocationManager(context)         val updates = mutableListOf<Pair<GeoPoint, Float?>>()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         manager.stop()         assertEquals(1, updates.size)         assertEquals(45f, updates[0].second)@@ -66,7 +66,7 @@ class FrameworkLocationNoAccuracySlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.NETWORK_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         val live = shadowOf(lm).requestLocationUpdateListeners         live.forEach { it.onLocationChanged(bareFix(timeNanos = 1_000_000_000L)) }         // A network fix with no accuracy stated cannot displace fresh GPS:
maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationSensorSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationSensorSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationSensorSlice2Test.ktindex 28ab61d3c8..d69353a23a 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationSensorSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationSensorSlice2Test.kt@@ -66,7 +66,7 @@ class FrameworkLocationSensorSlice2Test {         val updates = mutableListOf<Pair<GeoPoint, Float?>>()         val accuracies = mutableListOf<Int>()         manager.startUpdates(-            onUpdateReceived = { point, heading -> updates.add(point to heading) },+            onUpdateReceived = { point, heading, _ -> updates.add(point to heading) },             onAccuracyReceived = { accuracies.add(it) },         )         assertTrue(shadowOf(sm).hasListener(manager), "compass listeners registered")@@ -110,7 +110,7 @@ class FrameworkLocationSensorSlice2Test {         shadowOf(lm).setLastKnownLocation(LocationManager.GPS_PROVIDER, fix())         val manager = FrameworkLocationManager(context)         val updates = mutableListOf<Pair<GeoPoint, Float?>>()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         assertTrue(shadowOf(lm).requestLocationUpdateListeners.isEmpty())         assertEquals(0, updates.size)         manager.stop()@@ -127,7 +127,7 @@ class FrameworkLocationSensorSlice2Test {         )         val manager = FrameworkLocationManager(context)         val points = mutableListOf<GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         manager.stop()         assertEquals(1, points.size)         assertEquals(37.25, points[0].latitude)@@ -139,11 +139,11 @@ class FrameworkLocationSensorSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         shadowOf(lm).requestLocationUpdateListeners.forEach { it.onLocationChanged(fix()) }         manager.stop()         // Same fix again in a fresh session: it must emit, not be rejected as stale.-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         shadowOf(lm).requestLocationUpdateListeners.forEach { it.onLocationChanged(fix()) }         manager.stop()         assertEquals(2, points.size)@@ -157,7 +157,7 @@ class FrameworkLocationSensorSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.NETWORK_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<GeoPoint>()-        manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         val live = shadowOf(lm).requestLocationUpdateListeners         // GPS at t=1s, then a network fix 11 s later (GPS stale) far away: taken.         live.forEach { it.onLocationChanged(fix(timeNanos = 1_000_000_000L)) }
maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationStopSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationStopSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationStopSlice2Test.ktindex 7860d92c4f..4a647fca5a 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationStopSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationStopSlice2Test.kt@@ -58,7 +58,7 @@ class FrameworkLocationStopSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val points = mutableListOf<GeoPoint>()-        val listener = manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+        val listener = manager.startUpdates(onUpdateReceived = { point, _, _ -> points.add(point) })         @Suppress("DEPRECATION")         listener.onStatusChanged(LocationManager.GPS_PROVIDER, 2, Bundle())         listener.onLocationChanged(fix())@@ -79,7 +79,7 @@ class FrameworkLocationStopSlice2Test {         shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)         val manager = FrameworkLocationManager(context)         val updates = mutableListOf<Pair<GeoPoint, Float?>>()-        manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+        manager.startUpdates(onUpdateReceived = { point, heading, _ -> updates.add(point to heading) })         shadowOf(lm).requestLocationUpdateListeners.forEach { it.onLocationChanged(fix()) }         assertEquals(1, updates.size)         // All-zero accel/mag readings cannot form a rotation matrix.
maps/src/test/java/com/vayunmathur/maps/util/NavigationSessionSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/NavigationSessionSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/NavigationSessionSlice3ExtraTest.ktindex 41c180027c..55cc20ffeb 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/NavigationSessionSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/NavigationSessionSlice3ExtraTest.kt@@ -154,8 +154,12 @@ class NavigationSessionSlice3ExtraTest {         var sawRecalc = false         while (System.currentTimeMillis() < deadline) {             val s = NavigationSessionManager.state.value-            if (s is NavigationSessionManager.NavState.Recalculating) { sawRecalc = true; break }-            if (s is NavigationSessionManager.NavState.Failed) { sawRecalc = true; break }+            if (s is NavigationSessionManager.NavState.Recalculating ||+                s is NavigationSessionManager.NavState.Failed+            ) {+                sawRecalc = true+                break+            }             Thread.sleep(200)             // Nudge with another off-route fix via a fresh registration is not possible;             // the debounce is on fix timestamps, so simply waiting is the honest drive.