Skip to content

Commit

Permalink
Build and test with JDK 17 & 21 (#607)
Browse files Browse the repository at this point in the history
* Build and test with JDK 17 & 21

Update Maven in CI to 3.9.4 (latest stable)

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* Bump Mockito to 5.5.0

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* Do not use Mockito to create a mock of java.io.File class

It fails on JdK 21 with:
```
[ERROR]   FilesTest.dontWaitTooMuchIfCantDelete:96 Mockito
Mockito cannot mock this class: class java.io.File.

If you're not sure why you're getting this error, please open an issue on GitHub.

Java               : 21
JVM vendor name    : Oracle Corporation
JVM vendor version : 21+35-2513
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21+35-2513
JVM info           : mixed mode, sharing
OS name            : Linux
OS version         : 6.2.0-10018-tuxedo

You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface java.io.Serializable, class java.lang.Object, class java.io.File, interface java.lang.Comparable]
```

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* Fix failing tests on JDK 21

The problem is explained at https://bugs.openjdk.org/browse/JDK-8304925

Update Byte-Buddy to fix failing tests due to Mockito not able to create
mocks

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* Update org.openrewrite.recipe:rewrite-recipe-bom to support Java 21

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* Test against JDK 22-ea too

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* 22-ea is not yet available at adoptium.net

Test against latest stable - JDK 20

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* Add a Maven profile for JDK 21

Fix the version of EA
Update maven-javadoc-plugin

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

---------

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g authored Sep 11, 2023
1 parent a36ed9f commit 5d6c882
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 24 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
name: Java CI

on: [push, pull_request]
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
MAVEN_VERSION: 3.9.4

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
java:
- '17'
- '20'
- '21-ea'

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Setup Temurin JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}

- name: Apt update
run: sudo apt update

- name: Install Java & Puppeteer's dependencies
run: sudo apt-get install -y openjdk-17-jdk chromium-browser fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libappindicator3-1 libgbm1
- name: Install Puppeteer's dependencies
run: sudo apt-get install -y chromium-browser fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libappindicator3-1 libgbm1

- name: Install Maven
run: |
MAVEN_VERSION=3.8.7
wget https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
tar -xzf apache-maven-${MAVEN_VERSION}-bin.tar.gz
export PATH=$PWD/apache-maven-${MAVEN_VERSION}/bin:$PATH
- name: Cache Maven packages
uses: actions/cache@v3
Expand All @@ -32,8 +49,5 @@ jobs:

