Skip to content

Commit 486b3f8

Browse files
committed
feat: upgrade to a more recent JDK (21 or higher)
* Upgraded the GitHub actions. * Upgraded the JDK to 22 or higher. * Upgraded Gradle to newest possible 9.x. * Upgraded Mockito. * Upgrade JUnit.
1 parent a7bc483 commit 486b3f8

File tree

8 files changed

+60
-37
lines changed

8 files changed

+60
-37
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
# https://en.wikipedia.org/wiki/Java_version_history
22-
java: [ '8', '11' ] # LTS
22+
java: [ '21' ] # LTS
2323

2424
steps:
2525
- name: Checkout

build.gradle.kts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ plugins {
77

88
group = "com.uploadcare"
99

10-
1110
val isReleaseVersion = !version.toString().lowercase().endsWith("snapshot")
1211

1312
java {
14-
sourceCompatibility = JavaVersion.VERSION_1_7
15-
targetCompatibility = JavaVersion.VERSION_1_7
13+
toolchain {
14+
languageVersion.set(JavaLanguageVersion.of(21))
15+
}
1616
withSourcesJar()
1717
withJavadocJar()
1818
}
@@ -21,14 +21,31 @@ dependencies {
2121
implementation("org.apache.httpcomponents:httpclient:4.5.13")
2222
implementation("org.apache.httpcomponents:httpmime:4.5.13")
2323
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.2")
24-
implementation("commons-codec:commons-codec:1.10")
25-
implementation("commons-io:commons-io:2.7")
24+
implementation("commons-codec:commons-codec:1.19.0")
25+
implementation("commons-io:commons-io:2.21.0")
2626
implementation("com.sun.activation:javax.activation:1.2.0")
2727

28-
testImplementation("junit:junit:4.13.1")
28+
testImplementation(platform("org.junit:junit-bom:6.0.1"))
29+
testImplementation("org.junit.jupiter:junit-jupiter")
30+
31+
// Ensure the launcher/engine are aligned at runtime
32+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
33+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
34+
35+
testImplementation("org.hamcrest:hamcrest:2.2")
2936
testImplementation("org.mockito:mockito-all:1.10.19")
3037
}
3138

39+
tasks {
40+
withType<Test> {
41+
useJUnitPlatform()
42+
}
43+
44+
withType<Test>().configureEach {
45+
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
46+
}
47+
}
48+
3249
// Setup global publishing repository settings.
3350
signing {
3451
useGpgCmd()

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ kotlin.parallel.tasks.in.project=true
1515
org.gradle.parallel=true
1616
org.gradle.caching=true
1717
org.gradle.daemon.idletimeout=3600000
18+
19+
org.gradle.jvmargs=--add-opens java.base/java.lang=ALL-UNNAMED

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/test/java/com/uploadcare/api/FileTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import com.fasterxml.jackson.databind.DeserializationFeature;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
6-
import org.junit.Assert;
7-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
88

9-
public class FileTest
9+
class FileTest
1010
{
1111

1212
@Test
13-
public void enumFails() throws Exception {
13+
void enumFails() throws Exception {
1414
String json = "{ \"color_mode\": \"RGBa\"}";
1515

1616
// duplicate the way the mapper is configured in uploadcare
@@ -20,7 +20,7 @@ public void enumFails() throws Exception {
2020

2121
Bug bug = mapper.readValue(json, Bug.class);
2222

23-
Assert.assertTrue("Color mode was not properly converted!", File.ColorMode.RGBa.equals(bug.colorMode));
23+
assertEquals(File.ColorMode.RGBa, bug.colorMode, "Color mode was not properly converted!");
2424
}
2525

2626
static class Bug {

src/test/java/com/uploadcare/api/RequestHelperTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,44 @@
22

33
import com.uploadcare.urls.Urls;
44
import org.apache.http.client.methods.HttpGet;
5-
import org.junit.Before;
6-
import org.junit.Test;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
77

88
import java.net.URI;
99
import java.security.InvalidKeyException;
1010
import java.security.NoSuchAlgorithmException;
1111
import java.util.Calendar;
1212
import java.util.GregorianCalendar;
1313

14-
import static org.junit.Assert.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
1515

16-
public class RequestHelperTest {
16+
class RequestHelperTest {
1717

1818
private static final String FILE_ID = "27c7846b-a019-4516-a5e4-de635f822161";
1919
private static final String FORMATTED_DATE = "Fri, 17 Nov 1989 00:00:00 +0000";
2020
private RequestHelper requestHelper;
2121

22-
@Before
23-
public void setUp() {
22+
@BeforeEach
23+
void setUp() {
2424
Client client = Client.demoClient();
2525
requestHelper = new RequestHelper(client);
2626
}
2727

2828
@Test
29-
public void test_rfc2822() {
29+
void testRfc2822() {
3030
Calendar calendar = new GregorianCalendar(RequestHelper.UTC);
3131
calendar.set(1989, Calendar.NOVEMBER, 17, 0, 0, 0);
3232

3333
String formattedDate = RequestHelper.rfc2822(calendar.getTime());
34+
3435
assertEquals(formattedDate, formattedDate);
3536
}
3637

3738
@Test
38-
public void test_makeSignature() throws InvalidKeyException, NoSuchAlgorithmException {
39+
void testMakeSignature() throws InvalidKeyException, NoSuchAlgorithmException {
3940
URI url = Urls.apiFile(FILE_ID);
4041
String signature = requestHelper.makeSignature(new HttpGet(url), FORMATTED_DATE, null);
42+
4143
assertEquals("535e263808dd38599343f04aab3c9f34bb15573c", signature);
4244
}
4345

src/test/java/com/uploadcare/upload/FileUploaderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.apache.http.client.methods.HttpUriRequest;
1212
import org.hamcrest.BaseMatcher;
1313
import org.hamcrest.Description;
14-
import org.junit.Test;
14+
import org.junit.jupiter.api.Test;
1515
import org.mockito.InOrder;
1616

1717
import java.io.IOException;
@@ -22,12 +22,12 @@
2222
import static org.mockito.Matchers.eq;
2323
import static org.mockito.Mockito.*;
2424

25-
public class FileUploaderTest {
25+
class FileUploaderTest {
2626

2727
public static final String FILE_ID = "unique_file_id";
2828

2929
@Test
30-
public void test_upload() throws UploadFailureException, IOException {
30+
void testUpload() throws UploadFailureException, IOException {
3131
final RequestHelper requestHelper = mock(RequestHelper.class);
3232

3333
when(requestHelper.executeQuery(requestThat(Urls.uploadBase()), eq(false), eq(UploadBaseData.class)))
@@ -52,7 +52,7 @@ public RequestHelper get(Client client) {
5252
}
5353

5454
@Test
55-
public void test_upload_stream() throws UploadFailureException, IOException {
55+
void testUploadStream() throws UploadFailureException, IOException {
5656
final RequestHelper requestHelper = mock(RequestHelper.class);
5757

5858
when(requestHelper.executeQuery(requestThat(Urls.uploadBase()), eq(false), eq(UploadBaseData.class)))

src/test/java/com/uploadcare/urls/CdnPathBuilderTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22

33
import com.uploadcare.api.File;
44

5-
import org.junit.Before;
6-
import org.junit.Test;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
77

88
import java.awt.*;
99

10-
import static org.junit.Assert.assertEquals;
11-
import static org.junit.Assert.fail;
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.fail;
1212
import static org.mockito.Mockito.mock;
1313
import static org.mockito.Mockito.when;
1414

15-
public class CdnPathBuilderTest {
15+
class CdnPathBuilderTest {
1616

1717
private static final String FILE_ID = "27c7846b-a019-4516-a5e4-de635f822161";
1818
private CdnPathBuilder builder;
1919

20-
@Before
21-
public void setUp() {
20+
@BeforeEach
21+
void setUp() {
2222
File file = mock(File.class);
2323
when(file.getFileId()).thenReturn(FILE_ID);
2424

2525
builder = new CdnPathBuilder(file);
2626
}
2727

2828
@Test
29-
public void test_fileUrl() {
29+
void testFileUrl() {
3030
String path = builder.build();
31+
3132
assertEquals("/" + FILE_ID + "/", path);
3233
}
3334

3435
@Test
35-
public void test_allOperations() {
36+
void testAllOperations() {
3637
String path = builder
3738
.crop(100, 110)
3839
.cropColor(120, 130, Color.BLACK)
@@ -82,13 +83,14 @@ public void test_allOperations() {
8283
}
8384

8485
@Test
85-
public void test_detectFaces() {
86+
void testDetectFaces() {
8687
String path = builder.detectFaces().build();
88+
8789
assertEquals("/" + FILE_ID + "/detect_faces/", path);
8890
}
8991

9092
@Test
91-
public void test_dimensionGuard() {
93+
void testDimensionGuard() {
9294
builder.resizeWidth(1);
9395
builder.resizeWidth(2048);
9496
try {
@@ -104,7 +106,7 @@ public void test_dimensionGuard() {
104106
}
105107

106108
@Test
107-
public void test_dimensionsGuard() {
109+
void testDimensionsGuard() {
108110
builder.resize(1024, 634);
109111
builder.resize(634, 1024);
110112
try {

0 commit comments

Comments
 (0)