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.BBCTest;
29 import org.apache.maven.surefire.common.junit48.tests.group.BCTest;
30 import org.apache.maven.surefire.common.junit48.tests.group.BTest;
31 import org.apache.maven.surefire.group.match.GroupMatcher;
32 import org.apache.maven.surefire.group.match.SingleGroupMatcher;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35
36 import static org.junit.Assert.assertFalse;
37 import static org.junit.Assert.assertTrue;
38 import static org.junit.runner.Description.createSuiteDescription;
39 import static org.junit.runner.Description.createTestDescription;
40
41
42
43
44 public class GroupMatcherCategoryFilterTest {
45 private GroupMatcherCategoryFilter cut;
46
47 @BeforeClass
48 public static void printVersion() {
49 System.out.println(Version.id());
50 }
51
52 @Test
53 public void shouldMatchIncludedCategoryInSelf() {
54 GroupMatcher included =
55 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
56 GroupMatcher excluded = null;
57 cut = new GroupMatcherCategoryFilter(included, excluded);
58 assertTrue(cut.shouldRun(createSuiteDescription(BTest.class)));
59 }
60
61 @Test
62 public void shouldMatchIncludedCategoryInParent() {
63 GroupMatcher included =
64 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
65 GroupMatcher excluded = null;
66 cut = new GroupMatcherCategoryFilter(included, excluded);
67 assertTrue(cut.shouldRun(createSuiteDescription(BCTest.class)));
68 assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
69 }
70
71 @Test
72 public void shouldMatchIncludedCategoryInHierarchy() {
73 GroupMatcher included =
74 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryC");
75 GroupMatcher excluded = null;
76 cut = new GroupMatcherCategoryFilter(included, excluded);
77 assertTrue(cut.shouldRun(createSuiteDescription(ABCTest.class)));
78 assertTrue(cut.shouldRun(createSuiteDescription(BCTest.class)));
79 assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
80 }
81
82 @Test
83 public void shouldMatchIncludedCategoryInParentWhenSelfHasAnother() {
84 GroupMatcher included =
85 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
86 GroupMatcher excluded = null;
87 cut = new GroupMatcherCategoryFilter(included, excluded);
88 assertTrue(cut.shouldRun(createSuiteDescription(ABCTest.class)));
89 assertTrue(cut.shouldRun(createTestDescription(ABCTest.class, "abc")));
90 assertTrue(cut.shouldRun(createSuiteDescription(ABCParameterizedTest.class)));
91 assertTrue(cut.shouldRun(createTestDescription(ABCParameterizedTest.class, "abc")));
92 }
93
94 @Test
95 public void shouldNotMatchIncludedCategoryInParentWhenSelfHasExcludedCategory() {
96 GroupMatcher included =
97 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
98 GroupMatcher excluded =
99 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryA");
100 cut = new GroupMatcherCategoryFilter(included, excluded);
101 assertFalse(cut.shouldRun(createSuiteDescription(ABCTest.class)));
102 assertTrue(cut.shouldRun(createSuiteDescription(BBCTest.class)));
103 assertTrue(cut.shouldRun(createSuiteDescription(BTest.class)));
104 }
105
106 @Test
107 public void shouldMatchExcludedCategoryInSelf() {
108 GroupMatcher included = null;
109 GroupMatcher excluded =
110 new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryA");
111 cut = new GroupMatcherCategoryFilter(included, excluded);
112 assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
113 assertTrue(cut.shouldRun(createSuiteDescription(BTest.class)));
114 assertTrue(cut.shouldRun(createSuiteDescription(BBCTest.class)));
115 }
116
117
118
119
120 public static class JUnit4SuiteTest extends TestCase {
121 public static junit.framework.Test suite() {
122 TestSuite suite = new TestSuite();
123 suite.addTest(new JUnit4TestAdapter(GroupMatcherCategoryFilterTest.class));
124 return suite;
125 }
126 }
127 }