Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GoogleMapFocusTraversalTests {
)

private fun initMaps() {
check(hasValidApiKey) { "Maps API key not specified" }
assumeValidApiKey()

composeTestRule.setContent {
MapsInLazyColumn(
Expand Down Expand Up @@ -89,7 +89,7 @@ class GoogleMapFocusTraversalTests {
@OptIn(ExperimentalTestApi::class)
@Test
fun nonFocusableMapIsSkippedDuringTabTraversal() {
check(hasValidApiKey) { "Maps API key not specified" }
assumeValidApiKey()

composeTestRule.setContent {
Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GoogleMapViewClusteringTests {
clusterManagerHolder: Array<ClusterManager<MyItem>?>,
content: @Composable () -> Unit
): Marker {
check(hasValidApiKey) { "Maps API key not specified" }
assumeValidApiKey()
val countDownLatch = CountDownLatch(1)

composeTestRule.setContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MapsInLazyColumnTests {
private lateinit var cameraPositionStates: Map<MapItemId, CameraPositionState>

private fun initMaps() {
check(hasValidApiKey) { "Maps API key not specified" }
assumeValidApiKey()

composeTestRule.setContent {
val lazyListState = rememberLazyListState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class StreetViewTests {

@OptIn(MapsExperimentalFeature::class)
private fun initStreetView(onClick: (StreetViewPanoramaOrientation) -> Unit = {}) {
assumeValidApiKey()

composeTestRule.setContent {
StreetView(
Modifier.semantics { contentDescription = "StreetView" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Loading