in src/main/java/org/apache/sling/junit/impl/BundleTestsProvider.java [104:137]
private static Set<String> getTestClasses(Bundle bundle) {
final String headerValue = getSlingTestRegexp(bundle);
if (headerValue == null) {
LOG.debug("Bundle '{}' does not have {} header, not looking for test classes",
bundle.getSymbolicName(), SLING_TEST_REGEXP);
return Collections.emptySet();
}
Predicate<String> isTestClass;
try {
final Pattern testClassRegexp = Pattern.compile(headerValue);
isTestClass = name -> testClassRegexp.matcher(name).matches();
} catch (PatternSyntaxException pse) {
LOG.warn("Bundle '{}' has an invalid pattern for {} header, ignored: '{}', message: '{}'",
bundle.getSymbolicName(), SLING_TEST_REGEXP, headerValue, pse.getMessage());
return Collections.emptySet();
}
Enumeration<URL> classUrls = bundle.findEntries("", "*.class", true);
final Set<String> result = new LinkedHashSet<>();
while (classUrls.hasMoreElements()) {
URL url = classUrls.nextElement();
final String name = toClassName(url);
if(isTestClass.test(name)) {
result.add(name);
} else {
LOG.debug("Class '{}' does not match {} pattern '{}' of bundle '{}', ignored",
name, SLING_TEST_REGEXP, headerValue, bundle.getSymbolicName());
}
}
LOG.info("{} test classes found in bundle '{}'", result.size(), bundle.getSymbolicName());
return result;
}