-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
RootTestDescriptor.java
141 lines (115 loc) · 3.31 KB
/
RootTestDescriptor.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright 2015 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 static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestEngine;
import org.junit.gen5.engine.TestPlanSpecification;
import org.junit.gen5.engine.TestSource;
import org.junit.gen5.engine.TestTag;
/**
* @since 5.0
*/
final class RootTestDescriptor implements TestDescriptor {
private final HashMap<String, TestDescriptor> engineRootTestDescriptors = new HashMap<>();
void addTestDescriptorForEngine(TestEngine testEngine, TestDescriptor testDescriptor) {
engineRootTestDescriptors.put(testEngine.getId(), testDescriptor);
}
Collection<TestDescriptor> getEngineRootTestDescriptors() {
return Collections.unmodifiableCollection(engineRootTestDescriptors.values());
}
@Override
public long countStaticTests() {
return this.engineRootTestDescriptors.values().stream().mapToLong(
engineDescriptor -> engineDescriptor.countStaticTests()).sum();
}
Optional<TestDescriptor> getTestDescriptorFor(TestEngine testEngine) {
return Optional.of(this.engineRootTestDescriptors.get(testEngine.getId()));
}
@Override
public String getUniqueId() {
return "testplan";
}
@Override
public String getDisplayName() {
return "Test Plan";
}
@Override
public Optional<TestDescriptor> getParent() {
return Optional.empty();
}
@Override
public boolean isTest() {
return false;
}
@Override
public Set<TestTag> getTags() {
return emptySet();
}
@Override
public Set<TestDescriptor> getChildren() {
return engineRootTestDescriptors.values().stream().collect(toCollection(HashSet::new));
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this, () -> {
// the test plan itself will never be removed
});
new HashSet<>(engineRootTestDescriptors.values()).forEach(child -> child.accept(visitor));
}
@Override
public Optional<TestSource> getSource() {
return Optional.empty();
}
void applyFilters(TestPlanSpecification specification) {
Visitor filteringVisitor = (descriptor, remove) -> {
if (!descriptor.isTest())
return;
if (!specification.acceptDescriptor(descriptor))
remove.run();
};
accept(filteringVisitor);
}
void prune() {
Visitor pruningVisitor = (descriptor, remove) -> {
if (descriptor.isRoot() || descriptor.hasTests())
return;
remove.run();
};
accept(pruningVisitor);
}
@Override
public String toString() {
return engineRootTestDescriptors.values().toString();
}
@Override
public void setParent(TestDescriptor parent) {
throw new UnsupportedOperationException();
}
@Override
public boolean isContainer() {
return true;
}
@Override
public void addChild(TestDescriptor descriptor) {
// TODO Auto-generated method stub
}
@Override
public void removeChild(TestDescriptor descriptor) {
// TODO Auto-generated method stub
}
}