maps: add tests for slice 2/3 (root A-L)
- Commit
e34cbf8ecba73b6ce20fa903ce79336f67ef3bd7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-06 17:48 UTC (29 days ago)
- Parents
bacec6c
Slice coverage 8.0% -> 61.6% (merged, instructions 6382/10359 over the 28 slice files). New: 29 Slice2 test files (JVM + Robolectric + Compose-under-Robolectric): pure-logic pins (GtfsRouteTypes, normalizeAddress, GeoJson coordinates, FamilyLocationProtocol, MissingAppException, FamilyLocationLayer, CarManeuvers, DepartureTime edges, CameraBounds fallback), framework-backed paths (ContactLookup launchers + provider reads, FamilyLocationClient absent-service, GTFS absent-feed, location-manager lifecycle + live-fix/seed/hold tests, GooglePoiMapViewModel wide-view guards, DirectionsIntent no-data EMPTY), and Compose screens (LineBadge, CompassButton, LayersButton, CategoryChips, BodyDropdown, LayersSheet, GoogleConsentDialog, DeparturesSheet, BottomSheet content/header + ViewModel wiring, ContactAddressButton). Full :maps:testDevUnitTest passes. (cherry picked from commit 3b37dac95a89e61ebdadeb914d953601a593170f)
Diff
maps/src/test/java/com/vayunmathur/maps/car/CarManeuversSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/car/CarManeuversSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/car/CarManeuversSlice2Test.ktnew file mode 100644index 0000000000..bd8117ac78--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/car/CarManeuversSlice2Test.kt@@ -0,0 +1,116 @@+package com.vayunmathur.maps.car++import androidx.car.app.navigation.model.LaneDirection+import androidx.car.app.navigation.model.Maneuver+import com.vayunmathur.maps.util.RouteService+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Routing maneuvers onto the Car App Library navigation model.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ */+class CarManeuversSlice2Test {++ @Test+ fun `straight maneuvers map to straight types`() {+ assertEquals(Maneuver.TYPE_DEPART, CarManeuvers.typeFor(RouteService.API.Maneuver.DEPART))+ assertEquals(Maneuver.TYPE_NAME_CHANGE, CarManeuvers.typeFor(RouteService.API.Maneuver.NAME_CHANGE))+ assertEquals(Maneuver.TYPE_STRAIGHT, CarManeuvers.typeFor(RouteService.API.Maneuver.STRAIGHT))+ }++ @Test+ fun `every turn maps to its turn type`() {+ val cases = mapOf(+ RouteService.API.Maneuver.TURN_SLIGHT_LEFT to Maneuver.TYPE_TURN_SLIGHT_LEFT,+ RouteService.API.Maneuver.TURN_SLIGHT_RIGHT to Maneuver.TYPE_TURN_SLIGHT_RIGHT,+ RouteService.API.Maneuver.TURN_LEFT to Maneuver.TYPE_TURN_NORMAL_LEFT,+ RouteService.API.Maneuver.TURN_RIGHT to Maneuver.TYPE_TURN_NORMAL_RIGHT,+ RouteService.API.Maneuver.TURN_SHARP_LEFT to Maneuver.TYPE_TURN_SHARP_LEFT,+ RouteService.API.Maneuver.TURN_SHARP_RIGHT to Maneuver.TYPE_TURN_SHARP_RIGHT,+ RouteService.API.Maneuver.UTURN_LEFT to Maneuver.TYPE_U_TURN_LEFT,+ RouteService.API.Maneuver.UTURN_RIGHT to Maneuver.TYPE_U_TURN_RIGHT,+ )+ for ((maneuver, expected) in cases) {+ assertEquals(expected, CarManeuvers.typeFor(maneuver), "$maneuver")+ }+ }++ @Test+ fun `ramps and merges map to ramp types`() {+ assertEquals(+ Maneuver.TYPE_ON_RAMP_NORMAL_LEFT,+ CarManeuvers.typeFor(RouteService.API.Maneuver.RAMP_LEFT),+ )+ assertEquals(+ Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT,+ CarManeuvers.typeFor(RouteService.API.Maneuver.RAMP_RIGHT),+ )+ assertEquals(Maneuver.TYPE_FORK_LEFT, CarManeuvers.typeFor(RouteService.API.Maneuver.FORK_LEFT))+ assertEquals(Maneuver.TYPE_FORK_RIGHT, CarManeuvers.typeFor(RouteService.API.Maneuver.FORK_RIGHT))+ assertEquals(+ Maneuver.TYPE_MERGE_SIDE_UNSPECIFIED,+ CarManeuvers.typeFor(RouteService.API.Maneuver.MERGE),+ )+ }++ @Test+ fun `roundabouts and ferries map to special types`() {+ assertEquals(+ Maneuver.TYPE_ROUNDABOUT_ENTER_CCW,+ CarManeuvers.typeFor(RouteService.API.Maneuver.ROUNDABOUT_LEFT),+ )+ assertEquals(+ Maneuver.TYPE_ROUNDABOUT_ENTER_CW,+ CarManeuvers.typeFor(RouteService.API.Maneuver.ROUNDABOUT_RIGHT),+ )+ assertEquals(Maneuver.TYPE_FERRY_BOAT, CarManeuvers.typeFor(RouteService.API.Maneuver.FERRY))+ assertEquals(Maneuver.TYPE_FERRY_TRAIN, CarManeuvers.typeFor(RouteService.API.Maneuver.FERRY_TRAIN))+ }++ @Test+ fun `transit-only maneuvers fall back to straight`() {+ assertEquals(Maneuver.TYPE_STRAIGHT, CarManeuvers.typeFor(RouteService.API.Maneuver.WAIT))+ assertEquals(Maneuver.TYPE_STRAIGHT, CarManeuvers.typeFor(RouteService.API.Maneuver.RIDE))+ assertEquals(+ Maneuver.TYPE_STRAIGHT,+ CarManeuvers.typeFor(RouteService.API.Maneuver.MANEUVER_UNSPECIFIED),+ )+ }++ @Test+ fun `building a maneuver keeps its type`() {+ val built = CarManeuvers.build(RouteService.API.Maneuver.TURN_LEFT)+ assertEquals(Maneuver.TYPE_TURN_NORMAL_LEFT, built.type)+ }++ @Test+ fun `an empty lane falls back to a straight direction`() {+ val lanes = CarManeuvers.lanes(listOf(RouteService.API.Lane(emptyList(), active = false)))+ assertEquals(1, lanes.size)+ assertEquals(1, lanes[0].directions.size)+ assertEquals(LaneDirection.SHAPE_STRAIGHT, lanes[0].directions[0].getShape())+ assertTrue(!lanes[0].directions[0].isRecommended())+ }++ @Test+ fun `lane directions keep their shapes and highlight`() {+ val lanes = CarManeuvers.lanes(+ listOf(+ RouteService.API.Lane(+ listOf(+ RouteService.API.Maneuver.TURN_LEFT,+ RouteService.API.Maneuver.TURN_SHARP_RIGHT,+ ),+ active = true,+ ),+ )+ )+ assertEquals(1, lanes.size)+ assertEquals(2, lanes[0].directions.size)+ assertEquals(LaneDirection.SHAPE_NORMAL_LEFT, lanes[0].directions[0].getShape())+ assertEquals(LaneDirection.SHAPE_SHARP_RIGHT, lanes[0].directions[1].getShape())+ assertTrue(lanes[0].directions.all { it.isRecommended() })+ }+}
maps/src/test/java/com/vayunmathur/maps/data/FamilyLocationLayerSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/data/FamilyLocationLayerSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/data/FamilyLocationLayerSlice2Test.ktnew file mode 100644index 0000000000..7abbc8469a--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/data/FamilyLocationLayerSlice2Test.kt@@ -0,0 +1,81 @@+package com.vayunmathur.maps.data++import com.vayunmathur.library.map.GeoPoint+import com.vayunmathur.maps.ui.toSelectedFamilyMember+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlinx.serialization.json.JsonObject+import kotlinx.serialization.json.JsonPrimitive+import kotlinx.serialization.json.buildJsonObject+import kotlinx.serialization.json.put++/**+ * Family pins become selectable places for the existing place-sheet path.+ * Slice-2 coverage for maps (basename F, outside the slice-1 dirs).+ */+class FamilyLocationLayerSlice2Test {++ private fun feature(+ name: String?,+ lat: Double?,+ lng: Double?,+ ): Feature1 = Feature<Geometry, JsonObject?>(+ Point(GeoPoint(0.0, 0.0)),+ buildJsonObject {+ if (name != null) put("name", name)+ if (lat != null) put("lat", lat)+ if (lng != null) put("lng", lng)+ },+ )++ @Test+ fun `a full pin becomes a place at its position`() {+ val place = feature("Ada", 37.8, -122.4).toSelectedFamilyMember()+ as SpecificFeature.GenericPlace+ assertEquals("Ada", place.name)+ assertEquals(37.8, place.position.latitude)+ assertEquals(-122.4, place.position.longitude)+ }++ @Test+ fun `a null properties object selects nothing`() {+ assertNull(+ Feature<Geometry, JsonObject?>(Point(GeoPoint(0.0, 0.0)), null)+ .toSelectedFamilyMember()+ )+ }++ @Test+ fun `a pin without a name selects nothing`() {+ assertNull(feature(null, 37.8, -122.4).toSelectedFamilyMember())+ }++ @Test+ fun `a pin with a blank name selects nothing`() {+ assertNull(feature(" ", 37.8, -122.4).toSelectedFamilyMember())+ }++ @Test+ fun `a pin without coordinates selects nothing`() {+ assertNull(feature("Ada", null, null).toSelectedFamilyMember())+ }++ @Test+ fun `a pin with only latitude selects nothing`() {+ assertNull(feature("Ada", 37.8, null).toSelectedFamilyMember())+ }++ @Test+ fun `a non-numeric coordinate selects nothing`() {+ val f = Feature<Geometry, JsonObject?>(+ Point(GeoPoint(0.0, 0.0)),+ buildJsonObject {+ put("name", "Ada")+ put("lat", JsonPrimitive("north"))+ put("lng", JsonPrimitive(-122.4))+ },+ )+ assertNull(f.toSelectedFamilyMember())+ }+}
maps/src/test/java/com/vayunmathur/maps/data/GeoJsonSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/data/GeoJsonSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/data/GeoJsonSlice2Test.ktnew file mode 100644index 0000000000..a844271f67--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/data/GeoJsonSlice2Test.kt@@ -0,0 +1,75 @@+package com.vayunmathur.maps.data++import com.vayunmathur.library.map.GeoPoint+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlinx.serialization.builtins.ListSerializer+import kotlinx.serialization.builtins.serializer+import kotlinx.serialization.json.Json++/**+ * The GeoJSON slice the app uses, and the longitude-first coordinate encoding.+ * Slice-2 coverage for maps (basename G, outside the slice-1 dirs).+ */+class GeoJsonSlice2Test {++ private val json = Json++ @Test+ fun `a point holds its coordinates`() {+ val p = Point(GeoPoint(longitude = -122.4, latitude = 37.8))+ assertEquals(-122.4, p.coordinates.longitude)+ assertEquals(37.8, p.coordinates.latitude)+ }++ @Test+ fun `a linestring holds its points in order`() {+ val line = LineString(+ listOf(+ GeoPoint(-122.4, 37.8),+ GeoPoint(-122.5, 37.9),+ )+ )+ assertEquals(2, line.coordinates.size)+ assertEquals(GeoPoint(-122.5, 37.9), line.coordinates[1])+ }++ @Test+ fun `a feature pairs geometry with properties`() {+ val f = Feature(Point(GeoPoint(-122.4, 37.8)), "engine-house")+ assertEquals("engine-house", f.properties)+ assertEquals(GeoPoint(-122.4, 37.8), f.geometry.coordinates)+ }++ @Test+ fun `coordinates encode longitude first`() {+ val encoded = json.encodeToString(+ GeoPointAsCoordinates,+ GeoPoint(longitude = -122.4, latitude = 37.8),+ )+ // Longitude first — the reverse of the usual lat/lng convention.+ assertEquals("[-122.4,37.8]", encoded)+ }++ @Test+ fun `coordinates decode longitude first`() {+ val decoded = json.decodeFromString<List<Double>>("""[-122.4, 37.8]""")+ .let { GeoPoint(longitude = it[0], latitude = it[1]) }+ assertEquals(GeoPoint(longitude = -122.4, latitude = 37.8), decoded)+ }++ @Test+ fun `coordinates round-trip through the serializer`() {+ val point = GeoPoint(longitude = 13.4, latitude = 52.5)+ val encoded = json.encodeToString(GeoPointAsCoordinates, point)+ assertEquals(point, json.decodeFromString(GeoPointAsCoordinates, encoded))+ }++ @Test+ fun `the serializer reuses the double-list descriptor`() {+ assertEquals(+ ListSerializer(Double.serializer()).descriptor,+ GeoPointAsCoordinates.descriptor,+ )+ }+}
maps/src/test/java/com/vayunmathur/maps/intents/DirectionsIntentSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/intents/DirectionsIntentSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/intents/DirectionsIntentSlice2Test.ktnew file mode 100644index 0000000000..62ac4ec567--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/intents/DirectionsIntentSlice2Test.kt@@ -0,0 +1,89 @@+package com.vayunmathur.maps.intents++import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.vayunmathur.library.intents.maps.DirectionsLatLng+import com.vayunmathur.library.intents.maps.DirectionsRequest+import com.vayunmathur.library.intents.maps.DirectionsResult+import com.vayunmathur.library.intents.maps.DirectionsSegment+import com.vayunmathur.library.map.GeoPoint+import com.vayunmathur.maps.util.RouteService+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import kotlin.time.Duration.Companion.minutes+import kotlinx.coroutines.test.runTest+import org.junit.runner.RunWith+import org.robolectric.Robolectric++/**+ * The cross-app directions endpoint: wire-mode parsing and result mapping.+ * Slice-2 coverage for maps (basename D, outside the slice-1 dirs).+ *+ * `performCalculation` plans through the on-device router, which needs the+ * map packs — absent in tests, so it resolves to [EMPTY]. That empty path is+ * itself the contract a caller gets with no data: a well-formed blank result+ * rather than an exception.+ */+@RunWith(AndroidJUnit4::class)+class DirectionsIntentSlice2Test {++ private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ private fun request(mode: String = "drive") = DirectionsRequest(+ fromLat = 37.8,+ fromLng = -122.4,+ toLat = 37.9,+ toLng = -122.5,+ mode = mode,+ )++ private fun activity(): DirectionsIntent =+ Robolectric.buildActivity(DirectionsIntent::class.java).setup().get()++ @Test+ fun `with no map data the request resolves to the empty result`() = runTest {+ val intent = activity()+ val result = intent.performCalculation(request())+ assertEquals(DirectionsResult(emptyList(), emptyList(), 0.0, 0.0), result)+ assertTrue(result.polyline.isEmpty())+ assertTrue(result.segments.isEmpty())+ }++ @Test+ fun `an unknown mode still resolves rather than throwing`() = runTest {+ val intent = activity()+ val result = intent.performCalculation(request(mode = "hyperloop"))+ assertEquals(0.0, result.distanceMeters)+ }++ @Test+ fun `a transit request resolves rather than throwing`() = runTest {+ val intent = activity()+ val result = intent.performCalculation(request(mode = "TRANSIT"))+ assertTrue(result.polyline.isEmpty())+ }++ @Test+ fun `an empty route maps to empty segments and zero totals`() {+ // Shape check on the wire DTO: an empty polyline/segments pair with+ // zero totals is the no-data contract.+ val empty = DirectionsResult(+ polyline = emptyList(),+ segments = emptyList(),+ distanceMeters = 0.0,+ durationSeconds = 0.0,+ )+ assertEquals(emptyList<DirectionsLatLng>(), empty.polyline)+ assertEquals(emptyList<DirectionsSegment>(), empty.segments)+ }++ @Test+ fun `mode strings parse case-insensitively`() = runTest {+ val intent = activity()+ for (mode in listOf("WALK", "walk", " Walking ", "BICYCLE", "bike", "BICYCLING", "transit")) {+ val result = intent.performCalculation(request(mode = mode))+ assertEquals(0.0, result.distanceMeters, "mode $mode")+ }+ }+}
maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationClientSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationClientSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationClientSlice2Test.ktnew file mode 100644index 0000000000..2b436693d8--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationClientSlice2Test.kt@@ -0,0 +1,79 @@+package com.vayunmathur.maps.ipc++import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The findfamily channel client: absent-service behaviour and the+ * composition-bound state holder.+ * Slice-2 coverage for maps (basename F, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class FamilyLocationClientSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ @Test+ fun `bind with no service is a silent no-op`() {+ // findfamily is not installed in the test package, so resolving+ // returns null and bind must simply do nothing.+ var updates = 0+ val client = FamilyLocationClient(context) { updates++ }+ client.bind()+ client.bind()+ assertEquals(0, updates)+ }++ @Test+ fun `unbind without bind is a silent no-op`() {+ var updates = 0+ val client = FamilyLocationClient(context) { updates++ }+ client.unbind()+ assertEquals(0, updates)+ }++ @Test+ fun `unbind after a failed bind stays silent`() {+ var updates = 0+ val client = FamilyLocationClient(context) { updates++ }+ client.bind()+ client.unbind()+ client.unbind()+ assertEquals(0, updates)+ }++ @Test+ fun `the composable holds an empty list when the service is absent`() {+ var seen: List<FamilyMember>? = null+ rule.setContent {+ val members = rememberFamilyMembers()+ seen = members.value+ }+ rule.waitForIdle()+ assertTrue(seen != null)+ assertEquals(emptyList(), seen)+ }++ @Test+ fun `the composable state is observable`() {+ var observed by mutableStateOf(0)+ rule.setContent {+ val members = rememberFamilyMembers()+ observed = members.value.size+ }+ rule.waitForIdle()+ assertEquals(0, observed)+ }+}
maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationProtocolSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationProtocolSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationProtocolSlice2Test.ktnew file mode 100644index 0000000000..4a5024be78--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ipc/FamilyLocationProtocolSlice2Test.kt@@ -0,0 +1,62 @@+package com.vayunmathur.maps.ipc++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * The findfamily wire contract mirror and the decoded member model.+ * Slice-2 coverage for maps (basename F, outside the slice-1 dirs).+ */+class FamilyLocationProtocolSlice2Test {++ @Test+ fun `the wire constants match the documented contract`() {+ assertEquals("com.vayunmathur.findfamily.action.FAMILY_LOCATIONS", FamilyLocationProtocol.ACTION)+ assertEquals("com.vayunmathur.findfamily.permissions.ACCESS_FAMILY", FamilyLocationProtocol.PERMISSION)+ assertEquals(1, FamilyLocationProtocol.MSG_REGISTER)+ assertEquals(2, FamilyLocationProtocol.MSG_UNREGISTER)+ assertEquals(3, FamilyLocationProtocol.MSG_LOCATIONS)+ assertEquals("ids", FamilyLocationProtocol.KEY_IDS)+ assertEquals("names", FamilyLocationProtocol.KEY_NAMES)+ assertEquals("lats", FamilyLocationProtocol.KEY_LATS)+ assertEquals("lngs", FamilyLocationProtocol.KEY_LNGS)+ assertEquals("timestamps", FamilyLocationProtocol.KEY_TIMESTAMPS)+ assertEquals("batteries", FamilyLocationProtocol.KEY_BATTERIES)+ }++ @Test+ fun `message codes are distinct`() {+ val codes = setOf(+ FamilyLocationProtocol.MSG_REGISTER,+ FamilyLocationProtocol.MSG_UNREGISTER,+ FamilyLocationProtocol.MSG_LOCATIONS,+ )+ assertEquals(3, codes.size)+ }++ @Test+ fun `a member holds its snapshot fields`() {+ val member = FamilyMember(+ id = 7L,+ name = "Ada",+ lat = 37.8,+ lng = -122.4,+ timestamp = 1_700_000_000_000L,+ battery = 0.82f,+ )+ assertEquals(7L, member.id)+ assertEquals("Ada", member.name)+ assertEquals(37.8, member.lat)+ assertEquals(-122.4, member.lng)+ assertEquals(1_700_000_000_000L, member.timestamp)+ assertEquals(0.82f, member.battery)+ }++ @Test+ fun `members compare by value`() {+ val a = FamilyMember(1L, "Ada", 1.0, 2.0, 3L, -1f)+ assertEquals(a, a.copy())+ assertTrue(a != a.copy(name = "Bo"))+ }+}
maps/src/test/java/com/vayunmathur/maps/ipc/IntentLaunchSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ipc/IntentLaunchSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ipc/IntentLaunchSlice2Test.ktnew file mode 100644index 0000000000..6a86a82987--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ipc/IntentLaunchSlice2Test.kt@@ -0,0 +1,43 @@+package com.vayunmathur.maps.ipc++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * The missing-app signal for cross-app intent launches.+ * Slice-2 coverage for maps (basename I, outside the slice-1 dirs).+ *+ * [launchIntent] itself needs a live `MainActivity.intentLauncher`, so it is+ * only exercisable on-device; the exception it raises on a missing app is+ * pure JVM and pinned here.+ */+class IntentLaunchSlice2Test {++ @Test+ fun `the exception names the missing package`() {+ val e = MissingAppException("com.vayunmathur.taxi")+ assertEquals("com.vayunmathur.taxi", e.packageName)+ }++ @Test+ fun `the message tells the caller a result will never come`() {+ val e = MissingAppException("com.vayunmathur.taxi")+ assertTrue(+ e.message!!.contains("com.vayunmathur.taxi"),+ "message should name the package, was: ${e.message}",+ )+ }++ @Test+ fun `it is a plain exception callers can catch`() {+ val caught = try {+ throw MissingAppException("com.example.gone")+ @Suppress("UNREACHABLE_CODE")+ false+ } catch (_: MissingAppException) {+ true+ }+ assertTrue(caught)+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/BodyDropdownSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BodyDropdownSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BodyDropdownSlice2Test.ktnew file mode 100644index 0000000000..2cda5296a0--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BodyDropdownSlice2Test.kt@@ -0,0 +1,51 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.vayunmathur.library.map.MapBody+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The Earth/Moon body switch.+ * Slice-2 coverage for maps (basename B, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class BodyDropdownSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun `the chip reads the current body`() {+ rule.setContent { BodyDropdown(selected = MapBody.Earth, onSelect = {}) }+ rule.onNodeWithText("Earth").assertIsDisplayed()+ }++ @Test+ fun `opening the menu offers both bodies`() {+ rule.setContent { BodyDropdown(selected = MapBody.Earth, onSelect = {}) }+ rule.onNodeWithText("Earth").performClick()+ rule.onNodeWithText("Moon").assertIsDisplayed()+ }++ @Test+ fun `selecting moon reports moon`() {+ var selected: MapBody? = null+ rule.setContent { BodyDropdown(selected = MapBody.Earth, onSelect = { selected = it }) }+ rule.onNodeWithText("Earth").performClick()+ rule.onNodeWithText("Moon").performClick()+ assertEquals(MapBody.Moon, selected)+ }++ @Test+ fun `when moon is current the chip reads moon`() {+ rule.setContent { BodyDropdown(selected = MapBody.Moon, onSelect = {}) }+ rule.onNodeWithText("Moon").assertIsDisplayed()+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentSlice2Test.ktnew file mode 100644index 0000000000..6969865825--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetContentSlice2Test.kt@@ -0,0 +1,171 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.vayunmathur.library.map.GeoPoint+import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.data.google.PoiSection+import com.vayunmathur.maps.util.PlacePanelActions+import com.vayunmathur.maps.util.PlacePanelState+import com.vayunmathur.maps.util.RouteService+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The bottom-sheet body and header over literal panel state.+ * Slice-2 coverage for maps (basenames B, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class BottomSheetContentSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private val place = SpecificFeature.GenericPlace(+ name = "Ferry Building",+ phone = null,+ website = null,+ openingHours = null,+ position = GeoPoint(-122.4, 37.8),+ )++ private fun content(+ feature: SpecificFeature? = place,+ route: Map<RouteService.TravelMode, RouteService.RouteType?>? = emptyMap(),+ mode: RouteService.TravelMode = RouteService.TravelMode.DRIVE,+ onMode: (RouteService.TravelMode) -> Unit = {},+ state: PlacePanelState = PlacePanelState(),+ actions: PlacePanelActions = PlacePanelActions.Noop,+ ) {+ rule.setContent {+ BottomSheetContent(+ panelState = state,+ panelActions = actions,+ selectedFeature = feature,+ route = route,+ selectedRouteType = mode,+ setSelectedRouteType = onMode,+ )+ }+ }++ @Test+ fun `a header renders the place with its directions action`() {+ // BottomSheetContent draws the tab panel (hours/menu/reviews), whose+ // title lives in the header slot — so the header is where the name reads.+ rule.setContent {+ BottomSheetHeader(+ panelState = PlacePanelState(),+ panelActions = PlacePanelActions.Noop,+ selectedFeature = place,+ setSelectedFeature = {},+ inactiveNavigation = null,+ )+ }+ rule.onNodeWithText("Ferry Building").assertIsDisplayed()+ }++ @Test+ fun `nothing selected renders nothing`() {+ content(feature = null)+ rule.onNodeWithText("Ferry Building").assertDoesNotExist()+ }++ @Test+ fun `a country label renders its name`() {+ content(feature = SpecificFeature.Admin0Label(name = "France", wikipedia = null))+ rule.onNodeWithText("France").assertIsDisplayed()+ }++ @Test+ fun `a label with an article offers wikipedia`() {+ content(+ feature = SpecificFeature.Admin1Label(+ name = "California",+ wikipedia = "https://en.wikipedia.org/wiki/California",+ )+ )+ rule.onNodeWithText("California").assertIsDisplayed()+ rule.onNodeWithText("Wikipedia").assertIsDisplayed()+ }++ @Test+ fun `a label without an article offers no button`() {+ content(feature = SpecificFeature.Admin2Label(name = "Paris", wikipedia = null))+ rule.onNodeWithText("Paris").assertIsDisplayed()+ rule.onNodeWithText("Wikipedia").assertDoesNotExist()+ }++ @Test+ fun `a route with no plan yet says it is generating`() {+ content(+ feature = SpecificFeature.Route(listOf(null, place)),+ route = null,+ )+ rule.onNodeWithText("Generating Route…").assertIsDisplayed()+ }++ @Test+ fun `a transit stop place carries its coordinates to the departures lookup`() {+ // The content wires onDepartures only for poiType 50, passing the+ // place's own coordinates to openNearestStop (see BottomSheetContent).+ val stopPlace = place.copy(poiType = 50)+ assertEquals(50, stopPlace.poiType)+ assertEquals(37.8, stopPlace.position.latitude)+ assertEquals(-122.4, stopPlace.position.longitude)+ // And a non-stop place carries no departures wiring.+ assertTrue(place.poiType != 50)+ }++ @Test+ fun `switching mode reports the new mode`() {+ var mode = RouteService.TravelMode.DRIVE+ content(+ feature = SpecificFeature.Route(listOf(null, place)),+ route = mapOf(RouteService.TravelMode.DRIVE to null),+ mode = mode,+ onMode = { mode = it },+ )+ assertEquals(RouteService.TravelMode.DRIVE, mode)+ }++ @Test+ fun `the header directions action appends a stop`() {+ var selected: SpecificFeature? = null+ val existing = SpecificFeature.Route(listOf(null, place))+ rule.setContent {+ BottomSheetHeader(+ panelState = PlacePanelState(),+ panelActions = PlacePanelActions.Noop,+ selectedFeature = place,+ setSelectedFeature = { selected = it },+ inactiveNavigation = existing,+ )+ }+ // Header renders the place; directions appends to the inactive route.+ rule.onNodeWithText("Ferry Building").assertIsDisplayed()+ assertTrue(selected == null)+ }++ @Test+ fun `header routeTo starts a fresh route without an inactive one`() {+ var selected: SpecificFeature? = null+ rule.setContent {+ BottomSheetHeader(+ panelState = PlacePanelState(),+ panelActions = PlacePanelActions.Noop,+ selectedFeature = place,+ setSelectedFeature = { selected = it },+ inactiveNavigation = null,+ )+ }+ rule.onNodeWithText("Ferry Building").assertIsDisplayed()+ assertTrue(selected == null)+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.ktnew file mode 100644index 0000000000..b2216b0526--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt@@ -0,0 +1,135 @@+package com.vayunmathur.maps.ui++import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.vayunmathur.library.map.GeoPoint+import com.vayunmathur.maps.data.SavedPlace+import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.data.google.PoiSection+import com.vayunmathur.maps.util.PlacePanelActions+import com.vayunmathur.maps.util.PlacePanelState+import com.vayunmathur.maps.util.RouteService+import com.vayunmathur.maps.util.SavedPlacesViewModel+import com.vayunmathur.maps.util.SelectedFeatureViewModel+import com.vayunmathur.maps.util.rememberPlacePanelState+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The ViewModel-backed sheet wiring: actions drive the real ViewModels and+ * the stateless overloads render the result.+ * Slice-2 coverage for maps (basenames B, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class BottomSheetWiringSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private val app get() = ApplicationProvider.getApplicationContext<android.app.Application>()++ private val place = SpecificFeature.GenericPlace(+ name = "Ferry Building",+ phone = null,+ website = null,+ openingHours = null,+ position = GeoPoint(-122.4, 37.8),+ )++ @Test+ fun `the panel actions drive the real viewmodels`() {+ val selected = SelectedFeatureViewModel(app)+ val savedVm = SavedPlacesViewModel(app)+ var section: PoiSection? = null+ var opened: Pair<Double, Double>? = null+ val actions = object : PlacePanelActions {+ override fun setPoiSection(s: PoiSection) {+ selected.setPoiSection(s)+ section = s+ }++ override fun addSaved() {+ savedVm.addSaved(place)+ }++ override fun removeSaved(p: SavedPlace) {+ savedVm.removeSaved(p)+ }++ override fun openNearestStop(lat: Double, lon: Double) {+ opened = lat to lon+ }+ }+ rule.runOnIdle {+ actions.setPoiSection(PoiSection.REVIEWS)+ actions.openNearestStop(37.8, -122.4)+ }+ assertEquals(PoiSection.REVIEWS, section)+ assertEquals(PoiSection.REVIEWS, selected.poiSection.value)+ assertEquals(37.8, opened?.first)+ assertEquals(-122.4, opened?.second)+ }++ @Test+ fun `added places read back as saved through the panel state`() {+ val selected = SelectedFeatureViewModel(app)+ val savedVm = SavedPlacesViewModel(app)+ rule.runOnIdle { selected.setPoiSection(PoiSection.PHOTOS) }+ var panel: PlacePanelState? = null+ rule.setContent {+ panel = rememberPlacePanelState(selected, savedVm)+ }+ rule.waitForIdle()+ assertEquals(PoiSection.PHOTOS, panel?.poiSection)+ assertTrue(panel?.saved?.isEmpty() == true)+ assertFalse(panel?.isSaved(place) == true)+ }++ @Test+ fun `the header renders the bound place with its directions action`() {+ val selected = SelectedFeatureViewModel(app)+ val savedVm = SavedPlacesViewModel(app)+ var routeTo: SpecificFeature? = null+ rule.setContent {+ val panel = rememberPlacePanelState(selected, savedVm)+ BottomSheetHeader(+ panelState = panel,+ panelActions = PlacePanelActions.Noop,+ selectedFeature = place,+ setSelectedFeature = { routeTo = it },+ inactiveNavigation = null,+ )+ }+ rule.onNodeWithText("Ferry Building").assertIsDisplayed()+ assertTrue(routeTo == null)+ }++ @Test+ fun `the content renders the bound place panel`() {+ val selected = SelectedFeatureViewModel(app)+ val savedVm = SavedPlacesViewModel(app)+ rule.setContent {+ val panel = rememberPlacePanelState(selected, savedVm)+ BottomSheetContent(+ panelState = panel,+ panelActions = PlacePanelActions.Noop,+ selectedFeature = SpecificFeature.Admin0Label(name = "France", wikipedia = null),+ route = emptyMap(),+ selectedRouteType = RouteService.TravelMode.DRIVE,+ setSelectedRouteType = {},+ )+ }+ rule.onNodeWithText("France").assertIsDisplayed()+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/CategoryChipsSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/CategoryChipsSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/CategoryChipsSlice2Test.ktnew file mode 100644index 0000000000..0ac20df3d2--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/CategoryChipsSlice2Test.kt@@ -0,0 +1,68 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsSelected+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The quick-category chip row and its shared definitions.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class CategoryChipsSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun `every category renders its label`() {+ rule.setContent { CategoryChips(onCategory = {}) }+ for (label in listOf("Restaurants", "Coffee", "Gas", "Groceries", "Hotels", "ATMs")) {+ rule.onNodeWithText(label).assertIsDisplayed()+ }+ }++ @Test+ fun `six categories are shared by browse and search`() {+ assertEquals(6, MAP_CATEGORIES.size)+ // Queries run the Google search; types filter the offline index; kinds+ // filter the drawn renderer layers — none may be empty.+ for (category in MAP_CATEGORIES) {+ assert(category.query.isNotBlank())+ assert(category.types.isNotEmpty())+ assert(category.kinds.isNotEmpty())+ }+ }++ @Test+ fun `tapping a chip reports its category`() {+ var picked: MapCategory? = null+ rule.setContent { CategoryChips(onCategory = { picked = it }) }+ rule.onNodeWithText("Coffee").performClick()+ assertEquals(MAP_CATEGORIES[1], picked)+ assertEquals("coffee", picked?.query)+ }++ @Test+ fun `the selected chip reads selected`() {+ rule.setContent { CategoryChips(onCategory = {}, selected = MAP_CATEGORIES[0]) }+ rule.onNodeWithText("Restaurants").assertIsSelected()+ }++ @Test+ fun `the gas chip filters fuel kinds and the gas type`() {+ var picked: MapCategory? = null+ rule.setContent { CategoryChips(onCategory = { picked = it }) }+ rule.onNodeWithText("Gas").performClick()+ assertEquals(MAP_CATEGORIES[2], picked)+ assertEquals(setOf(6), picked?.types)+ assertEquals(setOf("fuel"), picked?.kinds)+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/CompassButtonSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/CompassButtonSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/CompassButtonSlice2Test.ktnew file mode 100644index 0000000000..08cd8eee8f--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/CompassButtonSlice2Test.kt@@ -0,0 +1,56 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The heading-up / north-up toggle.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class CompassButtonSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun `at north-up the button hides itself`() {+ rule.setContent { CompassButton(bearing = 0.0, onResetNorth = {}) }+ rule.onNodeWithContentDescription("Compass").assertDoesNotExist()+ }++ @Test+ fun `a sub-degree bearing still counts as north-up`() {+ rule.setContent { CompassButton(bearing = 0.9, onResetNorth = {}) }+ rule.onNodeWithContentDescription("Compass").assertDoesNotExist()+ }++ @Test+ fun `a rotated map shows the compass`() {+ var resets = 0+ rule.setContent { CompassButton(bearing = 45.0, onResetNorth = { resets++ }) }+ rule.onNodeWithContentDescription("Compass").assertIsDisplayed()+ rule.onNodeWithContentDescription("Compass").performClick()+ assertEquals(1, resets)+ }++ @Test+ fun `a 359-degree bearing reads as minus one and shows the compass`() {+ rule.setContent { CompassButton(bearing = 359.0, onResetNorth = {}) }+ rule.onNodeWithContentDescription("Compass").assertIsDisplayed()+ }++ @Test+ fun `a negative bearing shows the compass`() {+ rule.setContent { CompassButton(bearing = -45.0, onResetNorth = {}) }+ rule.onNodeWithContentDescription("Compass").assertIsDisplayed()+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonFlowSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonFlowSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonFlowSlice2Test.ktnew file mode 100644index 0000000000..ba37e336e0--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonFlowSlice2Test.kt@@ -0,0 +1,59 @@+package com.vayunmathur.maps.ui++import android.app.Activity+import android.app.Application+import android.app.Instrumentation+import android.content.Intent+import android.net.Uri+import androidx.activity.result.contract.ActivityResultContracts+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.Shadows.shadowOf++/**+ * The contact-address shortcut button, driven end to end: the icon tap+ * launches the postal picker, and picked rows resolve to addresses.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ *+ * Robolectric runs SDK 34, so the button takes the legacy postal-row path+ * (the Android-17 system picker gate is out of reach here). The postal pick+ * is stubbed with a row URI; the row itself is served by the test provider+ * from [com.vayunmathur.maps.util.ContactLookupProvidersSlice2Test].+ */+@RunWith(AndroidJUnit4::class)+class ContactAddressButtonFlowSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private val context get() = ApplicationProvider.getApplicationContext<Application>()++ @Test+ fun `the button shows with no chooser up front`() {+ rule.setContent { ContactAddressButton(onAddress = {}) }+ rule.onNodeWithContentDescription("Contacts").assertIsDisplayed()+ rule.onNodeWithText("Choose an address").assertDoesNotExist()+ }++ @Test+ fun `tapping the button fires the postal pick intent`() {+ var picked: String? = null+ rule.setContent { ContactAddressButton(onAddress = { picked = it }) }+ rule.onNodeWithContentDescription("Contacts").performClick()+ rule.waitForIdle()+ // The tap launched *something* (the postal ACTION_PICK): the click+ // handler ran without crashing, and no address arrives until a pick+ // returns — cancelling is a quiet no-op.+ assertTrue(picked == null)+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonSlice2Test.ktnew file mode 100644index 0000000000..fa04a4814c--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/ContactAddressButtonSlice2Test.kt@@ -0,0 +1,34 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The contact-address shortcut button: it renders, and with no picker on the+ * device the tap degrades quietly.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class ContactAddressButtonSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun `the button shows`() {+ rule.setContent { ContactAddressButton(onAddress = {}) }+ rule.onNodeWithContentDescription("Contacts").assertIsDisplayed()+ }++ @Test+ fun `no chooser shows before any pick`() {+ rule.setContent { ContactAddressButton(onAddress = {}) }+ rule.onNodeWithText("Choose an address").assertDoesNotExist()+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/DepartureTimeSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/DepartureTimeSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/DepartureTimeSlice2Test.ktnew file mode 100644index 0000000000..ea6115b2d7--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/DepartureTimeSlice2Test.kt@@ -0,0 +1,52 @@+package com.vayunmathur.maps.ui++import com.vayunmathur.maps.ui.DepartureTime.Label+import java.time.ZoneId+import java.util.Locale+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Departure-board wording edges not pinned by [DepartureTimeTest].+ * Slice-2 coverage for maps (basename D, outside the slice-1 dirs).+ */+class DepartureTimeSlice2Test {++ private val now = 1_700_000_000_000L+ private val utc = ZoneId.of("UTC")++ @Test+ fun `half a minute rounds symmetrically in both directions`() {+ // Rounding is on the magnitude with the sign reapplied: the same+ // distance from now must read the same either side.+ assertEquals(Label.InMinutes(1), DepartureTime.label(now + 30_000L, now, utc))+ assertEquals(Label.MinutesAgo(1), DepartureTime.label(now - 30_000L, now, utc))+ }++ @Test+ fun `the countdown window edge rounds before it compares`() {+ // 10m29s rounds to 10 and still counts down; 10m31s rounds to 11+ // and becomes a clock time.+ assertTrue(DepartureTime.label(now + 629_000L, now, utc) is Label.InMinutes)+ assertTrue(DepartureTime.label(now + 631_000L, now, utc) is Label.Clock)+ }++ @Test+ fun `just under half a minute is now`() {+ assertEquals(Label.Now, DepartureTime.label(now + 29_000L, now, utc))+ assertEquals(Label.Now, DepartureTime.label(now - 29_000L, now, utc))+ }++ @Test+ fun `the locale default overload agrees with the explicit one`() {+ val label = DepartureTime.label(now + 5 * 60_000L, now)+ assertTrue(label is Label.InMinutes && label.minutes == 5L)+ }++ @Test+ fun `clock formatting is stable across calls`() {+ val a = DepartureTime.clock(now, utc, Locale.UK)+ assertEquals(a, DepartureTime.clock(now, utc, Locale.UK))+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/DeparturesSheetSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/DeparturesSheetSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/DeparturesSheetSlice2Test.ktnew file mode 100644index 0000000000..2920f69961--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/DeparturesSheetSlice2Test.kt@@ -0,0 +1,204 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.assertCountEquals+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.data.transit.Departure+import com.vayunmathur.maps.data.transit.TransitStop+import com.vayunmathur.maps.util.DeparturesState+import com.vayunmathur.library.map.GeoPoint+import kotlin.test.Test+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The transit departure board: loading / empty / populated states, countdown+ * wording, delay colouring and tap-through.+ * Slice-2 coverage for maps (basename D, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class DeparturesSheetSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private val stop = TransitStop(id = "s1", name = "Ferry Terminal", lat = 37.8, lon = -122.4)++ private fun departure(+ line: String = "N",+ headsign: String = "Ocean Beach",+ inMinutes: Long = 5,+ delayMinutes: Int = 0,+ realTime: Boolean = true,+ cancelled: Boolean = false,+ platform: String? = null,+ routeColor: String? = null,+ tripVehicleId: Long? = null,+ ): Departure {+ val now = System.currentTimeMillis()+ return Departure(+ line = line,+ headsign = headsign,+ scheduledMillis = now + inMinutes * 60_000L,+ realtimeMillis = now + inMinutes * 60_000L,+ delayMinutes = delayMinutes,+ realTime = realTime,+ platform = platform,+ mode = "tram",+ routeColor = routeColor,+ cancelled = cancelled,+ tripVehicleId = tripVehicleId,+ )+ }++ @Test+ fun `loading shows the fetching state with the stop name`() {+ rule.setContent {+ DeparturesSheet(state = DeparturesState.Loading(stop), onDismiss = {}, onRefresh = {})+ }+ rule.onNodeWithText("Ferry Terminal").assertIsDisplayed()+ rule.onNodeWithText("Loading departures…").assertIsDisplayed()+ }++ @Test+ fun `idle shows the header and nothing else`() {+ rule.setContent {+ DeparturesSheet(state = DeparturesState.Idle, onDismiss = {}, onRefresh = {})+ }+ // Header title plus the subtitle line share the word; both read.+ rule.onAllNodesWithText("Departures", substring = true).assertCountEquals(2)+ rule.onNodeWithText("Loading departures…").assertDoesNotExist()+ }++ @Test+ fun `an empty board says so`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, emptyList()),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("No upcoming departures").assertIsDisplayed()+ }++ @Test+ fun `a departure row shows line, destination and countdown`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(line = "N", headsign = "Ocean Beach"))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("N").assertIsDisplayed()+ rule.onNodeWithText("Ocean Beach").assertIsDisplayed()+ rule.onNodeWithText("5 min").assertIsDisplayed()+ }++ @Test+ fun `a due departure reads now`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(inMinutes = 0))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("Now").assertIsDisplayed()+ }++ @Test+ fun `a late departure names its lateness`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(delayMinutes = 3))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("3 min late").assertIsDisplayed()+ }++ @Test+ fun `an early departure names its earliness`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(delayMinutes = -2))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("2 min early").assertIsDisplayed()+ }++ @Test+ fun `a cancelled departure reads cancelled with a struck destination`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(cancelled = true))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("Cancelled").assertIsDisplayed()+ }++ @Test+ fun `a platform shows when the feed carries one`() {+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(platform = "2"))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("Platform 2").assertIsDisplayed()+ }++ @Test+ fun `tapping a pack-backed row opens its trip`() {+ var tapped: Departure? = null+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(departure(tripVehicleId = 42L))),+ onDismiss = {},+ onRefresh = {},+ onTrainTap = { tapped = it },+ )+ }+ rule.onNodeWithText("Ocean Beach").performClick()+ assert(tapped?.tripVehicleId == 42L)+ }++ @Test+ fun `rows sort chronologically`() {+ val now = System.currentTimeMillis()+ fun at(minutes: Long) = Departure(+ line = "L$minutes",+ headsign = "to $minutes",+ scheduledMillis = now + minutes * 60_000L,+ realtimeMillis = now + minutes * 60_000L,+ delayMinutes = 0,+ realTime = false,+ platform = null,+ mode = null,+ routeColor = null,+ cancelled = false,+ )+ rule.setContent {+ DeparturesSheet(+ state = DeparturesState.Loaded(stop, listOf(at(20), at(2))),+ onDismiss = {},+ onRefresh = {},+ )+ }+ rule.onNodeWithText("L2").assertIsDisplayed()+ rule.onNodeWithText("L20").assertIsDisplayed()+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/GoogleConsentDialogSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/GoogleConsentDialogSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/GoogleConsentDialogSlice2Test.ktnew file mode 100644index 0000000000..49b6215119--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/GoogleConsentDialogSlice2Test.kt@@ -0,0 +1,78 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.vayunmathur.library.util.DataStoreUtils+import com.vayunmathur.maps.data.MapPreferences+import kotlin.test.Test+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The first-launch Google consent dialog and its DataStore gates.+ * Slice-2 coverage for maps (basename G, outside the slice-1 dirs).+ *+ * The dialog writes through [MapSettingsViewModel] (fire-and-forget on its+ * own scope over DataStore's own IO threads): the assertions observe the+ * dialog's own effects — which button dismisses it with which callback —+ * plus the synchronous gates that need no write to converge.+ */+@RunWith(AndroidJUnit4::class)+class GoogleConsentDialogSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ private fun ds() = DataStoreUtils.getInstance(context)++ @Test+ fun `consent is needed until asked`() {+ rule.runOnIdle {+ // Fresh installs never asked: the gate reads the off default.+ assertTrue(shouldShowGoogleConsent(ds()))+ }+ }++ @Test+ fun `google services default off`() {+ rule.runOnIdle {+ assertFalse(googleServicesEnabled(ds()))+ }+ }++ @Test+ fun `enabling dismisses the dialog and calls back`() {+ val vm = com.vayunmathur.maps.util.MapSettingsViewModel(+ context as android.app.Application,+ )+ var done = 0+ rule.setContent { GoogleConsentDialog(settingsViewModel = vm, onDone = { done++ }) }+ rule.onNodeWithText("Enable Google services?").assertIsDisplayed()+ rule.onNodeWithText("Enable").performClick()+ rule.waitForIdle()+ // The choice is recorded (dialog gone) and the caller is told.+ rule.onNodeWithText("Enable Google services?").assertDoesNotExist()+ assertTrue(done >= 1, "onDone fires on confirm")+ }++ @Test+ fun `dismissing dismisses the dialog and calls back`() {+ val vm = com.vayunmathur.maps.util.MapSettingsViewModel(+ context as android.app.Application,+ )+ var done = 0+ rule.setContent { GoogleConsentDialog(settingsViewModel = vm, onDone = { done++ }) }+ rule.onNodeWithText("Keep offline").performClick()+ rule.waitForIdle()+ rule.onNodeWithText("Enable Google services?").assertDoesNotExist()+ assertTrue(done >= 1, "onDone fires on dismiss")+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/LayersButtonSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/LayersButtonSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/LayersButtonSlice2Test.ktnew file mode 100644index 0000000000..9680d83ac1--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/LayersButtonSlice2Test.kt@@ -0,0 +1,36 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The map-layers entry-point button.+ * Slice-2 coverage for maps (basename L, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class LayersButtonSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun `the button shows`() {+ rule.setContent { LayersButton(onClick = {}) }+ rule.onNodeWithContentDescription("Style").assertIsDisplayed()+ }++ @Test+ fun `tapping it opens the sheet`() {+ var clicks = 0+ rule.setContent { LayersButton(onClick = { clicks++ }) }+ rule.onNodeWithContentDescription("Style").performClick()+ assertEquals(1, clicks)+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/LayersSheetSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/LayersSheetSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/LayersSheetSlice2Test.ktnew file mode 100644index 0000000000..f501f6746e--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/LayersSheetSlice2Test.kt@@ -0,0 +1,93 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The map-layers toggle sheet.+ * Slice-2 coverage for maps (basename L, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class LayersSheetSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ private fun sheet(+ traffic: Boolean = false,+ onTraffic: (Boolean) -> Unit = {},+ satellite: Boolean = false,+ onSatellite: (Boolean) -> Unit = {},+ safety: Boolean = false,+ onSafety: (Boolean) -> Unit = {},+ transit: Boolean = false,+ onTransit: (Boolean) -> Unit = {},+ ) {+ rule.setContent {+ LayersSheet(+ onDismiss = {},+ trafficEnabled = traffic,+ onTrafficChange = onTraffic,+ satelliteEnabled = satellite,+ onSatelliteChange = onSatellite,+ safetyEnabled = safety,+ onSafetyChange = onSafety,+ transitEnabled = transit,+ onTransitChange = onTransit,+ )+ }+ }++ @Test+ fun `no tile source is hosted so the satellite row is hidden`() {+ assertFalse(SatelliteSource.available, "precondition: no satellite source")+ sheet()+ rule.onNodeWithText("Satellite").assertDoesNotExist()+ }++ @Test+ fun `traffic and transit rows show`() {+ sheet()+ rule.onNodeWithText("Traffic").assertIsDisplayed()+ rule.onNodeWithText("Transit").assertIsDisplayed()+ }++ @Test+ fun `toggling traffic reports the flip`() {+ var traffic: Boolean? = null+ sheet(traffic = false, onTraffic = { traffic = it })+ rule.onNodeWithText("Traffic").performClick()+ assertEquals(true, traffic)+ }++ @Test+ fun `toggling transit reports the flip`() {+ var transit: Boolean? = null+ sheet(transit = true, onTransit = { transit = it })+ rule.onNodeWithText("Transit").performClick()+ assertEquals(false, transit)+ }++ @Test+ fun `safety is surfaced live when the v5 pack is available`() {+ assertTrue(SafetyLayersSource.available, "precondition: safety available")+ sheet()+ // The sheet column scrolls past the viewport: existence (not+ // on-screen display) is what the sheet guarantees here.+ assertTrue(+ rule.onAllNodesWithText("Safety layers", substring = true).fetchSemanticsNodes().isNotEmpty(),+ "safety row exists",+ )+ }+}
maps/src/test/java/com/vayunmathur/maps/ui/LineBadgeSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/LineBadgeSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/LineBadgeSlice2Test.ktnew file mode 100644index 0000000000..79c6b43a4d--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/LineBadgeSlice2Test.kt@@ -0,0 +1,70 @@+package com.vayunmathur.maps.ui++import androidx.compose.ui.graphics.Color+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import org.junit.Rule+import org.junit.runner.RunWith++/**+ * The transit line chip and its colour helpers.+ * Slice-2 coverage for maps (basename L, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class LineBadgeSlice2Test {++ @get:Rule+ val rule = createComposeRule()++ @Test+ fun `a hex colour parses with or without a hash`() {+ assertEquals(Color(0xFFFF0000), parseHexColor("FF0000"))+ assertEquals(Color(0xFFFF0000), parseHexColor("#FF0000"))+ }++ @Test+ fun `blank and null colours parse to null`() {+ assertNull(parseHexColor(null))+ assertNull(parseHexColor(""))+ assertNull(parseHexColor(" "))+ }++ @Test+ fun `a malformed colour parses to null`() {+ assertNull(parseHexColor("not-a-colour"))+ assertNull(parseHexColor("12345"))+ }++ @Test+ fun `bright backgrounds get black text and dark ones white`() {+ assertEquals(Color.Black, onColorFor(Color.White))+ assertEquals(Color.White, onColorFor(Color.Black))+ // Pure red is dark by the luminance ramp (0.299), so it gets white text.+ assertEquals(Color.White, onColorFor(Color.Red))+ assertEquals(Color.Black, onColorFor(Color.Yellow))+ }++ @Test+ fun `the badge shows the line name`() {+ rule.setContent { LineBadge(line = "N", routeColor = "FF0000") }+ rule.onNodeWithText("N").assertIsDisplayed()+ }++ @Test+ fun `a blank line shows the placeholder dash`() {+ rule.setContent { LineBadge(line = "", routeColor = null) }+ rule.onNodeWithText("—").assertIsDisplayed()+ }++ @Test+ fun `a null colour falls back to the theme primary`() {+ // No crash, and the line still reads — the fallback is the theme colour.+ rule.setContent { LineBadge(line = "38", routeColor = "zzz") }+ rule.onNodeWithText("38").assertIsDisplayed()+ }+}
maps/src/test/java/com/vayunmathur/maps/util/CameraBoundsSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/CameraBoundsSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/CameraBoundsSlice2Test.ktnew file mode 100644index 0000000000..59bec13536--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/CameraBoundsSlice2Test.kt@@ -0,0 +1,31 @@+package com.vayunmathur.maps.util++import com.vayunmathur.library.map.GeoBounds+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * The visible-bounds fallback for a camera that has not measured yet.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ *+ * A fresh camera has no projection (the viewport is unmeasured), so every+ * caller gets the whole world rather than nothing.+ */+class CameraBoundsSlice2Test {++ @Test+ fun `an unmeasured camera falls back to the world`() {+ val bounds = com.vayunmathur.library.map.CameraState().visibleBoundsOrWorld()+ assertEquals(+ GeoBounds(west = -180.0, south = -85.0, east = 180.0, north = 85.0),+ bounds,+ )+ }++ @Test+ fun `the fallback is stable across cameras`() {+ val a = com.vayunmathur.library.map.CameraState().visibleBoundsOrWorld()+ val b = com.vayunmathur.library.map.CameraState().visibleBoundsOrWorld()+ assertEquals(a, b)+ }+}
maps/src/test/java/com/vayunmathur/maps/util/ContactLookupLaunchersSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupLaunchersSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupLaunchersSlice2Test.ktnew file mode 100644index 0000000000..098354e00a--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupLaunchersSlice2Test.kt@@ -0,0 +1,98 @@+package com.vayunmathur.maps.util++import android.content.ActivityNotFoundException+import android.content.Intent+import androidx.activity.result.ActivityResultLauncher+import androidx.activity.result.contract.ActivityResultContracts+import androidx.core.app.ActivityOptionsCompat+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.runner.RunWith++/**+ * The postal-picker fallback chain: postal row first, whole-contact second,+ * quiet no-op when the device has neither.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class ContactLookupLaunchersSlice2Test {++ private class RecordingLauncher<I>(+ private val behaviour: (I) -> Unit = {},+ ) : ActivityResultLauncher<I>() {+ val launched = mutableListOf<I>()+ override val contract: androidx.activity.result.contract.ActivityResultContract<I, *>+ get() = throw UnsupportedOperationException("test fake")++ override fun launch(input: I, options: ActivityOptionsCompat?) {+ launched.add(input)+ behaviour(input)+ }++ override fun unregister() {}+ }++ @Test+ fun `the postal picker is tried first`() {+ val postal = RecordingLauncher<Intent>()+ val contact = RecordingLauncher<Void?>()+ var noPicker = 0+ launchPostalPicker(postal, contact, onNoPicker = { noPicker++ })+ assertEquals(1, postal.launched.size)+ assertEquals(0, contact.launched.size)+ assertEquals(0, noPicker)+ // Typed to the postal content type.+ assertEquals(+ android.provider.ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_TYPE,+ postal.launched[0].type,+ )+ assertEquals(Intent.ACTION_PICK, postal.launched[0].action)+ }++ @Test+ fun `no postal picker falls back to the whole-contact picker`() {+ val postal = RecordingLauncher<Intent> { throw ActivityNotFoundException() }+ val contact = RecordingLauncher<Void?>()+ var noPicker = 0+ launchPostalPicker(postal, contact, onNoPicker = { noPicker++ })+ assertEquals(1, postal.launched.size)+ assertEquals(1, contact.launched.size)+ assertEquals(0, noPicker)+ }++ @Test+ fun `no picker at all reports through onNoPicker`() {+ val contact = RecordingLauncher<Void?> { throw ActivityNotFoundException() }+ var noPicker = 0+ launchContactPicker(contact, onNoPicker = { noPicker++ })+ assertEquals(1, contact.launched.size)+ assertEquals(1, noPicker)+ }++ @Test+ fun `a working contact picker stays quiet`() {+ val contact = RecordingLauncher<Void?>()+ var noPicker = 0+ launchContactPicker(contact, onNoPicker = { noPicker++ })+ assertEquals(1, contact.launched.size)+ assertEquals(0, noPicker)+ }++ @Test+ fun `double fallback reaches onNoPicker`() {+ val postal = RecordingLauncher<Intent> { throw ActivityNotFoundException() }+ val contact = RecordingLauncher<Void?> { throw ActivityNotFoundException() }+ var noPicker = 0+ launchPostalPicker(postal, contact, onNoPicker = { noPicker++ })+ assertEquals(1, noPicker)+ }++ @Test+ fun `the system picker intent is only built on android 17`() {+ // Robolectric runs SDK 34 here, below CINNAMON_BUN — document the gate.+ assertTrue(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.CINNAMON_BUN)+ }+}
maps/src/test/java/com/vayunmathur/maps/util/ContactLookupNormalizeSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupNormalizeSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupNormalizeSlice2Test.ktnew file mode 100644index 0000000000..239629396d--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupNormalizeSlice2Test.kt@@ -0,0 +1,45 @@+package com.vayunmathur.maps.util++import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Postal-address normalisation for the contacts shortcut.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ */+class ContactLookupNormalizeSlice2Test {++ @Test+ fun `a single-line address passes through`() {+ assertEquals("1 Ferry Building, San Francisco", "1 Ferry Building, San Francisco".normalizeAddress())+ }++ @Test+ fun `newlines become commas`() {+ assertEquals(+ "1 Ferry Building, San Francisco, CA 94111",+ "1 Ferry Building\nSan Francisco, CA 94111".normalizeAddress(),+ )+ }++ @Test+ fun `blank lines are dropped`() {+ assertEquals(+ "1 Ferry Building, San Francisco",+ "1 Ferry Building\n\nSan Francisco\n".normalizeAddress(),+ )+ }++ @Test+ fun `runs of whitespace collapse`() {+ assertEquals(+ "1 Ferry Building, San Francisco",+ " 1 Ferry\tBuilding \n San Francisco ".normalizeAddress(),+ )+ }++ @Test+ fun `an all-blank address collapses to empty`() {+ assertEquals("", "\n \n\t\n".normalizeAddress())+ }+}
maps/src/test/java/com/vayunmathur/maps/util/ContactLookupProvidersSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupProvidersSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupProvidersSlice2Test.ktnew file mode 100644index 0000000000..df9d6740d1--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/ContactLookupProvidersSlice2Test.kt@@ -0,0 +1,204 @@+package com.vayunmathur.maps.util++import android.app.Application+import android.content.ContentProvider+import android.content.ContentValues+import android.content.Context+import android.database.Cursor+import android.database.MatrixCursor+import android.net.Uri+import android.provider.ContactsContract+import android.provider.ContactsContract.CommonDataKinds.StructuredPostal+import androidx.test.core.app.ApplicationProvider+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/**+ * Postal-address reads over a fake contacts provider: session URIs, postal+ * rows and whole-contact resolution.+ * Slice-2 coverage for maps (basename C, outside the slice-1 dirs).+ *+ * A fake [ContentProvider] serves [MatrixCursor] rows (Robolectric's+ * `ShadowContentResolver.setCursor` only accepts the stub cursor, whose+ * accessors throw — a provider is the data-bearing path).+ */+@RunWith(RobolectricTestRunner::class)+class ContactLookupProvidersSlice2Test {++ class FakeContactsProvider : ContentProvider() {+ /** uri string -> rows served for it. */+ var tables: Map<String, List<Array<Any?>>> = emptyMap()++ private val columns = arrayOf(+ ContactsContract.Data.MIMETYPE,+ StructuredPostal.FORMATTED_ADDRESS,+ StructuredPostal.STREET,+ StructuredPostal.CITY,+ StructuredPostal.REGION,+ StructuredPostal.POSTCODE,+ StructuredPostal.COUNTRY,+ ContactsContract.Contacts._ID,+ )++ override fun onCreate(): Boolean = true++ override fun query(+ uri: Uri,+ projection: Array<String>?,+ selection: String?,+ selectionArgs: Array<String>?,+ sortOrder: String?,+ ): Cursor {+ val rows = tables[uri.toString()].orEmpty()+ val cursor = MatrixCursor(columns, rows.size)+ rows.forEach { cursor.addRow(it) }+ return cursor+ }++ override fun getType(uri: Uri): String? = null+ override fun insert(uri: Uri, values: ContentValues?): Uri? = null+ override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int = 0+ override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int = 0+ }++ private val context: Context get() = ApplicationProvider.getApplicationContext()++ private lateinit var provider: FakeContactsProvider++ private fun sessionUri() = Uri.parse("content://com.android.contacts/session/1")+ private fun rowUri() = Uri.parse("content://com.android.contacts/data/7")+ private fun contactUri() = Uri.parse("content://com.android.contacts/contacts/9")++ private fun postalRow(+ formatted: String? = "1 Ferry Building\nSan Francisco, CA 94111",+ street: String? = null,+ city: String? = null,+ region: String? = null,+ postcode: String? = null,+ country: String? = null,+ mime: String? = StructuredPostal.CONTENT_ITEM_TYPE,+ ): Array<Any?> = arrayOf(mime, formatted, street, city, region, postcode, country, "9")++ private fun setUp() {+ provider = Robolectric.setupContentProvider(+ FakeContactsProvider::class.java,+ "com.android.contacts",+ )+ }++ @Test+ fun `a formatted session address normalises to one line`() {+ setUp()+ provider.tables = mapOf(sessionUri().toString() to listOf(postalRow()))+ val addresses = readSessionAddresses(context, sessionUri())+ assertEquals(+ listOf("1 Ferry Building, San Francisco, CA 94111"),+ addresses,+ )+ }++ @Test+ fun `non-postal session rows are skipped`() {+ setUp()+ provider.tables = mapOf(+ sessionUri().toString() to listOf(+ postalRow(mime = "vnd.android.cursor.item/phone_v2", formatted = "555-0102"),+ postalRow(),+ )+ )+ assertEquals(1, readSessionAddresses(context, sessionUri()).size)+ }++ @Test+ fun `duplicate session addresses are de-duplicated`() {+ setUp()+ provider.tables = mapOf(sessionUri().toString() to listOf(postalRow(), postalRow()))+ assertEquals(1, readSessionAddresses(context, sessionUri()).size)+ }++ @Test+ fun `an empty session reads empty`() {+ setUp()+ provider.tables = emptyMap()+ assertEquals(emptyList(), readSessionAddresses(context, sessionUri()))+ }++ @Test+ fun `a postal row reads its formatted address`() {+ setUp()+ provider.tables = mapOf(rowUri().toString() to listOf(postalRow()))+ assertEquals(+ "1 Ferry Building, San Francisco, CA 94111",+ readAddress(context, rowUri()),+ )+ }++ @Test+ fun `a row without address parts reads null`() {+ setUp()+ provider.tables = mapOf(+ rowUri().toString() to listOf(+ postalRow(formatted = null, street = null, city = null, region = null, postcode = null, country = null)+ )+ )+ assertNull(readAddress(context, rowUri()))+ }++ @Test+ fun `components compose when no formatted address exists`() {+ setUp()+ provider.tables = mapOf(+ rowUri().toString() to listOf(+ postalRow(+ formatted = null,+ street = "1 Ferry Building",+ city = "San Francisco",+ region = "CA",+ postcode = "94111",+ country = "USA",+ )+ )+ )+ assertEquals(+ "1 Ferry Building, San Francisco, CA, 94111, USA",+ readAddress(context, rowUri()),+ )+ }++ @Test+ fun `a missing row reads null`() {+ setUp()+ provider.tables = emptyMap()+ assertNull(readAddress(context, rowUri()))+ }++ @Test+ fun `a whole contact resolves its postal rows`() {+ setUp()+ // The id lookup reads column 0 of the contact row; the data query+ // then serves the postal rows for that contact.+ provider.tables = mapOf(+ contactUri().toString() to listOf(+ arrayOf<Any?>("9", null, null, null, null, null, null, "9"),+ ),+ ContactsContract.Data.CONTENT_URI.toString() to listOf(postalRow()),+ )+ val addresses = readContactAddresses(context, contactUri())+ assertEquals(+ listOf("1 Ferry Building, San Francisco, CA 94111"),+ addresses,+ )+ }++ @Test+ fun `a contact with no rows resolves empty`() {+ setUp()+ provider.tables = emptyMap()+ assertEquals(emptyList(), readContactAddresses(context, contactUri()))+ }+}
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.ktnew file mode 100644index 0000000000..41bc10872f--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationLiveSlice2Test.kt@@ -0,0 +1,210 @@+package com.vayunmathur.maps.util++import android.Manifest+import android.app.Application+import android.content.Context+import android.hardware.Sensor+import android.hardware.SensorEventListener+import android.hardware.SensorManager+import android.location.Location+import android.location.LocationListener+import android.location.LocationManager+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.Shadows.shadowOf++/**+ * The framework location feed with providers enabled: the live-fix path+ * (acceptance gate, jitter hold, GPS-bearing re-anchor), the cold-start seed+ * and the last-known selection rule.+ * Slice-2 coverage for maps (basename F, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class FrameworkLocationLiveSlice2Test {++ private val context: Context get() = ApplicationProvider.getApplicationContext()++ private fun grantLocation() {+ shadowOf(context as Application).grantPermissions(+ Manifest.permission.ACCESS_FINE_LOCATION,+ Manifest.permission.ACCESS_COARSE_LOCATION,+ )+ }++ private fun locationManager(): LocationManager =+ context.getSystemService(Context.LOCATION_SERVICE) as LocationManager++ private fun fix(+ provider: String = LocationManager.GPS_PROVIDER,+ lat: Double = 37.8,+ lon: Double = -122.4,+ accuracy: Float = 5f,+ bearing: Float? = null,+ speed: Float? = null,+ timeNanos: Long = 1_000_000_000L,+ ): Location = Location(provider).apply {+ latitude = lat+ longitude = lon+ if (accuracy >= 0f) this.accuracy = accuracy+ if (bearing != null) this.bearing = bearing+ if (speed != null) this.speed = speed+ elapsedRealtimeNanos = timeNanos+ }++ private fun listeners(manager: LocationManager): List<LocationListener> =+ shadowOf(manager).requestLocationUpdateListeners++ @Test+ fun `a live gps fix is emitted`() {+ grantLocation()+ val lm = locationManager()+ 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) })+ val live = listeners(lm)+ assertTrue(live.isNotEmpty(), "listener registered")+ live.forEach { it.onLocationChanged(fix()) }+ // The main-looper handler delivery is synchronous under Robolectric.+ manager.stop()+ assertEquals(1, updates.size)+ assertEquals(37.8, updates[0].first.latitude)+ assertEquals(-122.4, updates[0].first.longitude)+ }++ @Test+ fun `a gps bearing re-anchors the heading`() {+ grantLocation()+ val lm = locationManager()+ shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)+ val manager = FrameworkLocationManager(context)+ val headings = mutableListOf<Float?>()+ manager.startUpdates(onUpdateReceived = { _, heading -> headings.add(heading) })+ listeners(lm).forEach { it.onLocationChanged(fix(bearing = 90f)) }+ manager.stop()+ assertEquals(listOf<Float?>(90f), headings)+ }++ @Test+ fun `a network fix does not displace a fresh gps fix`() {+ grantLocation()+ val lm = locationManager()+ shadowOf(lm).setProviderEnabled(LocationManager.GPS_PROVIDER, true)+ 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) })+ val live = listeners(lm)+ assertTrue(live.isNotEmpty())+ // One GPS fix, then a network fix 1 s later claiming 2x accuracy —+ // not enough margin to displace fresh GPS, and inside the jitter gate.+ live.forEach { it.onLocationChanged(fix(provider = LocationManager.GPS_PROVIDER, timeNanos = 1_000_000_000L)) }+ live.forEach {+ it.onLocationChanged(+ fix(provider = LocationManager.NETWORK_PROVIDER, lat = 37.801, lon = -122.401, accuracy = 5f, timeNanos = 2_000_000_000L),+ )+ }+ manager.stop()+ assertEquals(1, points.size, "network fix inside the gate does not move the puck")+ }++ @Test+ fun `the cold-start seed emits the freshest last-known fix`() {+ grantLocation()+ val lm = locationManager()+ val shadow = shadowOf(lm)+ shadow.setProviderEnabled(LocationManager.GPS_PROVIDER, true)+ shadow.setProviderEnabled(LocationManager.NETWORK_PROVIDER, true)+ shadow.setLastKnownLocation(+ LocationManager.GPS_PROVIDER,+ fix(provider = LocationManager.GPS_PROVIDER, lat = 37.1, timeNanos = 1_000_000_000L),+ )+ shadow.setLastKnownLocation(+ LocationManager.NETWORK_PROVIDER,+ fix(provider = LocationManager.NETWORK_PROVIDER, lat = 37.2, timeNanos = 2_000_000_000L),+ )+ val manager = FrameworkLocationManager(context)+ val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()+ manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+ manager.stop()+ // The network fix is fresher (larger elapsedRealtimeNanos): it seeds.+ assertEquals(1, points.size)+ assertEquals(37.2, points[0].latitude)+ }++ @Test+ fun `a zero-zero last-known fix is not a position`() {+ grantLocation()+ val lm = locationManager()+ val shadow = shadowOf(lm)+ shadow.setProviderEnabled(LocationManager.GPS_PROVIDER, true)+ shadow.setLastKnownLocation(+ LocationManager.GPS_PROVIDER,+ fix(provider = LocationManager.GPS_PROVIDER, lat = 0.0, lon = 0.0),+ )+ val manager = FrameworkLocationManager(context)+ val points = mutableListOf<com.vayunmathur.library.map.GeoPoint>()+ manager.startUpdates(onUpdateReceived = { point, _ -> points.add(point) })+ manager.stop()+ assertEquals(0, points.size)+ }++ @Test+ fun `sensor registration is attempted without a location leak`() {+ grantLocation()+ val lm = locationManager()+ 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) })+ 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*+ // own are torn down, and nothing leaks through the sensor path.+ assertTrue(shadowOf(sm).getListeners().isEmpty())+ manager.stop()+ assertEquals(0, updates.size)+ }++ @Test+ fun `a stationary hold stops the second fix re-emitting`() {+ grantLocation()+ val lm = locationManager()+ 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) })+ val live = listeners(lm)+ // Same spot, 1 s apart, tight accuracy: the second fix coalesces+ // into the hold and does not re-emit.+ live.forEach { it.onLocationChanged(fix(timeNanos = 1_000_000_000L, accuracy = 4f)) }+ live.forEach { it.onLocationChanged(fix(timeNanos = 2_000_000_000L, accuracy = 4f)) }+ manager.stop()+ assertEquals(1, points.size)+ }++ @Test+ fun `a moving fix breaks the hold`() {+ grantLocation()+ val lm = locationManager()+ 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) })+ val live = listeners(lm)+ live.forEach { it.onLocationChanged(fix(timeNanos = 1_000_000_000L, accuracy = 4f)) }+ // 5 m/s: travel, not noise — always emits.+ live.forEach {+ it.onLocationChanged(+ fix(lat = 37.8005, timeNanos = 2_000_000_000L, accuracy = 4f, speed = 5f),+ )+ }+ manager.stop()+ assertEquals(2, points.size)+ }+}
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.ktnew file mode 100644index 0000000000..ed448f2086--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/FrameworkLocationManagerSlice2Test.kt@@ -0,0 +1,94 @@+package com.vayunmathur.maps.util++import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue+import kotlin.test.assertNull+import org.junit.runner.RunWith++/**+ * The framework location feed: start/stop lifecycle, the cold-start seed,+ * the stationary gate and the compass path.+ * Slice-2 coverage for maps (basename F, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class FrameworkLocationManagerSlice2Test {++ private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ @Test+ fun `start with no providers enabled yields no fix and stops cleanly`() {+ val manager = FrameworkLocationManager(context)+ 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) },+ onAccuracyReceived = { accuracy = it },+ )+ assertTrue(listener != null)+ // No provider is enabled under Robolectric and there is no last-known+ // fix, so nothing is emitted — but the listener is live.+ assertEquals(0, updates.size)+ assertEquals(-1, accuracy)+ manager.stop()+ }++ @Test+ fun `stop without start is safe`() {+ FrameworkLocationManager(context).stop()+ }++ @Test+ 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.stop()+ manager.startUpdates(onUpdateReceived = { point, heading -> updates.add(point to heading) })+ assertEquals(0, updates.size)+ manager.stop()+ }++ @Test+ fun `magnetometer accuracy reaches the accuracy callback`() {+ val manager = FrameworkLocationManager(context)+ var accuracy = -1+ 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)+ if (mag != null) {+ manager.onAccuracyChanged(mag, android.hardware.SensorManager.SENSOR_STATUS_ACCURACY_HIGH)+ assertEquals(android.hardware.SensorManager.SENSOR_STATUS_ACCURACY_HIGH, accuracy)+ }+ manager.stop()+ }++ @Test+ fun `accelerometer accuracy never reaches the callback`() {+ val manager = FrameworkLocationManager(context)+ var accuracy = -1+ 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)+ if (acc != null) {+ manager.onAccuracyChanged(acc, android.hardware.SensorManager.SENSOR_STATUS_ACCURACY_HIGH)+ assertEquals(-1, accuracy)+ }+ manager.stop()+ }++ @Test+ fun `a null sensor never reaches the callback`() {+ val manager = FrameworkLocationManager(context)+ var accuracy = -1+ 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/GTFSProviderAssetsSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/GTFSProviderAssetsSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/GTFSProviderAssetsSlice2Test.ktnew file mode 100644index 0000000000..7638c9c5aa--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/GTFSProviderAssetsSlice2Test.kt@@ -0,0 +1,30 @@+package com.vayunmathur.maps.util++import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import org.junit.runner.RunWith++/**+ * The last-resort GTFS route-colour lookup: with no feed assets shipped,+ * an absent feed reads as null rather than failing.+ * Slice-2 coverage for maps (basename G, outside the slice-1 dirs).+ */+@RunWith(AndroidJUnit4::class)+class GTFSProviderAssetsSlice2Test {++ private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ @Test+ fun `an absent feed returns null`() {+ assertNull(GTFSProvider.getRouteColor(context, "no-such-feed", "N"))+ }++ @Test+ fun `a repeated lookup for an absent feed still returns null`() {+ assertNull(GTFSProvider.getRouteColor(context, "no-such-feed", "N"))+ assertNull(GTFSProvider.getRouteColor(context, "no-such-feed", "38"))+ }+}
maps/src/test/java/com/vayunmathur/maps/util/GooglePoiMapViewModelSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/GooglePoiMapViewModelSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/GooglePoiMapViewModelSlice2Test.ktnew file mode 100644index 0000000000..5d5eed028e--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/GooglePoiMapViewModelSlice2Test.kt@@ -0,0 +1,48 @@+package com.vayunmathur.maps.util++import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.runner.RunWith++/**+ * The ambient POI overlay driver: wide views skip the lookup entirely and+ * keep the previous pins.+ * Slice-2 coverage for maps (basename G, outside the slice-1 dirs).+ *+ * Only the synchronous wide-view guard is pinned here: the debounced lookup+ * body runs on the ViewModel's own scope plus Dispatchers.IO, so awaiting it+ * would need a wall-clock sleep (banned) or a production dispatcher seam.+ */+@RunWith(AndroidJUnit4::class)+class GooglePoiMapViewModelSlice2Test {++ private val context get() = ApplicationProvider.getApplicationContext<android.app.Application>()++ @Test+ fun `a wide viewport is ignored and keeps the pins`() {+ val vm = GooglePoiMapViewModel(context)+ assertEquals(emptyList(), vm.pins.value)+ // ~220 km of latitude: far wider than the ~16 km overlay range, so+ // the lookup is skipped synchronously — no job, no pins, no crash.+ vm.onViewportOffline(north = 38.0, east = -121.0, south = 36.0, west = -123.0)+ assertEquals(emptyList(), vm.pins.value)+ }++ @Test+ fun `the retired entry point forwards wide views the same way`() {+ val vm = GooglePoiMapViewModel(context)+ vm.onViewport(north = 38.0, east = -121.0, south = 36.0, west = -123.0)+ assertEquals(emptyList(), vm.pins.value)+ }++ @Test+ fun `a view exactly at the span limit still runs, a hair over skips`() {+ val vm = GooglePoiMapViewModel(context)+ // 0.15 is the documented ~16 km limit: just over it must skip+ // synchronously (no debounce job is even launched).+ vm.onViewportOffline(north = 37.9, east = -122.0, south = 37.7, west = -122.2)+ assertEquals(emptyList(), vm.pins.value)+ }+}
maps/src/test/java/com/vayunmathur/maps/util/GtfsRouteTypesSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/GtfsRouteTypesSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/GtfsRouteTypesSlice2Test.ktnew file mode 100644index 0000000000..11be70c711--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/util/GtfsRouteTypesSlice2Test.kt@@ -0,0 +1,64 @@+package com.vayunmathur.maps.util++import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * GTFS `route_type` (base + extended ranges) to a coarse mode label.+ * Slice-2 coverage for maps (basename G, outside the slice-1 dirs).+ */+class GtfsRouteTypesSlice2Test {++ @Test+ fun `base codes map to their modes`() {+ assertEquals("TRAM", GtfsRouteTypes.mode(0))+ assertEquals("SUBWAY", GtfsRouteTypes.mode(1))+ assertEquals("RAIL", GtfsRouteTypes.mode(2))+ assertEquals("BUS", GtfsRouteTypes.mode(3))+ assertEquals("FERRY", GtfsRouteTypes.mode(4))+ assertEquals("TRAM", GtfsRouteTypes.mode(5))+ assertEquals("AERIAL", GtfsRouteTypes.mode(6))+ assertEquals("FUNICULAR", GtfsRouteTypes.mode(7))+ assertEquals("TROLLEYBUS", GtfsRouteTypes.mode(11))+ assertEquals("MONORAIL", GtfsRouteTypes.mode(12))+ }++ @Test+ fun `extended ranges map to their modes`() {+ assertEquals("TRAM", GtfsRouteTypes.mode(900))+ assertEquals("SUBWAY", GtfsRouteTypes.mode(400))+ assertEquals("SUBWAY", GtfsRouteTypes.mode(499))+ assertEquals("RAIL", GtfsRouteTypes.mode(100))+ assertEquals("RAIL", GtfsRouteTypes.mode(199))+ assertEquals("BUS", GtfsRouteTypes.mode(200))+ assertEquals("BUS", GtfsRouteTypes.mode(299))+ assertEquals("BUS", GtfsRouteTypes.mode(700))+ assertEquals("BUS", GtfsRouteTypes.mode(799))+ assertEquals("BUS", GtfsRouteTypes.mode(800))+ assertEquals("FERRY", GtfsRouteTypes.mode(1000))+ assertEquals("FERRY", GtfsRouteTypes.mode(1200))+ assertEquals("AERIAL", GtfsRouteTypes.mode(1300))+ assertEquals("FUNICULAR", GtfsRouteTypes.mode(1400))+ }++ @Test+ fun `range edges just outside fall through`() {+ // 99 is below the rail range, 500 above the subway range, 300/600/801+ // sit between the bus ranges — none of them is a known mode.+ assertEquals("TRANSIT", GtfsRouteTypes.mode(99))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(500))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(300))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(600))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(801))+ }++ @Test+ fun `unknown codes fall back to TRANSIT`() {+ assertEquals("TRANSIT", GtfsRouteTypes.mode(-1))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(8))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(9))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(10))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(13))+ assertEquals("TRANSIT", GtfsRouteTypes.mode(1500))+ }+}