View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.group.parse;
20  
21  import junit.framework.TestCase;
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  /**
29   *
30   */
31  public class GroupMatcherParserTest extends TestCase {
32  
33      public void testParseSingleClass() throws ParseException {
34          GroupMatcher matcher = new GroupMatcherParser(GroupMatcherParser.class.getName()).parse();
35          assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher);
36          assertTrue(matcher.enabled(GroupMatcherParser.class));
37      }
38  
39      public void testParseInvertedSingleClass() throws ParseException {
40          GroupMatcher matcher = new GroupMatcherParser("NOT " + GroupMatcherParser.class.getName()).parse();
41          assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof InverseGroupMatcher);
42          assertFalse(matcher.enabled(GroupMatcherParser.class));
43      }
44  
45      public void testParseBareANDedPair() throws ParseException {
46          GroupMatcher matcher = new GroupMatcherParser(
47                          GroupMatcherParser.class.getName() + " AND " + SingleGroupMatcher.class.getName())
48                  .parse();
49  
50          assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof AndGroupMatcher);
51          assertFalse(matcher.enabled(GroupMatcherParser.class));
52          assertTrue(matcher.enabled(GroupMatcherParser.class, SingleGroupMatcher.class));
53      }
54  
55      public void testParseBareORedPair() throws ParseException {
56          GroupMatcher matcher = new GroupMatcherParser(
57                          GroupMatcherParser.class.getName() + " OR " + SingleGroupMatcher.class.getName())
58                  .parse();
59  
60          assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof OrGroupMatcher);
61          assertTrue(matcher.enabled(GroupMatcherParser.class));
62          assertTrue(matcher.enabled(GroupMatcherParser.class, SingleGroupMatcher.class));
63      }
64  
65      public void testBareCommaSeparatedORedPair() throws ParseException {
66          GroupMatcher matcher = new GroupMatcherParser(
67                          GroupMatcherParser.class.getName() + ", " + SingleGroupMatcher.class.getName())
68                  .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 testParseGroupedANDedPair() throws ParseException {
76          GroupMatcher matcher = new GroupMatcherParser(
77                          "(" + GroupMatcherParser.class.getName() + " AND " + SingleGroupMatcher.class.getName() + ")")
78                  .parse();
79  
80          assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof AndGroupMatcher);
81          assertFalse(matcher.enabled(GroupMatcherParser.class));
82          assertTrue(matcher.enabled(GroupMatcherParser.class, SingleGroupMatcher.class));
83      }
84  
85      public void testParseGroupedORedPair() throws ParseException {
86          GroupMatcher matcher = new GroupMatcherParser(
87                          "(" + GroupMatcherParser.class.getName() + " OR " + SingleGroupMatcher.class.getName() + ")")
88                  .parse();
89  
90          assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof OrGroupMatcher);
91          assertTrue(matcher.enabled(GroupMatcherParser.class));
92          assertTrue(matcher.enabled(GroupMatcherParser.class, SingleGroupMatcher.class));
93      }
94  
95      public void testParseInvertedGroupedANDedPair() throws ParseException {
96          GroupMatcher matcher = new GroupMatcherParser("NOT (" + GroupMatcherParser.class.getName() + " AND "
97                          + SingleGroupMatcher.class.getName() + ")")
98                  .parse();
99  
100         assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof InverseGroupMatcher);
101         assertTrue(matcher.enabled(GroupMatcherParser.class));
102         assertFalse(matcher.enabled(GroupMatcherParser.class, SingleGroupMatcher.class));
103     }
104 
105     public void testParseInvertedGroupedORedPair() throws ParseException {
106         GroupMatcher matcher = new GroupMatcherParser("NOT (" + GroupMatcherParser.class.getName() + " OR "
107                         + SingleGroupMatcher.class.getName() + ")")
108                 .parse();
109 
110         assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof InverseGroupMatcher);
111         assertFalse(matcher.enabled(GroupMatcherParser.class));
112         assertFalse(matcher.enabled(GroupMatcherParser.class, SingleGroupMatcher.class));
113     }
114 
115     public void testSingleMatchWhenDotClassAppended() throws ParseException {
116         GroupMatcher matcher = new GroupMatcherParser(SingleGroupMatcher.class.getName() + ".class").parse();
117         assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher);
118         assertTrue(matcher.enabled(SingleGroupMatcher.class));
119     }
120 
121     public void testSingleMatchWithOnlyClassSimpleName() throws ParseException {
122         GroupMatcher matcher = new GroupMatcherParser(SingleGroupMatcher.class.getSimpleName()).parse();
123         assertTrue("Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher);
124         assertTrue(matcher.enabled(SingleGroupMatcher.class));
125     }
126 }