1 package org.apache.maven.surefire.group.parse;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.group.match.AndGroupMatcher;
23 import org.apache.maven.surefire.group.match.GroupMatcher;
24 import org.apache.maven.surefire.group.match.InverseGroupMatcher;
25 import org.apache.maven.surefire.group.match.OrGroupMatcher;
26 import org.apache.maven.surefire.group.match.SingleGroupMatcher;
27
28 import junit.framework.TestCase;
29
30
31
32
33 public class GroupMatcherParserTest
34 extends TestCase
35 {
36
37 public void testParseSingleClass()
38 throws ParseException
39 {
40 GroupMatcher matcher = new GroupMatcherParser( GroupMatcherParser.class.getName() ).parse();
41 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher );
42 assertTrue( matcher.enabled( GroupMatcherParser.class ) );
43 }
44
45 public void testParseInvertedSingleClass()
46 throws ParseException
47 {
48 GroupMatcher matcher = new GroupMatcherParser( "NOT " + GroupMatcherParser.class.getName() ).parse();
49 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof InverseGroupMatcher );
50 assertFalse( matcher.enabled( GroupMatcherParser.class ) );
51 }
52
53 public void testParseBareANDedPair()
54 throws ParseException
55 {
56 GroupMatcher matcher = new GroupMatcherParser(
57 GroupMatcherParser.class.getName() + " AND " + SingleGroupMatcher.class.getName() ).parse();
58
59 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof AndGroupMatcher );
60 assertFalse( matcher.enabled( GroupMatcherParser.class ) );
61 assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
62 }
63
64 public void testParseBareORedPair()
65 throws ParseException
66 {
67 GroupMatcher matcher = new GroupMatcherParser(
68 GroupMatcherParser.class.getName() + " OR " + SingleGroupMatcher.class.getName() ).parse();
69
70 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof OrGroupMatcher );
71 assertTrue( matcher.enabled( GroupMatcherParser.class ) );
72 assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
73 }
74
75 public void testBareCommaSeparatedORedPair()
76 throws ParseException
77 {
78 GroupMatcher matcher = new GroupMatcherParser(
79 GroupMatcherParser.class.getName() + ", " + SingleGroupMatcher.class.getName() ).parse();
80
81 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof OrGroupMatcher );
82 assertTrue( matcher.enabled( GroupMatcherParser.class ) );
83 assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
84 }
85
86 public void testParseGroupedANDedPair()
87 throws ParseException
88 {
89 GroupMatcher matcher = new GroupMatcherParser(
90 "(" + GroupMatcherParser.class.getName() + " AND " + SingleGroupMatcher.class.getName() + ")" ).parse();
91
92 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof AndGroupMatcher );
93 assertFalse( matcher.enabled( GroupMatcherParser.class ) );
94 assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
95 }
96
97 public void testParseGroupedORedPair()
98 throws ParseException
99 {
100 GroupMatcher matcher = new GroupMatcherParser(
101 "(" + GroupMatcherParser.class.getName() + " OR " + SingleGroupMatcher.class.getName() + ")" ).parse();
102
103 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof OrGroupMatcher );
104 assertTrue( matcher.enabled( GroupMatcherParser.class ) );
105 assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
106 }
107
108 public void testParseInvertedGroupedANDedPair()
109 throws ParseException
110 {
111 GroupMatcher matcher = new GroupMatcherParser(
112 "NOT (" + GroupMatcherParser.class.getName() + " AND " + SingleGroupMatcher.class.getName() + ")" ).parse();
113
114 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof InverseGroupMatcher );
115 assertTrue( matcher.enabled( GroupMatcherParser.class ) );
116 assertFalse( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
117 }
118
119 public void testParseInvertedGroupedORedPair()
120 throws ParseException
121 {
122 GroupMatcher matcher = new GroupMatcherParser(
123 "NOT (" + GroupMatcherParser.class.getName() + " OR " + SingleGroupMatcher.class.getName() + ")" ).parse();
124
125 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof InverseGroupMatcher );
126 assertFalse( matcher.enabled( GroupMatcherParser.class ) );
127 assertFalse( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
128 }
129
130 public void testSingleMatchWhenDotClassAppended()
131 throws ParseException
132 {
133 GroupMatcher matcher = new GroupMatcherParser( SingleGroupMatcher.class.getName() + ".class" ).parse();
134 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher );
135 assertTrue( matcher.enabled( SingleGroupMatcher.class ) );
136 }
137
138 public void testSingleMatchWithOnlyClassSimpleName()
139 throws ParseException
140 {
141 GroupMatcher matcher = new GroupMatcherParser( SingleGroupMatcher.class.getSimpleName() ).parse();
142 assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher );
143 assertTrue( matcher.enabled( SingleGroupMatcher.class ) );
144 }
145
146 }