This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
DiscoveryHelper.java
55 lines (46 loc) · 2.05 KB
/
DiscoveryHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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<EngineDescriptor, Class<?>> 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...
}
}