diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 3452137a..2c8f106e 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -66,3 +66,30 @@ jobs: path: ${{ runner.temp }}/ci-report-unit-tests if-no-files-found: ignore + + test-modern-jdks: + name: SDK tests on Java ${{ matrix.test-java }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + test-java: [11, 17, 19, 21, 25, 27] + + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up JDK 11, 17, 19, 21, 25 and 27 + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 + with: + java-version: | + 11 + 21 + 19 + 25 + 27 + 17 + distribution: 'corretto' + + - name: Run SDK tests + run: ./gradlew :sdk-java:test -PtestJavaVersion=${{ matrix.test-java }} -Porg.gradle.java.installations.fromEnv=JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_19_X64,JAVA_HOME_21_X64,JAVA_HOME_25_X64,JAVA_HOME_27_X64 diff --git a/sdk-java-ui/build.gradle b/sdk-java-ui/build.gradle index 00f2e6ac..b1ea3e41 100644 --- a/sdk-java-ui/build.gradle +++ b/sdk-java-ui/build.gradle @@ -68,7 +68,7 @@ dependencies { implementation 'org.json:json:20260814' testImplementation 'junit:junit:4.13.2' - testImplementation 'org.mockito:mockito-core:4.11.0' + testImplementation 'org.mockito:mockito-core:5.25.0' } // -PtestUiWithLocalCore=true builds and tests this module's source against the sdk-java project diff --git a/sdk-java/build.gradle b/sdk-java/build.gradle index 02391c4c..c5663a7f 100644 --- a/sdk-java/build.gradle +++ b/sdk-java/build.gradle @@ -18,8 +18,9 @@ if (JavaVersion.current().isJava9Compatible()) { } // Gradle itself needs Java 17, so CI passes -PtestJavaVersion=8 to run the tests on the SDK's Java 8 floor. -def testJavaVersion = findProperty('testJavaVersion') -if (testJavaVersion) { +def testJavaVersion = findProperty('testJavaVersion') ?: JavaVersion.current().majorVersion +def mockitoVersion = testJavaVersion.toString().toInteger() >= 11 ? '5.25.0' : '4.11.0' +if (findProperty('testJavaVersion')) { tasks.named('test') { javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(testJavaVersion.toString()) @@ -32,7 +33,7 @@ dependencies { implementation 'com.google.code.findbugs:jsr305:3.0.2' testImplementation 'junit:junit:4.13.2' - testImplementation 'org.mockito:mockito-core:4.11.0' + testImplementation "org.mockito:mockito-core:${mockitoVersion}" //testImplementation 'com.squareup.okhttp3:mockwebserver:3.7.0' } diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java index 419a6edf..e07eeea8 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java @@ -136,7 +136,6 @@ public void setupMigrations_latestVersion() throws IOException { initStorage(); // to initialize json storage after data version is set to expectedLatestVersion MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class)); - migrationHelper.logger = spy(migrationHelper.logger); migrationHelper.setupMigrations(storageProvider); Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion); @@ -199,7 +198,6 @@ public void applyMigrations_0to1() throws IOException { migrationHelper.setupMigrations(storageProvider); Assert.assertEquals(0, migrationHelper.currentDataModelVersion); //legacy state - migrationHelper.logger = Mockito.spy(migrationHelper.logger); //run migration helper Assert.assertNull(storageProvider.getDeviceID()); Assert.assertNull(storageProvider.getDeviceIdType()); @@ -297,7 +295,6 @@ public void applyMigrations_1to2_nothingToMigrate() throws IOException { MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class)); migrationHelper.setupMigrations(storageProvider); Assert.assertEquals(1, migrationHelper.currentDataModelVersion); - migrationHelper.logger = Mockito.spy(migrationHelper.logger); migrationHelper.migration_UserImplFile_02(migrationParams); Assert.assertEquals(2, migrationHelper.currentDataModelVersion); @@ -317,7 +314,6 @@ public void applyMigrations_1to2_nullMigrationParams() throws IOException { MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class)); migrationHelper.setupMigrations(storageProvider); Assert.assertEquals(1, migrationHelper.currentDataModelVersion); - migrationHelper.logger = Mockito.spy(migrationHelper.logger); Assert.assertFalse(migrationHelper.migration_UserImplFile_02(new ConcurrentHashMap<>())); Assert.assertEquals(2, migrationHelper.currentDataModelVersion); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/RemoteConfigValueStoreTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/RemoteConfigValueStoreTests.java index d8f8e06d..495bb973 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/RemoteConfigValueStoreTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/RemoteConfigValueStoreTests.java @@ -75,7 +75,6 @@ public void cacheClearValues_cachingEnabled() { @Test public void cacheClearValues_garbageJson() { RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class)); - rcvs.L = Mockito.spy(rcvs.L); rcvs.cacheClearValues(); Mockito.verify(rcvs.L, Mockito.times(1)).w("[RemoteConfigValueStore] cacheClearValues, stored entry was not a JSON object, key:[" + TestUtils.keysValues[0] + "] value:[garbage]"); Assert.assertEquals(0, rcvs.getAllValues().size()); @@ -145,7 +144,6 @@ public void mergeValues_nullRcValues() { @Test public void getValue_nullRcValues() { RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class)); - rcvs.L = Mockito.spy(rcvs.L); Assert.assertNull(rcvs.getValue(TestUtils.keysValues[0]).value); Mockito.verify(rcvs.L, Mockito.times(1)).e(Mockito.anyString()); } @@ -227,7 +225,6 @@ public void getAllValues_garbageJson() { @Test public void getAllValues_garbageCacheKey() { RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson("garbage"), true, Mockito.mock(Log.class)); - rcvs.L = Mockito.spy(rcvs.L); Assert.assertEquals(0, rcvs.getAllValues().size()); Mockito.verify(rcvs.L, Mockito.times(2)).e(Mockito.anyString()); Assert.assertEquals(2, rcvs.values.length());