From 12251ffa97871e6d8baed20bc4f80f8664984091 Mon Sep 17 00:00:00 2001 From: Steven Schoen Date: Wed, 18 Jan 2023 20:06:30 -0500 Subject: [PATCH] chore: Fail tests when API key is missing (#244) --- .../java/com/google/maps/android/compose/GoogleMapViewTests.kt | 1 + .../java/com/google/maps/android/compose/MapInColumnTests.kt | 1 + .../java/com/google/maps/android/compose/TestUtils.kt | 3 +++ 3 files changed, 5 insertions(+) diff --git a/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt b/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt index fa5b8375..aaefe0c1 100644 --- a/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt +++ b/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapViewTests.kt @@ -40,6 +40,7 @@ class GoogleMapViewTests { private lateinit var cameraPositionState: CameraPositionState private fun initMap(content: @Composable () -> Unit = {}) { + check(hasValidApiKey) { "Maps API key not specified" } val countDownLatch = CountDownLatch(1) composeTestRule.setContent { GoogleMapView( diff --git a/app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt b/app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt index 8d284421..6c7723e3 100644 --- a/app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt +++ b/app/src/androidTest/java/com/google/maps/android/compose/MapInColumnTests.kt @@ -40,6 +40,7 @@ class MapInColumnTests { private lateinit var cameraPositionState: CameraPositionState private fun initMap(content: @Composable () -> Unit = {}) { + check(hasValidApiKey) { "Maps API key not specified" } val countDownLatch = CountDownLatch(1) composeTestRule.setContent { var scrollingEnabled by remember { mutableStateOf(true) } diff --git a/app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt b/app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt index 9ff769a6..c8eb5cad 100644 --- a/app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt +++ b/app/src/androidTest/java/com/google/maps/android/compose/TestUtils.kt @@ -4,6 +4,9 @@ import com.google.android.gms.maps.model.LatLng import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals +val hasValidApiKey: Boolean = + BuildConfig.MAPS_API_KEY.isNotBlank() && BuildConfig.MAPS_API_KEY != "YOUR_API_KEY" + const val assertRoundingError: Double = 0.01 fun LatLng.assertEquals(other: LatLng) {