Skip to content

Commit 3cca45c

Browse files
author
Davide Melfi
committed
chore: update test framework and fixed test
1 parent 1a5f2bc commit 3cca45c

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

aws-lambda-java-runtime-interface-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<jacoco.maven.plugin.version>0.8.12</jacoco.maven.plugin.version>
3838
<maven-install-plugin.version>2.4</maven-install-plugin.version>
3939
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
40-
<junit-jupiter.version>5.9.2</junit-jupiter.version>
40+
<junit-jupiter.version>5.14.3</junit-jupiter.version>
4141
<maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version>
4242
<!--
4343
The test/integration/codebuild/buildspec.*.yml files will set -DmultiArch=false

aws-lambda-java-runtime-interface-client/src/test/java/com/amazonaws/services/lambda/runtime/api/client/ClasspathLoaderTest.java

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
package com.amazonaws.services.lambda.runtime.api.client;
77

88
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.condition.DisabledForJreRange;
10+
import org.junit.jupiter.api.condition.EnabledForJreRange;
11+
import org.junit.jupiter.api.condition.JRE;
912
import org.junit.jupiter.api.io.TempDir;
1013
import java.io.File;
1114
import java.io.FileNotFoundException;
1215
import java.io.FileOutputStream;
1316
import java.io.IOException;
1417
import java.nio.file.Path;
15-
import java.util.Collections;
16-
import java.util.Enumeration;
1718
import java.util.jar.JarEntry;
18-
import java.util.jar.JarFile;
1919
import java.util.jar.JarOutputStream;
2020

2121
import static org.junit.jupiter.api.Assertions.*;
@@ -27,21 +27,38 @@ void testLoadAllClassesWithNoClasspath() throws IOException {
2727
String originalClasspath = System.getProperty("java.class.path");
2828
try {
2929
System.clearProperty("java.class.path");
30-
ClasspathLoader.main(new String[]{});
30+
ClasspathLoader.main(new String[] {});
3131
} finally {
3232
if (originalClasspath != null) {
3333
System.setProperty("java.class.path", originalClasspath);
3434
}
3535
}
3636
}
3737

