org.testng.junit5.DiscoveryHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testng-junit5 Show documentation
Show all versions of testng-junit5 Show documentation
Implementation of the JUnit5 Platform TestEngine interface
The newest version!
package org.testng.junit5;
import static org.junit.platform.commons.util.ReflectionUtils.findAllClassesInClasspathRoot;
import static org.junit.platform.commons.util.ReflectionUtils.findAllClassesInPackage;
import java.util.Collection;
import java.util.function.BiConsumer;
import org.junit.platform.commons.util.ClassFilter;
import org.junit.platform.engine.EngineDiscoveryRequest;
import org.junit.platform.engine.discovery.ClassSelector;
import org.junit.platform.engine.discovery.ClasspathRootSelector;
import org.junit.platform.engine.discovery.PackageSelector;
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
/** This should be in org.junit.platform.engine.support... */
class DiscoveryHelper {
private final EngineDiscoveryRequest engineDiscoveryRequest;
private final ClassFilter classFilter;
DiscoveryHelper(EngineDiscoveryRequest engineDiscoveryRequest, ClassFilter classFilter) {
this.engineDiscoveryRequest = engineDiscoveryRequest;
this.classFilter = classFilter;
}
void discover(EngineDescriptor engine, BiConsumer> handler) {
// class-path root
engineDiscoveryRequest.getSelectorsByType(ClasspathRootSelector.class).stream()
.map(ClasspathRootSelector::getClasspathRoot)
.map(uri -> findAllClassesInClasspathRoot(uri, classFilter))
.flatMap(Collection::stream)
.forEach(candidate -> handler.accept(engine, candidate));
// package
engineDiscoveryRequest.getSelectorsByType(PackageSelector.class).stream()
.map(PackageSelector::getPackageName)
.map(packageName -> findAllClassesInPackage(packageName, classFilter))
.flatMap(Collection::stream)
.forEach(candidate -> handler.accept(engine, candidate));
// class
engineDiscoveryRequest.getSelectorsByType(ClassSelector.class).stream()
.map(ClassSelector::getJavaClass)
.filter(classFilter)
.forEach(candidate -> handler.accept(engine, candidate));
// TODO Add missing selector types...
}
}