1
1
package org .junit .runner ;
2
2
3
- import java .util .HashSet ;
4
- import java .util .Set ;
5
-
3
+ import org .hamcrest .Matcher ;
6
4
import org .junit .Before ;
7
5
import org .junit .Test ;
8
6
import org .junit .experimental .categories .Category ;
9
7
import org .junit .experimental .categories .ExcludeCategories ;
10
8
import org .junit .experimental .categories .IncludeCategories ;
11
- import org .junit .runner .notification .RunListener ;
12
9
import org .junit .tests .TestSystem ;
10
+ import org .junit .testsupport .EventCollector ;
13
11
12
+ import static org .hamcrest .CoreMatchers .allOf ;
14
13
import static org .hamcrest .CoreMatchers .is ;
14
+ import static org .hamcrest .CoreMatchers .not ;
15
15
import static org .hamcrest .MatcherAssert .assertThat ;
16
- import static org .junit .Assert . assertFalse ;
17
- import static org .junit .Assert . assertTrue ;
16
+ import static org .junit .testsupport . EventCollectorMatchers . hasTestFinished ;
17
+ import static org .junit .testsupport . EventCollectorMatchers . hasTestStarted ;
18
18
19
19
public class FilterOptionIntegrationTest {
20
20
private static final String INCLUDES_DUMMY_CATEGORY_0 = "--filter=" +
@@ -23,7 +23,7 @@ public class FilterOptionIntegrationTest {
23
23
ExcludeCategories .class .getName () + "=" + DummyCategory1 .class .getName ();
24
24
25
25
private JUnitCore jUnitCore = new JUnitCore ();
26
- private TestListener testListener = new TestListener ();
26
+ private EventCollector testListener = new EventCollector ();
27
27
28
28
@ Before
29
29
public void setUp () {
@@ -111,40 +111,15 @@ private Result runJUnit(final String... args) {
111
111
}
112
112
113
113
private void assertWasRun (Class <?> testClass ) {
114
- assertTrue ( testClass . getName () + " expected to finish but did not" , testListener . wasRun (testClass ));
114
+ assertThat ( testListener , wasRun (testClass ));
115
115
}
116
116
117
117
private void assertWasNotRun (Class <?> testClass ) {
118
- assertFalse (
119
- testClass .getName () + " expected not to have been started but was" ,
120
- testListener .wasRun (testClass ));
118
+ assertThat (testListener , not (wasRun (testClass )));
121
119
}
122
120
123
- private static class TestListener extends RunListener {
124
- private Set <String > startedTests = new HashSet <String >();
125
- private Set <String > finishedTests = new HashSet <String >();
126
-
127
- @ Override
128
- public void testFinished (final Description description ) {
129
- finishedTests .add (description .getClassName ());
130
- }
131
-
132
- private boolean testFinished (final Class <?> testClass ) {
133
- return finishedTests .contains (testClass .getName ());
134
- }
135
-
136
- @ Override
137
- public void testStarted (final Description description ) {
138
- startedTests .add (description .getClassName ());
139
- }
140
-
141
- private boolean testStarted (final Class <?> testClass ) {
142
- return startedTests .contains (testClass .getName ());
143
- }
144
-
145
- public boolean wasRun (final Class <?> testClass ) {
146
- return testStarted (testClass ) && testFinished (testClass );
147
- }
121
+ private Matcher <EventCollector > wasRun (Class <?> testClass ) {
122
+ return allOf (hasTestStarted (testClass ), hasTestFinished (testClass ));
148
123
}
149
124
150
125
public static class DummyTestClass {
0 commit comments