1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.common.junit48;
20
21 import junit.framework.JUnit4TestAdapter;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import junit.runner.Version;
25 import org.apache.maven.surefire.common.junit48.tests.group.ABCParameterizedTest;
26 import org.apache.maven.surefire.common.junit48.tests.group.ABCTest;
27 import org.apache.maven.surefire.common.junit48.tests.group.ATest;
28 import org.apache.maven.surefire.common.junit48.tests.group.BCTest;
29 import org.apache.maven.surefire.group.match.GroupMatcher;
30 import org.apache.maven.surefire.group.match.SingleGroupMatcher;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.runner.Description.createSuiteDescription;
36 import static org.junit.runner.Description.createTestDescription;
37
38
39
40
41 public class GroupMatcherCategoryFilterPreJUnit412Test {
42 private GroupMatcherCategoryFilter cut;
43
44 @BeforeClass
45 public static void printVersion() {
46 System.out.println(Version.id());
47 }
48
49 @Test
50 public void shouldNotMatchIncludedCategoryInParent() {
51 GroupMatcher included =
52 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
53 GroupMatcher excluded = null;
54 cut = new GroupMatcherCategoryFilter(included, excluded);
55 assertFalse(cut.shouldRun(createSuiteDescription(BCTest.class)));
56 assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
57 }
58
59 @Test
60 public void shouldNotMatchIncludedCategoryInHierarchy() {
61 GroupMatcher included =
62 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryC");
63 GroupMatcher excluded = null;
64 cut = new GroupMatcherCategoryFilter(included, excluded);
65 assertFalse(cut.shouldRun(createSuiteDescription(ABCTest.class)));
66 assertFalse(cut.shouldRun(createSuiteDescription(BCTest.class)));
67 assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
68 }
69
70 @Test
71 public void shouldNotMatchIncludedCategoryInParentWhenSelfHasAnother() {
72 GroupMatcher included =
73 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
74 GroupMatcher excluded = null;
75 cut = new GroupMatcherCategoryFilter(included, excluded);
76 assertFalse(cut.shouldRun(createSuiteDescription(ABCTest.class)));
77 assertFalse(cut.shouldRun(createTestDescription(ABCTest.class, "abc")));
78 assertFalse(cut.shouldRun(createSuiteDescription(ABCParameterizedTest.class)));
79 assertFalse(cut.shouldRun(createTestDescription(ABCParameterizedTest.class, "abc")));
80 }
81
82
83
84
85 public static class JUnit4SuiteTest extends TestCase {
86 public static junit.framework.Test suite() {
87 TestSuite suite = new TestSuite();
88 suite.addTest(new JUnit4TestAdapter(GroupMatcherCategoryFilterPreJUnit412Test.class));
89 return suite;
90 }
91 }
92 }