Skip to content

Commit

Permalink
Optimize ParentRunner.filter for nested suites
Browse files Browse the repository at this point in the history
Prior to this change, applying a filter to a nested suite would create redundant nested filters
  • Loading branch information
kcooney committed May 31, 2011
1 parent 01b427b commit 5eee07b
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/main/java/org/junit/runners/ParentRunner.java
Expand Up @@ -50,8 +50,6 @@ public abstract class ParentRunner<T> extends Runner implements Filterable,
Sortable {
private final TestClass fTestClass;

private Filter fFilter= Filter.ALL;

private Sorter fSorter= Sorter.NULL;

private List<T> fFilteredChildren= null;
Expand Down Expand Up @@ -319,13 +317,11 @@ public void run(final RunNotifier notifier) {
//

public void filter(Filter filter) throws NoTestsRemainException {
fFilter= fFilter.intersect(filter);

for (Iterator<T> iter = getFilteredChildren().iterator(); iter.hasNext(); ) {
T each = iter.next();
if (shouldRun(each))
if (shouldRun(filter, each))
try {
filterChild(each);
filter.apply(each);
} catch (NoTestsRemainException e) {
iter.remove();
}
Expand Down Expand Up @@ -365,12 +361,8 @@ private void sortChild(T child) {
fSorter.apply(child);
}

private void filterChild(T child) throws NoTestsRemainException {
fFilter.apply(child);
}

private boolean shouldRun(T each) {
return fFilter.shouldRun(describeChild(each));
private boolean shouldRun(Filter filter, T each) {
return filter.shouldRun(describeChild(each));
}

private Comparator<? super T> comparator() {
Expand Down

0 comments on commit 5eee07b

Please sign in to comment.