Skip to content

Commit 7a98d8d

Browse files
committed
fix: Java 1.8 compatibility in PublicApiBeanContractTest
- Replace Path.of() with Paths.get() (Java 11+ -> Java 8) - Replace var with explicit type (Java 10+ -> Java 8) - Replace List.of/Set.of/Map.of with Collections methods (Java 9+ -> Java 8) - Replace .toList() with .collect(Collectors.toList()) (Java 16+ -> Java 8)
1 parent d11c999 commit 7a98d8d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎src/test/java/io/github/easy4j/openclaw/PublicApiBeanContractTest.java‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
import java.net.URI;
1111
import java.nio.file.Files;
1212
import java.nio.file.Path;
13+
import java.nio.file.Paths;
14+
import java.util.stream.Collectors;
1315
import java.time.Duration;
1416
import java.util.ArrayList;
1517
import java.util.Arrays;
18+
import java.util.Collections;
1619
import java.util.Collection;
1720
import java.util.Comparator;
1821
import java.util.LinkedHashMap;
@@ -68,10 +71,11 @@ void shouldExerciseEveryModelAndCliOptionContract() throws Exception {
6871
}
6972

7073
private List<Class<?>> discoverContractTypes() throws Exception {
71-
Path classesRoot = Path.of(OpenClawClient.class.getProtectionDomain().getCodeSource().getLocation().toURI());
74+
Path classesRoot = Paths.get(OpenClawClient.class.getProtectionDomain().getCodeSource().getLocation().toURI());
7275
List<Class<?>> result = new ArrayList<>();
73-
try (var paths = Files.walk(classesRoot)) {
74-
for (Path path : paths.filter(value -> value.toString().endsWith(".class")).toList()) {
76+
java.util.stream.Stream<Path> paths = Files.walk(classesRoot);
77+
try {
78+
for (Path path : paths.filter(value -> value.toString().endsWith(".class")).collect(Collectors.toList())) {
7579
String name = classesRoot.relativize(path).toString()
7680
.replace(File.separatorChar, '.')
7781
.replaceAll("\\.class$", "");
@@ -80,6 +84,8 @@ private List<Class<?>> discoverContractTypes() throws Exception {
8084
result.add(Class.forName(name));
8185
}
8286
}
87+
} finally {
88+
paths.close();
8389
}
8490
result.sort(Comparator.comparing(Class::getName));
8591
return result;
@@ -189,13 +195,13 @@ private Object sampleValue(Class<?> type) {
189195
if (type == byte.class || type == Byte.class) return (byte) 1;
190196
if (type == char.class || type == Character.class) return 'x';
191197
if (type == Duration.class) return Duration.ofSeconds(1);
192-
if (type == Path.class) return Path.of("target");
198+
if (type == Path.class) return Paths.get("target");
193199
if (type == File.class) return new File("target");
194200
if (type == URI.class) return URI.create("http://localhost");
195201
if (type == Optional.class) return Optional.of("value");
196-
if (type == List.class || type == Collection.class) return List.of("value");
197-
if (type == Set.class) return Set.of("value");
198-
if (type == Map.class) return Map.of("key", "value");
202+
if (type == List.class || type == Collection.class) return Collections.singletonList("value");
203+
if (type == Set.class) return Collections.singleton("value");
204+
if (type == Map.class) return Collections.singletonMap("key", "value");
199205
if (type == Consumer.class) return (Consumer<Object>) ignored -> { };
200206
if (type == Supplier.class) return (Supplier<Object>) () -> "value";
201207
if (type.isArray()) {

0 commit comments

Comments
 (0)