Skip to content

Commit

Permalink
DefaultLauncher no longer prunes TestDescriptor trees
Browse files Browse the repository at this point in the history
Closes #732.
  • Loading branch information
marcphilipp committed Jun 18, 2017
1 parent 8101e24 commit 936a919
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 44 deletions.
4 changes: 4 additions & 0 deletions documentation/src/docs/asciidoc/release-notes-5.0.0-M5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ is placed on the Java 9 module path.
- `junit-platform-commons`: `ReflectionUtils.findAllClassesInClasspathRoot(Path, Predicate, Predicate)`
* The `isLeaf()` method of the `org.junit.platform.engine.support.hierarchical.Node`
interface has been removed.
* The default methods `prune()` and `pruneTree()` have been removed from `TestDescriptor`.
* The `DefaultLauncher` no longer prunes trees of `TestDescriptors` it receives from test
engines. It's the responsibility of test engines to only return `TestDescriptors` they
wish to execute.

===== New Features and Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ public void resolveSelectors(EngineDiscoveryRequest request, TestDescriptor engi
request.getSelectorsByType(UniqueIdSelector.class).forEach(selector -> {
javaElementsResolver.resolveUniqueId(selector.getUniqueId());
});
engineDescriptor.pruneTree();
pruneTree(engineDescriptor);
}

private void pruneTree(TestDescriptor engineDescriptor) {
engineDescriptor.accept(testDescriptor -> {
if (testDescriptor.isRoot() || testDescriptor.hasTests()) {
return;
}
testDescriptor.removeFromHierarchy();
});
}

private JavaElementsResolver createJavaElementsResolver(TestDescriptor engineDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,37 +195,6 @@ default boolean hasTests() {
return isTest() || getChildren().stream().anyMatch(TestDescriptor::hasTests);
}

/**
* Remove this descriptor from the hierarchy unless it is a root or has tests.
*
* <p>A concrete {@link TestEngine} may override this method in order to implement
* a different algorithm or to skip pruning altogether.
*
* @see #isRoot()
* @see #hasTests()
* @see #removeFromHierarchy()
*/
default void prune() {
if (isRoot() || hasTests()) {
return;
}
removeFromHierarchy();
}

/**
* Remove this descriptor and its descendants from the hierarchy.
*
* <p>The default implementation supplies the {@link #prune()} method as a
* {@link Visitor} to this descriptor, thereby effectively removing this
* descriptor and all of its descendants.
*
* @see #accept(Visitor)
* @see #prune()
*/
default void pruneTree() {
accept(TestDescriptor::prune);
}

/**
* Find the descriptor with the supplied unique ID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private Root discoverRoot(LauncherDiscoveryRequest discoveryRequest, String phas
engineRoot.ifPresent(rootDescriptor -> root.add(testEngine, rootDescriptor));
}
root.applyPostDiscoveryFilters(discoveryRequest);
root.prune();
return root;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ void applyPostDiscoveryFilters(LauncherDiscoveryRequest discoveryRequest) {
acceptInAllTestEngines(removeExcludedTestDescriptors);
}

/**
* Prune all branches in the tree of {@link TestDescriptor TestDescriptors}
* that do not have executable tests.
*
* <p>If a {@link TestEngine} ends up with no {@code TestDescriptors} after
* pruning, it will <strong>not</strong> be removed.
*/
void prune() {
acceptInAllTestEngines(TestDescriptor::prune);
}

private boolean isExcluded(TestDescriptor descriptor, Filter<TestDescriptor> postDiscoveryFilter) {
return descriptor.getChildren().isEmpty() && postDiscoveryFilter.apply(descriptor).excluded();
}
Expand Down

0 comments on commit 936a919

Please sign in to comment.