Improve precondition checks in TestClassScanner
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.test.context.aot;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
@@ -103,9 +104,7 @@ class TestClassScanner {
|
||||
* @param classpathRoots the classpath roots to scan
|
||||
*/
|
||||
TestClassScanner(Set<Path> classpathRoots) {
|
||||
Assert.notEmpty(classpathRoots, "'classpathRoots' must not be null or empty");
|
||||
Assert.noNullElements(classpathRoots, "'classpathRoots' must not contain null elements");
|
||||
this.classpathRoots = classpathRoots;
|
||||
this.classpathRoots = assertPreconditions(classpathRoots);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,4 +206,13 @@ class TestClassScanner {
|
||||
mergedAnnotations.isPresent(BootstrapWith.class));
|
||||
}
|
||||
|
||||
|
||||
private static Set<Path> assertPreconditions(Set<Path> classpathRoots) {
|
||||
Assert.notEmpty(classpathRoots, "'classpathRoots' must not be null or empty");
|
||||
Assert.noNullElements(classpathRoots, "'classpathRoots' must not contain null elements");
|
||||
classpathRoots.forEach(classpathRoot -> Assert.isTrue(Files.exists(classpathRoot),
|
||||
() -> "Classpath root [%s] does not exist".formatted(classpathRoot)));
|
||||
return classpathRoots;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user