From 4e9fad7514479cdbd762635f6f70bdaf796e8981 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 9 Sep 2022 16:57:01 +0200 Subject: [PATCH] Revise TestAotProcessorTests to rely on Path APIs Instead of String comparisons, assertions are now based on Path comparisons. See gh-29103 --- .../context/aot/TestAotProcessorTests.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestAotProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestAotProcessorTests.java index 634af8817d..97dc489de2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/TestAotProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/TestAotProcessorTests.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -64,11 +66,11 @@ class TestAotProcessorTests extends AbstractAotTests { TestAotProcessor processor = new TestAotProcessor(classpathRoots, sourceOutput, resourceOutput, classOutput, groupId, artifactId); processor.process(); - assertThat(findFiles(sourceOutput)).containsExactlyInAnyOrder(expectedSourceFiles); + assertThat(findFiles(sourceOutput)).containsExactlyInAnyOrderElementsOf(expectedSourceFiles()); assertThat(findFiles(resourceOutput.resolve("META-INF/native-image"))).contains( - "org.example/app-tests/reflect-config.json", - "org.example/app-tests/resource-config.json"); + Path.of(groupId, artifactId, "reflect-config.json"), + Path.of(groupId, artifactId, "resource-config.json")); } private void copy(Class testClass, Path destination) { @@ -84,11 +86,13 @@ class TestAotProcessorTests extends AbstractAotTests { } } - private static Stream findFiles(Path directory) throws IOException { + private static Stream findFiles(Path directory) throws IOException { return Files.walk(directory).filter(Files::isRegularFile) - .map(path -> path.subpath(directory.getNameCount(), path.getNameCount())) - // Convert Windows path to UNIX path since the expectedSourceFiles array is hard coded - .map(path -> path.toString().replace('\\', '/')); + .map(path -> path.subpath(directory.getNameCount(), path.getNameCount())); + } + + private static List expectedSourceFiles() { + return Arrays.stream(expectedSourceFiles).map(Path::of).toList(); } private static final String[] expectedSourceFiles = {