- name: Build with Maven
run: |
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
java -version
mvn -version
mvn clean verify -Pjs-test
./apache-maven-${MAVEN_VERSION}/bin/mvn --show-version clean verify -Pjs-test
34 changes: 30 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<aspectj.version>1.9.19</aspectj.version>
<assertj-core.version>3.24.2</assertj-core.version>
<bouncycastle.version>1.74</bouncycastle.version>
<byte-buddy.version>1.14.2</byte-buddy.version>
<byte-buddy.version>1.14.7</byte-buddy.version>
<cdi-unit.version>4.1.0</cdi-unit.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-fileupload.version>2.0.0-M1</commons-fileupload.version>
Expand Down Expand Up @@ -170,7 +170,7 @@
<hibernate-validator.version>7.0.5.Final</hibernate-validator.version>
<httpunit.version>1.7.3</httpunit.version>
<metrics.version>4.2.17</metrics.version>
<mockito.version>5.2.0</mockito.version>
<mockito.version>5.5.0</mockito.version>
<objenesis.version>3.3</objenesis.version>
<openjson.version>1.0.12</openjson.version>
<slf4j.version>2.0.6</slf4j.version>
Expand All @@ -192,7 +192,7 @@
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-install-plugin.version>3.1.0</maven-install-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<maven-project-info-reports-plugin.version>3.4.1</maven-project-info-reports-plugin.version>
<maven-release-plugin.version>3.0.0-M7</maven-release-plugin.version>
<maven-remote-resources-plugin.version>3.0.0</maven-remote-resources-plugin.version>
Expand Down Expand Up @@ -1489,6 +1489,32 @@
</plugins>
</build>
</profile>
<profile>
<id>java21</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>${maven-toolchains-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>21</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>on-jdk-11-or-12</id>
<activation>
Expand All @@ -1501,7 +1527,7 @@
<profile>
<id>on-jdk-early-access</id>
<activation>
<jdk>[18,)</jdk>
<jdk>[21,)</jdk>
</activation>
<properties>
<javadoc.jdk.apidocs.link>https://download.java.net/java/early_access/jdk${java.specification.version}/docs/api/</javadoc.jdk.apidocs.link>
Expand Down
22 changes: 20 additions & 2 deletions wicket-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,34 @@
<artifactId>jakarta.activation-api</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.18.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>3.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
<version>1.17.0</version>
<version>2.2.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.apache.wicket.util.convert.ConversionException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;

import java.time.LocalDateTime;
import java.util.Locale;
Expand All @@ -30,18 +32,36 @@
public class LocalDateTimeConverterTest
{
@Test
public void convertToString() {
@EnabledOnJre({JRE.JAVA_17, JRE.JAVA_18, JRE.JAVA_19})
public void convertToString_upto_jdk19() {
LocalDateTimeConverter converter = new LocalDateTimeConverter();
String date = converter.convertToString(LocalDateTime.of(2016, 7, 11, 1, 2, 3), Locale.ENGLISH);
assertEquals("Jul 11, 2016, 1:02:03 AM", date);
}

@Test
public void convertToObject() {
@EnabledOnJre({JRE.JAVA_20, JRE.JAVA_21}) // See https://bugs.openjdk.org/browse/JDK-8304925
public void convertToString_jdk20_and_newer() {
LocalDateTimeConverter converter = new LocalDateTimeConverter();
String date = converter.convertToString(LocalDateTime.of(2016, 7, 11, 1, 2, 3), Locale.ENGLISH);
assertEquals("Jul 11, 2016, 1:02:03 AM", date);
}

@Test
@EnabledOnJre({JRE.JAVA_17, JRE.JAVA_18, JRE.JAVA_19})
public void convertToObject_upto_jdk19() {
LocalDateTimeConverter converter = new LocalDateTimeConverter();
LocalDateTime date = converter.convertToObject("Jul 11, 2016, 1:02:03 AM", Locale.ENGLISH);
assertEquals(date, LocalDateTime.of(2016, 7, 11, 1, 2, 3));
}

@Test
@EnabledOnJre({JRE.JAVA_20, JRE.JAVA_21}) // See https://bugs.openjdk.org/browse/JDK-8304925
public void convertToObject_jdk20_and_newer() {
LocalDateTimeConverter converter = new LocalDateTimeConverter();
LocalDateTime date = converter.convertToObject("Jul 11, 2016, 1:02:03 AM", Locale.ENGLISH);
assertEquals(date, LocalDateTime.of(2016, 7, 11, 1, 2, 3));
}

@Test
public void convertFails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,37 @@ public class ZonedDateTimeConverterTest
private final ZoneId zoneUTC = ZoneId.of("Etc/UTC");

@Test
public void convertToString() {
@EnabledOnJre({JRE.JAVA_17, JRE.JAVA_18, JRE.JAVA_19})
public void convertToString_upto_jdk19() {
ZonedDateTimeConverter converter = new ZonedDateTimeConverter();
String date = converter.convertToString(ZonedDateTime.of(2016, 7, 11, 1, 2, 3, 0, zoneUCT), Locale.ENGLISH);
assertEquals("Jul 11, 2016, 1:02:03 AM Coordinated Universal Time", date);
}

@Test
public void convertToObject() {
@EnabledOnJre({JRE.JAVA_20, JRE.JAVA_21}) // See https://bugs.openjdk.org/browse/JDK-8304925
public void convertToString_jdk20_and_newer() {
ZonedDateTimeConverter converter = new ZonedDateTimeConverter();
String date = converter.convertToString(ZonedDateTime.of(2016, 7, 11, 1, 2, 3, 0, zoneUCT), Locale.ENGLISH);
assertEquals("Jul 11, 2016, 1:02:03 AM Coordinated Universal Time", date);
}

@Test
@EnabledOnJre({JRE.JAVA_17, JRE.JAVA_18, JRE.JAVA_19})
public void convertToObject_upto_jdk19() {
ZonedDateTimeConverter converter = new ZonedDateTimeConverter();
ZonedDateTime date = converter.convertToObject("Jul 11, 2016, 1:02:03 AM Coordinated Universal Time", Locale.ENGLISH);
assertEquals(ZonedDateTime.of(2016, 7, 11, 1, 2, 3, 0, zoneUTC), date);
}

@Test
@EnabledOnJre({JRE.JAVA_20, JRE.JAVA_21}) // See https://bugs.openjdk.org/browse/JDK-8304925
public void convertToObject_jdk20_and_newer() {
ZonedDateTimeConverter converter = new ZonedDateTimeConverter();
ZonedDateTime date = converter.convertToObject("Jul 11, 2016, 1:02:03 AM Coordinated Universal Time", Locale.ENGLISH);
assertEquals(ZonedDateTime.of(2016, 7, 11, 1, 2, 3, 0, zoneUTC), date);
}

@Test
public void convertFails() {
ZonedDateTimeConverter converter = new ZonedDateTimeConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,24 @@ private java.io.File getFolder()
@Test
public void dontWaitTooMuchIfCantDelete()
{
java.io.File f = mock(java.io.File.class);
when(f.isFile()).thenReturn(true);
when(f.delete()).thenReturn(false);
java.io.File f = new java.io.File("dummy/path")
{
@Override
public boolean isFile()
{
return true;
}

@Override
public boolean delete()
{
return false;
}
};
long start = currentTimeMillis();
Files.remove(f);
long end = currentTimeMillis();
assertTrue((end - start) < 5000l);
assertTrue((end - start) < 5000L);
}

/**
Expand Down

0 comments on commit 5d6c882

Please sign in to comment.