38+
// On JDK 8-24, new File("").exists() returns false → FileNotFoundException.
3839
@Test
40+
@DisabledForJreRange(min = JRE.JAVA_25)
3941
void testLoadAllClassesWithEmptyClasspath() {
4042
String originalClasspath = System.getProperty("java.class.path");
4143
try {
4244
System.setProperty("java.class.path", "");
43-
assertThrows(FileNotFoundException.class, () ->
44-
ClasspathLoader.main(new String[]{}));
45+
assertThrows(FileNotFoundException.class, () -> ClasspathLoader.main(new String[] {}));
46+
} finally {
47+
if (originalClasspath != null) {
48+
System.setProperty("java.class.path", originalClasspath);
49+
}
50+
}
51+
}
52+
53+
// On JDK 25+, new File("") resolves to cwd (exists=true, isDirectory=true) →
54+
// skipped with warning, no exception.
55+
@Test
56+
@EnabledForJreRange(min = JRE.JAVA_25)
57+
void testLoadAllClassesWithEmptyClasspathJdk25Plus() throws IOException {
58+
String originalClasspath = System.getProperty("java.class.path");
59+
try {
60+
System.setProperty("java.class.path", "");
61+
ClasspathLoader.main(new String[] {});
4562
} finally {
4663
if (originalClasspath != null) {
4764
System.setProperty("java.class.path", originalClasspath);
@@ -54,8 +71,7 @@ void testLoadAllClassesWithInvalidPath() {
5471
String originalClasspath = System.getProperty("java.class.path");
5572
try {
5673
System.setProperty("java.class.path", "nonexistent/path");
57-
assertThrows(FileNotFoundException.class, () ->
58-
ClasspathLoader.main(new String[]{}));
74+
assertThrows(FileNotFoundException.class, () -> ClasspathLoader.main(new String[] {}));
5975
} finally {
6076
if (originalClasspath != null) {
6177
System.setProperty("java.class.path", originalClasspath);
@@ -69,7 +85,7 @@ void testLoadAllClassesWithValidJar(@TempDir Path tempDir) throws IOException {
6985
String originalClasspath = System.getProperty("java.class.path");
7086
try {
7187
System.setProperty("java.class.path", jarFile.getAbsolutePath());
72-
ClasspathLoader.main(new String[]{});
88+
ClasspathLoader.main(new String[] {});
7389
} finally {
7490
if (originalClasspath != null) {
7591
System.setProperty("java.class.path", originalClasspath);
@@ -82,7 +98,7 @@ void testLoadAllClassesWithDirectory(@TempDir Path tempDir) throws IOException {
8298
String originalClasspath = System.getProperty("java.class.path");
8399
try {
84100
System.setProperty("java.class.path", tempDir.toString());
85-
ClasspathLoader.main(new String[]{});
101+
ClasspathLoader.main(new String[] {});
86102
} finally {
87103
if (originalClasspath != null) {
88104
System.setProperty("java.class.path", originalClasspath);
@@ -94,14 +110,14 @@ void testLoadAllClassesWithDirectory(@TempDir Path tempDir) throws IOException {
94110
void testLoadAllClassesWithMultipleEntries(@TempDir Path tempDir) throws IOException {
95111
File jarFile1 = createSimpleJar(tempDir, "test1.jar", "TestClass1");
96112
File jarFile2 = createSimpleJar(tempDir, "test2.jar", "TestClass2");
97-
113+
98114
String originalClasspath = System.getProperty("java.class.path");
99115
try {
100-
String newClasspath = jarFile1.getAbsolutePath() +
101-
File.pathSeparator +
102-
jarFile2.getAbsolutePath();
116+
String newClasspath = jarFile1.getAbsolutePath() +
117+
File.pathSeparator +
118+
jarFile2.getAbsolutePath();
103119
System.setProperty("java.class.path", newClasspath);
104-
ClasspathLoader.main(new String[]{});
120+
ClasspathLoader.main(new String[] {});
105121
} finally {
106122
if (originalClasspath != null) {
107123
System.setProperty("java.class.path", originalClasspath);
@@ -112,7 +128,7 @@ void testLoadAllClassesWithMultipleEntries(@TempDir Path tempDir) throws IOExcep
112128
@Test
113129
void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOException {
114130
File jarFile = tempDir.resolve("blocklist-test.jar").toFile();
115-
131+
116132
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile))) {
117133
JarEntry blockedEntry = new JarEntry("META-INF/versions/9/module-info.class");
118134
jos.putNextEntry(blockedEntry);
@@ -128,8 +144,9 @@ void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOExce
128144
String originalClasspath = System.getProperty("java.class.path");
129145
try {
130146
System.setProperty("java.class.path", jarFile.getAbsolutePath());
131-
ClasspathLoader.main(new String[]{});
132-
// The test passes if no exception is thrown and the blocklisted class is skipped
147+
ClasspathLoader.main(new String[] {});
148+
// The test passes if no exception is thrown and the blocklisted class is
149+
// skipped
133150
} finally {
134151
if (originalClasspath != null) {
135152
System.setProperty("java.class.path", originalClasspath);
@@ -139,15 +156,15 @@ void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOExce
139156

140157
private File createSimpleJar(Path tempDir, String jarName, String className) throws IOException {
141158
File jarFile = tempDir.resolve(jarName).toFile();
142-
159+
143160
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile))) {
144161
// Add a simple non-class file to make it a valid jar
145162
JarEntry entry = new JarEntry("com/test/" + className + ".txt");
146163
jos.putNextEntry(entry);
147164
jos.write("test content".getBytes());
148165
jos.closeEntry();
149166
}
150-
167+
151168
return jarFile;
152169
}
153170
}

0 commit comments

Comments
 (0)