From dfd0bba58bfdacfd8802ee07c8f83ee794a51aba Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Mon, 30 May 2011 11:58:46 -0700 Subject: [PATCH 1/2] Update ParentRunner to make a copy of the List returned by getChildren() Fixes issue #227 --- .../java/org/junit/runners/ParentRunner.java | 2 +- .../classes/ParentRunnerFilteringTest.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/junit/runners/ParentRunner.java b/src/main/java/org/junit/runners/ParentRunner.java index 520561784f38..32c92ac5cf45 100644 --- a/src/main/java/org/junit/runners/ParentRunner.java +++ b/src/main/java/org/junit/runners/ParentRunner.java @@ -357,7 +357,7 @@ private void validate() throws InitializationError { private List getFilteredChildren() { if (fFilteredChildren == null) - fFilteredChildren = getChildren(); + fFilteredChildren = new ArrayList(getChildren()); return fFilteredChildren; } diff --git a/src/test/java/org/junit/tests/running/classes/ParentRunnerFilteringTest.java b/src/test/java/org/junit/tests/running/classes/ParentRunnerFilteringTest.java index 0c8efe36b619..9bf542f824c6 100644 --- a/src/test/java/org/junit/tests/running/classes/ParentRunnerFilteringTest.java +++ b/src/test/java/org/junit/tests/running/classes/ParentRunnerFilteringTest.java @@ -8,7 +8,9 @@ import static org.junit.runner.Description.createSuiteDescription; import static org.junit.runner.Description.createTestDescription; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.Test; @@ -22,6 +24,8 @@ import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.RunnerBuilder; public class ParentRunnerFilteringTest { private static Filter notThisMethodName(final String methodName) { @@ -91,6 +95,38 @@ public void testSuiteFiltering() throws Exception { fail("Expected 'NoTestsRemainException' due to complete filtering"); } + public static class SuiteWithUnmodifyableChildList extends Suite { + + public SuiteWithUnmodifyableChildList( + Class klass, RunnerBuilder builder) + throws InitializationError { + super(klass, builder); + } + + @Override + protected List getChildren() { + return Collections.unmodifiableList(super.getChildren()); + } + } + + @RunWith(SuiteWithUnmodifyableChildList.class) + @SuiteClasses({ ExampleTest.class }) + public static class ExampleSuiteWithUnmodifyableChildList { + } + + @Test + public void testSuiteFilteringWithUnmodifyableChildList() throws Exception { + Runner runner= Request.aClass(ExampleSuiteWithUnmodifyableChildList.class) + .getRunner(); + Filter filter= notThisMethodName("test1"); + try { + filter.apply(runner); + } catch (NoTestsRemainException e) { + return; + } + fail("Expected 'NoTestsRemainException' due to complete filtering"); + } + @Test public void testRunSuiteFiltering() throws Exception { Request request= Request.aClass(ExampleSuite.class); From de8dfa6dcaf4353c5e399ff976db6803db73f9bd Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Tue, 31 May 2011 21:31:53 -0700 Subject: [PATCH 2/2] Update ackowledgements for kcooney --- acknowledgements.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/acknowledgements.txt b/acknowledgements.txt index 75843045a1b7..d8c36728b074 100644 --- a/acknowledgements.txt +++ b/acknowledgements.txt @@ -71,9 +71,9 @@ Markus Keller: Reported bug (github#163): Bad comparison failure message when using assertEquals(String, String) - Kevin Cooney (kcooney): - Patches for runLeaf, public multiple failure exception, abstract base - class for TestRule, assertion messages and null. + Kevin Cooney (kcooney@github): + Patches for runLeaf, public multiple failure exception, + assertion messages and null. 2011 Mar 04 Jerome Lacoste (lacostej@github) for initial patch for GH-191. @@ -87,3 +87,8 @@ 2011 Apr 29 reinholdfuereder@github: bug report, test, and fix for GH-38: ParentRunner filtering +2011 May 31 + Kevin Cooney (kcooney@github): Patches for filtering test suites: + copy List returned by getChildren() before mutating it; + optimize ParentRunner.filter for nested suites; + optimize Filter.intersect for common cases