Skip to content

Commit 5d7b0e7

Browse files
authored
build: update to Kotlin 2.2.20, fixed tests (#1604)
* build: update to Kotlin 2.2.20, fixed tests * build: re-added BuildConfig
1 parent f8b0d4d commit 5d7b0e7

File tree

8 files changed

+52
-31
lines changed

8 files changed

+52
-31
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ buildscript {
3232
}
3333

3434
tasks.register<Delete>("clean") {
35-
delete(rootProject.buildDir)
35+
delete(layout.buildDirectory)
3636
}
3737

3838
allprojects {

demo/build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
/**
24
* Copyright 2025 Google LLC
35
*
@@ -22,7 +24,7 @@ plugins {
2224

2325
android {
2426
lint {
25-
sarifOutput = file("$buildDir/reports/lint-results.sarif")
27+
sarifOutput = layout.buildDirectory.file("reports/lint-results.sarif").get().asFile
2628
}
2729

2830
defaultConfig {
@@ -48,12 +50,13 @@ android {
4850
viewBinding = true
4951
}
5052

51-
kotlinOptions {
52-
jvmTarget = "17"
53-
}
5453
kotlin {
54+
compilerOptions {
55+
jvmTarget.set(JvmTarget.JVM_17)
56+
}
5557
jvmToolchain(17)
5658
}
59+
5760
namespace = "com.google.maps.android.utils.demo"
5861
}
5962

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ mavenCentralPassword=
3737

3838
# Add a property to enable automatic release to Maven Central (optional, but good for CI)
3939
# If true, publishToMavenCentral will also close and release the staging repository
40-
mavenCentralAutomaticRelease=false
40+
mavenCentralAutomaticRelease=false

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gradle = "8.13.0"
99
jacoco-android = "0.2.1"
1010
lifecycle-extensions = "2.2.0"
1111
lifecycle-viewmodel-ktx = "2.9.4"
12-
kotlin = "2.2.0"
12+
kotlin = "2.2.20"
1313
kotlinx-coroutines = "1.10.2"
1414
junit = "4.13.2"
1515
mockito-core = "5.20.0"

library/build.gradle.kts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
/**
24
* Copyright 2024 Google Inc.
35
*
@@ -21,14 +23,13 @@ plugins {
2123

2224
android {
2325
lint {
24-
sarifOutput = file("$buildDir/reports/lint-results.sarif")
26+
sarifOutput = layout.buildDirectory.file("reports/lint-results.sarif").get().asFile
2527
}
2628
defaultConfig {
2729
compileSdk = libs.versions.compileSdk.get().toInt()
2830
minSdk = 21
29-
targetSdk = libs.versions.targetSdk.get().toInt()
31+
testOptions.targetSdk = libs.versions.targetSdk.get().toInt()
3032
consumerProguardFiles("consumer-rules.pro")
31-
buildConfigField("String", "TRAVIS", "\"${System.getenv("TRAVIS")}\"")
3233
}
3334
buildTypes {
3435
release {
@@ -40,16 +41,19 @@ android {
4041
}
4142
}
4243
resourcePrefix = "amu_"
43-
adbOptions {
44+
45+
installation {
4446
timeOutInMs = 10 * 60 * 1000 // 10 minutes
4547
installOptions("-d", "-t")
4648
}
47-
kotlinOptions {
48-
jvmTarget = "17"
49-
}
49+
5050
kotlin {
51+
compilerOptions {
52+
jvmTarget.set(JvmTarget.JVM_17)
53+
}
5154
jvmToolchain(17)
5255
}
56+
5357
testOptions {
5458
animationsDisabled = true
5559
unitTests.isIncludeAndroidResources = true
@@ -75,6 +79,7 @@ dependencies {
7579
testImplementation(libs.mockk)
7680
testImplementation(libs.kotlinx.coroutines.test)
7781
testImplementation(libs.robolectric)
82+
testImplementation(libs.mockito.core)
7883
}
7984

8085
tasks.register("instrumentTest") {

library/src/test/java/com/google/maps/android/TestUtil.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google Inc.
2+
* Copyright 2025 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,10 +18,12 @@
1818
public class TestUtil {
1919

2020
/**
21-
* Returns true if execution is occurring on Travis CI, and false if it is not
22-
* @return true if execution is occurring on Travis CI, and false if it is not
21+
* Returns true if execution is occurring on GitHub Actions, and false otherwise.
22+
* This is determined by checking the GITHUB_ACTIONS environment variable.
23+
*
24+
* @return true if running on GitHub Actions, false otherwise.
2325
*/
24-
public static boolean isRunningOnTravis() {
25-
return BuildConfig.TRAVIS != null && BuildConfig.TRAVIS.equals("true");
26+
public static boolean isRunningOnGitHub() {
27+
return "true".equals(System.getenv("GITHUB_ACTIONS"));
2628
}
2729
}

library/src/test/java/com/google/maps/android/data/geojson/GeoJsonPointStyleTest.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
import com.google.android.gms.maps.MapsInitializer;
1919
import com.google.android.gms.maps.model.BitmapDescriptor;
2020
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
21-
import com.google.maps.android.TestUtil;
2221

23-
import org.junit.Assume;
22+
import org.junit.After;
2423
import org.junit.Before;
25-
import org.junit.Ignore;
2624
import org.junit.Test;
2725
import org.junit.runner.RunWith;
26+
import org.mockito.MockedStatic;
2827
import org.robolectric.RobolectricTestRunner;
2928

3029
import java.util.Arrays;
@@ -35,15 +34,28 @@
3534
import static org.junit.Assert.assertFalse;
3635
import static org.junit.Assert.assertNull;
3736
import static org.junit.Assert.assertTrue;
37+
import static org.mockito.Mockito.mock;
38+
import static org.mockito.Mockito.mockStatic;
39+
import static org.mockito.Mockito.when;
3840

3941
@RunWith(RobolectricTestRunner.class)
4042
public class GeoJsonPointStyleTest {
4143
private GeoJsonPointStyle pointStyle;
4244

45+
private MockedStatic<BitmapDescriptorFactory> mockedStatic;
46+
4347
@Before
4448
public void setUp() {
4549
MapsInitializer.initialize(InstrumentationRegistry.getInstrumentation().getTargetContext());
4650
pointStyle = new GeoJsonPointStyle();
51+
mockedStatic = mockStatic(BitmapDescriptorFactory.class);
52+
}
53+
54+
@After
55+
public void tearDown() {
56+
if (mockedStatic != null) {
57+
mockedStatic.close();
58+
}
4759
}
4860

4961
@Test
@@ -84,16 +96,15 @@ public void testFlat() {
8496
assertTrue(pointStyle.toMarkerOptions().isFlat());
8597
}
8698

87-
@Ignore("I should run via Robolectric - java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized") // FIXME
8899
@Test
89100
public void testIcon() {
90-
if (TestUtil.isRunningOnTravis()) {
91-
Assume.assumeTrue("Skipping GeoJsonPointStyleTest.testIcon() - this is expected behavior on Travis CI (#573)", false);
92-
return;
93-
}
94-
BitmapDescriptor icon =
95-
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN);
101+
// Mock the return value of defaultMarker
102+
BitmapDescriptor mockedIcon = mock(BitmapDescriptor.class);
103+
when(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)).thenReturn(mockedIcon);
104+
105+
BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN);
96106
pointStyle.setIcon(icon);
107+
97108
assertEquals(icon, pointStyle.getIcon());
98109
assertEquals(icon, pointStyle.toMarkerOptions().getIcon());
99110
}

library/src/test/java/com/google/maps/android/data/kml/KmlStyleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testLineColor() {
134134
@Test
135135
@Ignore("I should run via Robolectric - java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized") // FIXME
136136
public void testMarkerColorLeadingSpace() {
137-
if (TestUtil.isRunningOnTravis()) {
137+
if (TestUtil.isRunningOnGitHub()) {
138138
Assume.assumeTrue("Skipping KmlStyleTest.testMarkerColorLeadingSpace() - this is expected behavior on Travis CI (#573)", false);
139139
return;
140140
}
@@ -148,7 +148,7 @@ public void testMarkerColorLeadingSpace() {
148148
@Test
149149
@Ignore("I should run via Robolectric - java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized") // FIXME
150150
public void testMarkerColorTrailingSpace() {
151-
if (TestUtil.isRunningOnTravis()) {
151+
if (TestUtil.isRunningOnGitHub()) {
152152
Assume.assumeTrue("Skipping KmlStyleTest.testMarkerColorTrailingSpace() - this is expected behavior on Travis CI (#573)", false);
153153
return;
154154
}

0 commit comments

Comments
 (0)