/
Root.java
66 lines (55 loc) · 1.7 KB
/
Root.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
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2015-2016 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.junit.gen5.launcher;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestDescriptor.Visitor;
import org.junit.gen5.engine.TestEngine;
/**
* @since 5.0
*/
final class Root {
private final Map<TestEngine, TestDescriptor> testEngines = new LinkedHashMap<>();
public void add(TestEngine engine, TestDescriptor testDescriptor) {
testEngines.put(engine, testDescriptor);
}
public Collection<TestDescriptor> getAllTestDescriptors() {
return testEngines.values();
}
Iterable<TestEngine> getTestEngines() {
return testEngines.keySet();
}
TestDescriptor getTestDescriptorFor(TestEngine testEngine) {
return testEngines.get(testEngine);
}
void applyFilters(DiscoveryRequest discoveryRequest) {
Visitor filteringVisitor = (descriptor, remove) -> {
if (!descriptor.isTest())
return;
if (!discoveryRequest.acceptDescriptor(descriptor))
remove.run();
};
accept(filteringVisitor);
}
void accept(Visitor visitor) {
testEngines.values().stream().forEach(testEngine -> testEngine.accept(visitor));
}
void prune() {
Visitor pruningVisitor = (descriptor, remove) -> {
if (descriptor.isRoot() || descriptor.hasTests())
return;
remove.run();
};
accept(pruningVisitor);
testEngines.values().removeIf(testEngine -> testEngine.getChildren().isEmpty());
}
}