Skip to content

Commit

Permalink
Introduce default semantics for Node.isLeaf()
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed May 31, 2016
1 parent 0621ba4 commit 6b46df0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Expand Up @@ -78,11 +78,15 @@ private void execute(TestDescriptor testDescriptor, C parentContext) {
C context = node.before(preparedContext); C context = node.before(preparedContext);
context = node.execute(context); context = node.execute(context);


if (!node.isLeaf()) { // Prevent execution of dynamically added children // If a node is not a leaf, execute its children recursively.
// Note: executing children for a leaf would result in accidental
// execution of dynamically added children.
if (!node.isLeaf()) {
for (TestDescriptor child : testDescriptor.getChildren()) { for (TestDescriptor child : testDescriptor.getChildren()) {
execute(child, context); execute(child, context);
} }
} }

node.after(context); node.after(context);
}); });


Expand All @@ -96,11 +100,6 @@ private Node<C> asNode(TestDescriptor testDescriptor) {


@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Node noOpNode = new Node() { private static final Node noOpNode = new Node() {

@Override
public boolean isLeaf() {
return true;
}
}; };


} }
Expand Up @@ -29,8 +29,12 @@ public interface Node<C extends EngineExecutionContext> {


/** /**
* Determine if this {@code Node} is a leaf in the hierarchy. * Determine if this {@code Node} is a leaf in the hierarchy.
*
* <p>The default implementation returns {@code false}.
*/ */
boolean isLeaf(); default boolean isLeaf() {
return false;
}


/** /**
* Prepare the supplied {@code context} prior to execution. * Prepare the supplied {@code context} prior to execution.
Expand All @@ -54,10 +58,14 @@ default SkipResult shouldBeSkipped(C context) throws Exception {
/** /**
* Execute the <em>before</em> behavior of this node. * Execute the <em>before</em> behavior of this node.
* *
* <p>This method will be called once <em>before</em> executing this node. * <p>This method will be called once <em>before</em> {@linkplain #execute
* execution} of this node.
* *
* @param context the context to execute in * @param context the context to execute in
* @return the new context to be used for children of this node * @return the new context to be used for children of this node
*
* @see #execute
* @see #after
*/ */
default C before(C context) throws Exception { default C before(C context) throws Exception {
return context; return context;
Expand All @@ -69,6 +77,9 @@ default C before(C context) throws Exception {
* @param context the context to execute in * @param context the context to execute in
* @return the new context to be used for children of this node and for the * @return the new context to be used for children of this node and for the
* <em>after</em> behavior of the parent of this node, if any * <em>after</em> behavior of the parent of this node, if any
*
* @see #before
* @see #after
*/ */
default C execute(C context) throws Exception { default C execute(C context) throws Exception {
return context; return context;
Expand All @@ -77,9 +88,13 @@ default C execute(C context) throws Exception {
/** /**
* Execute the <em>after</em> behavior of this node. * Execute the <em>after</em> behavior of this node.
* *
* <p>This method will be called once <em>after</em> executing this node. * <p>This method will be called once <em>after</em> {@linkplain #execute
* execution} of this node.
* *
* @param context the context to execute in * @param context the context to execute in
*
* @see #before
* @see #execute
*/ */
default void after(C context) throws Exception { default void after(C context) throws Exception {
} }
Expand Down
Expand Up @@ -34,9 +34,4 @@ public JUnit5EngineExecutionContext before(JUnit5EngineExecutionContext context)
return context.extend().withExtensionRegistry(createRegistryWithDefaultExtensions()).build(); return context.extend().withExtensionRegistry(createRegistryWithDefaultExtensions()).build();
} }


@Override
public boolean isLeaf() {
return false;
}

} }

0 comments on commit 6b46df0

Please sign in to comment.