diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapFocusTraversalTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapFocusTraversalTests.kt index 3c6dea96..b64b95ec 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapFocusTraversalTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapFocusTraversalTests.kt @@ -52,7 +52,7 @@ class GoogleMapFocusTraversalTests { ) private fun initMaps() { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() composeTestRule.setContent { MapsInLazyColumn( @@ -89,7 +89,7 @@ class GoogleMapFocusTraversalTests { @OptIn(ExperimentalTestApi::class) @Test fun nonFocusableMapIsSkippedDuringTabTraversal() { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() composeTestRule.setContent { Column { diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewClusteringTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewClusteringTests.kt index d4807c3c..9e231c12 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewClusteringTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewClusteringTests.kt @@ -59,7 +59,7 @@ class GoogleMapViewClusteringTests { clusterManagerHolder: Array?>, content: @Composable () -> Unit ): Marker { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() val countDownLatch = CountDownLatch(1) composeTestRule.setContent { diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt index 25f24d63..9ef1dde5 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt @@ -53,7 +53,7 @@ class GoogleMapViewTests { private var mapColorScheme = ComposeMapColorScheme.FOLLOW_SYSTEM private fun initMap(content: @Composable () -> Unit = {}) { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() val countDownLatch = CountDownLatch(1) val appContext: Context = InstrumentationRegistry.getInstrumentation().targetContext diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt index 76036441..b03fc267 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt @@ -40,7 +40,7 @@ class MapInColumnTests { private lateinit var cameraPositionState: CameraPositionState private fun initMap() { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() val countDownLatch = CountDownLatch(1) composeTestRule.setContent { var scrollingEnabled by remember { mutableStateOf(true) } diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/MapsInLazyColumnTest.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/MapsInLazyColumnTest.kt index 7ec24aff..4f6152e2 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/MapsInLazyColumnTest.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/MapsInLazyColumnTest.kt @@ -58,7 +58,7 @@ class MapsInLazyColumnTests { private lateinit var cameraPositionStates: Map private fun initMaps() { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() composeTestRule.setContent { val lazyListState = rememberLazyListState() diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/RecompositionActivityTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/RecompositionActivityTests.kt index fc5d4e2b..b5692a38 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/RecompositionActivityTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/RecompositionActivityTests.kt @@ -31,7 +31,7 @@ class RecompositionActivityTests { @Test fun testChangeLocationButton_MovesCameraToNewLocation() { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() val initialPosition = singapore val cameraPositionState = CameraPositionState( position = CameraPosition.fromLatLngZoom(initialPosition, 11f) diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/ScaleBarTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/ScaleBarTests.kt index fe55c3a5..b859b8fb 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/ScaleBarTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/ScaleBarTests.kt @@ -49,7 +49,7 @@ class ScaleBarTests { private lateinit var density: Density private fun initScaleBar(initialZoom: Float, initialPosition: LatLng) { - check(hasValidApiKey) { "Maps API key not specified" } + assumeValidApiKey() val countDownLatch = CountDownLatch(1) diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/StreetViewTests.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/StreetViewTests.kt index ed5b3fc3..fae84065 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/StreetViewTests.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/StreetViewTests.kt @@ -43,6 +43,8 @@ class StreetViewTests { @OptIn(MapsExperimentalFeature::class) private fun initStreetView(onClick: (StreetViewPanoramaOrientation) -> Unit = {}) { + assumeValidApiKey() + composeTestRule.setContent { StreetView( Modifier.semantics { contentDescription = "StreetView" }, diff --git a/maps-app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt b/maps-app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt index e9b74f01..eb732b85 100644 --- a/maps-app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt +++ b/maps-app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt @@ -18,6 +18,7 @@ package com.google.maps.android.compose import com.google.android.gms.maps.model.LatLng import org.junit.Assert.assertEquals +import org.junit.Assume.assumeTrue const val timeout2 = 2_000L const val timeout3 = 3_000L const val timeout5 = 5_000L @@ -26,6 +27,17 @@ const val MAP_LOAD_TIMEOUT_SECONDS = 30L val hasValidApiKey: Boolean = BuildConfig.MAPS_API_KEY.isNotBlank() && BuildConfig.MAPS_API_KEY != "YOUR_API_KEY" +/** + * Skips the calling test unless a real Maps API key is configured. + * + * Without a key the map never loads, so these tests have nothing to assert. Treating that as a + * skipped test rather than a failure keeps the build honest on forks and on Dependabot pull + * requests, neither of which can read the repository secret that supplies the key. + */ +fun assumeValidApiKey() { + assumeTrue("Maps API key not specified", hasValidApiKey) +} + const val assertRoundingError: Double = 0.01 fun LatLng.assertEquals(other: LatLng) {