66package com .amazonaws .services .lambda .runtime .api .client ;
77
88import 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 ;
129import org .junit .jupiter .api .io .TempDir ;
1310import java .io .File ;
1411import java .io .FileNotFoundException ;
1512import java .io .FileOutputStream ;
1613import java .io .IOException ;
1714import java .nio .file .Path ;
15+ import java .util .Collections ;
16+ import java .util .Enumeration ;
1817import java .util .jar .JarEntry ;
18+ import java .util .jar .JarFile ;
1919import java .util .jar .JarOutputStream ;
2020
2121import static org .junit .jupiter .api .Assertions .*;
@@ -27,38 +27,21 @@ 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.
3938 @ Test
40- @ DisabledForJreRange (min = JRE .JAVA_25 )
4139 void testLoadAllClassesWithEmptyClasspath () {
4240 String originalClasspath = System .getProperty ("java.class.path" );
4341 try {
4442 System .setProperty ("java.class.path" , "" );
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 [] {});
43+ assertThrows (FileNotFoundException .class , () ->
44+ ClasspathLoader .main (new String []{}));
6245 } finally {
6346 if (originalClasspath != null ) {
6447 System .setProperty ("java.class.path" , originalClasspath );
@@ -71,7 +54,8 @@ void testLoadAllClassesWithInvalidPath() {
7154 String originalClasspath = System .getProperty ("java.class.path" );
7255 try {
7356 System .setProperty ("java.class.path" , "nonexistent/path" );
74- assertThrows (FileNotFoundException .class , () -> ClasspathLoader .main (new String [] {}));
57+ assertThrows (FileNotFoundException .class , () ->
58+ ClasspathLoader .main (new String []{}));
7559 } finally {
7660 if (originalClasspath != null ) {
7761 System .setProperty ("java.class.path" , originalClasspath );
@@ -85,7 +69,7 @@ void testLoadAllClassesWithValidJar(@TempDir Path tempDir) throws IOException {
8569 String originalClasspath = System .getProperty ("java.class.path" );
8670 try {
8771 System .setProperty ("java.class.path" , jarFile .getAbsolutePath ());
88- ClasspathLoader .main (new String [] {});
72+ ClasspathLoader .main (new String []{});
8973 } finally {
9074 if (originalClasspath != null ) {
9175 System .setProperty ("java.class.path" , originalClasspath );
@@ -98,7 +82,7 @@ void testLoadAllClassesWithDirectory(@TempDir Path tempDir) throws IOException {
9882 String originalClasspath = System .getProperty ("java.class.path" );
9983 try {
10084 System .setProperty ("java.class.path" , tempDir .toString ());
101- ClasspathLoader .main (new String [] {});
85+ ClasspathLoader .main (new String []{});
10286 } finally {
10387 if (originalClasspath != null ) {
10488 System .setProperty ("java.class.path" , originalClasspath );
@@ -110,14 +94,14 @@ void testLoadAllClassesWithDirectory(@TempDir Path tempDir) throws IOException {
11094 void testLoadAllClassesWithMultipleEntries (@ TempDir Path tempDir ) throws IOException {
11195 File jarFile1 = createSimpleJar (tempDir , "test1.jar" , "TestClass1" );
11296 File jarFile2 = createSimpleJar (tempDir , "test2.jar" , "TestClass2" );
113-
97+
11498 String originalClasspath = System .getProperty ("java.class.path" );
11599 try {
116- String newClasspath = jarFile1 .getAbsolutePath () +
117- File .pathSeparator +
118- jarFile2 .getAbsolutePath ();
100+ String newClasspath = jarFile1 .getAbsolutePath () +
101+ File .pathSeparator +
102+ jarFile2 .getAbsolutePath ();
119103 System .setProperty ("java.class.path" , newClasspath );
120- ClasspathLoader .main (new String [] {});
104+ ClasspathLoader .main (new String []{});
121105 } finally {
122106 if (originalClasspath != null ) {
123107 System .setProperty ("java.class.path" , originalClasspath );
@@ -128,7 +112,7 @@ void testLoadAllClassesWithMultipleEntries(@TempDir Path tempDir) throws IOExcep
128112 @ Test
129113 void testLoadAllClassesWithBlocklistedClass (@ TempDir Path tempDir ) throws IOException {
130114 File jarFile = tempDir .resolve ("blocklist-test.jar" ).toFile ();
131-
115+
132116 try (JarOutputStream jos = new JarOutputStream (new FileOutputStream (jarFile ))) {
133117 JarEntry blockedEntry = new JarEntry ("META-INF/versions/9/module-info.class" );
134118 jos .putNextEntry (blockedEntry );
@@ -144,9 +128,8 @@ void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOExce
144128 String originalClasspath = System .getProperty ("java.class.path" );
145129 try {
146130 System .setProperty ("java.class.path" , jarFile .getAbsolutePath ());
147- ClasspathLoader .main (new String [] {});
148- // The test passes if no exception is thrown and the blocklisted class is
149- // skipped
131+ ClasspathLoader .main (new String []{});
132+ // The test passes if no exception is thrown and the blocklisted class is skipped
150133 } finally {
151134 if (originalClasspath != null ) {
152135 System .setProperty ("java.class.path" , originalClasspath );
@@ -156,15 +139,15 @@ void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOExce
156139
157140 private File createSimpleJar (Path tempDir , String jarName , String className ) throws IOException {
158141 File jarFile = tempDir .resolve (jarName ).toFile ();
159-
142+
160143 try (JarOutputStream jos = new JarOutputStream (new FileOutputStream (jarFile ))) {
161144 // Add a simple non-class file to make it a valid jar
162145 JarEntry entry = new JarEntry ("com/test/" + className + ".txt" );
163146 jos .putNextEntry (entry );
164147 jos .write ("test content" .getBytes ());
165148 jos .closeEntry ();
166149 }
167-
150+
168151 return jarFile ;
169152 }
170153}
0 commit comments