Skip to content

Commit feb2a30

Browse files
committed
Improve precondition checks in TestClassScanner
1 parent 41e8683 commit feb2a30

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spring-test/src/main/java/org/springframework/test/context/aot/TestClassScanner.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.test.context.aot;
1818

1919
import java.lang.annotation.Annotation;
20+
import java.nio.file.Files;
2021
import java.nio.file.Path;
2122
import java.util.Arrays;
2223
import java.util.Comparator;
@@ -103,9 +104,7 @@ class TestClassScanner {
103104
* @param classpathRoots the classpath roots to scan
104105
*/
105106
TestClassScanner(Set<Path> classpathRoots) {
106-
Assert.notEmpty(classpathRoots, "'classpathRoots' must not be null or empty");
107-
Assert.noNullElements(classpathRoots, "'classpathRoots' must not contain null elements");
108-
this.classpathRoots = classpathRoots;
107+
this.classpathRoots = assertPreconditions(classpathRoots);
109108
}
110109

111110

@@ -207,4 +206,13 @@ private static boolean isGenericSpringTestClass(Class<?> clazz) {
207206
mergedAnnotations.isPresent(BootstrapWith.class));
208207
}
209208

209+
210+
private static Set<Path> assertPreconditions(Set<Path> classpathRoots) {
211+
Assert.notEmpty(classpathRoots, "'classpathRoots' must not be null or empty");
212+
Assert.noNullElements(classpathRoots, "'classpathRoots' must not contain null elements");
213+
classpathRoots.forEach(classpathRoot -> Assert.isTrue(Files.exists(classpathRoot),
214+
() -> "Classpath root [%s] does not exist".formatted(classpathRoot)));
215+
return classpathRoots;
216+
}
217+
210218
}

0 commit comments

Comments
 (0)