View Javadoc

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