View Javadoc
1   package org.apache.maven.surefire.testset;
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.junit.Test;
22  
23  import static org.hamcrest.MatcherAssert.assertThat;
24  import static org.hamcrest.Matchers.*;
25  
26  @SuppressWarnings( { "javadoc", "checkstyle:javadoctype" } )
27  /**
28   * Inclusive test patters:<p>
29   *
30   * <table cellspacing=0 border=1>
31   * <tr>
32   * <td style=min-width:50px> test</td>
33   * <td style=min-width:50px></td>
34   * <td style=min-width:50px> pattern</td>
35   * <td style=min-width:50px></td>
36   * <td style=min-width:50px></td>
37   * <td style=min-width:50px></td>
38   * </tr>
39   * <tr>
40   * <td style=min-width:50px>class</td>
41   * <td style=min-width:50px>method</td>
42   * <td style=min-width:50px>class</td>
43   * <td style=min-width:50px>method</td>
44   * <td style=min-width:50px>shouldRunAsInclusive</td>
45   * <td style=min-width:50px></td>
46   * </tr>
47   * <tr>
48   * <td style=min-width:50px>n</td>
49   * <td style=min-width:50px>n</td>
50   * <td style=min-width:50px>n</td>
51   * <td style=min-width:50px>n</td>
52   * <td style=min-width:50px>y (wildcard pattern)</td>
53   * <td style=min-width:50px>testIncludes1</td>
54   * </tr>
55   * <tr>
56   * <td style=min-width:50px>n</td>
57   * <td style=min-width:50px>n</td>
58   * <td style=min-width:50px>n</td>
59   * <td style=min-width:50px>y</td>
60   * <td style=min-width:50px>y (suppose suite and custome filter)</td>
61   * <td style=min-width:50px>testIncludes2</td>
62   * </tr>
63   * <tr>
64   * <td style=min-width:50px>n</td>
65   * <td style=min-width:50px>n</td>
66   * <td style=min-width:50px>y</td>
67   * <td style=min-width:50px>n</td>
68   * <td style=min-width:50px>y (suppose Suite)</td>
69   * <td style=min-width:50px>testIncludes3</td>
70   * </tr>
71   * <tr>
72   * <td style=min-width:50px>n</td>
73   * <td style=min-width:50px>n</td>
74   * <td style=min-width:50px>y</td>
75   * <td style=min-width:50px>y</td>
76   * <td style=min-width:50px>y (suppose Suite)</td>
77   * <td style=min-width:50px>testIncludes4</td>
78   * </tr>
79   * <tr>
80   * <td style=min-width:50px>n</td>
81   * <td style=min-width:50px>y</td>
82   * <td style=min-width:50px>n</td>
83   * <td style=min-width:50px>n</td>
84   * <td style=min-width:50px>y (wildcard pattern)</td>
85   * <td style=min-width:50px>testIncludes5</td>
86   * </tr>
87   * <tr>
88   * <td style=min-width:50px>n</td>
89   * <td style=min-width:50px>y</td>
90   * <td style=min-width:50px>n</td>
91   * <td style=min-width:50px>y</td>
92   * <td style=min-width:50px>match methods</td>
93   * <td style=min-width:50px>testIncludes6</td>
94   * </tr>
95   * <tr>
96   * <td style=min-width:50px>n</td>
97   * <td style=min-width:50px>y</td>
98   * <td style=min-width:50px>y</td>
99   * <td style=min-width:50px>n</td>
100  * <td style=min-width:50px>y (due to Cucumber)</td>
101  * <td style=min-width:50px>testIncludes7</td>
102  * </tr>
103  * <tr>
104  * <td style=min-width:50px>n</td>
105  * <td style=min-width:50px>y</td>
106  * <td style=min-width:50px>y</td>
107  * <td style=min-width:50px>y</td>
108  * <td style=min-width:50px>y (due to Cucumber)</td>
109  * <td style=min-width:50px>testIncludes8</td>
110  * </tr>
111  * <tr>
112  * <td style=min-width:50px>y</td>
113  * <td style=min-width:50px>n</td>
114  * <td style=min-width:50px>n</td>
115  * <td style=min-width:50px>n</td>
116  * <td style=min-width:50px>y (wildcard pattern)</td>
117  * <td style=min-width:50px>testIncludes9</td>
118  * </tr>
119  * <tr>
120  * <td style=min-width:50px>y</td>
121  * <td style=min-width:50px>n</td>
122  * <td style=min-width:50px>n</td>
123  * <td style=min-width:50px>y</td>
124  * <td style=min-width:50px>y (suppose suite and custome filter)</td>
125  * <td style=min-width:50px>testIncludes10</td>
126  * </tr>
127  * <tr>
128  * <td style=min-width:50px>y</td>
129  * <td style=min-width:50px>n</td>
130  * <td style=min-width:50px>y</td>
131  * <td style=min-width:50px>n</td>
132  * <td style=min-width:50px>match classes</td>
133  * <td style=min-width:50px>testIncludes11</td>
134  * </tr>
135  * <tr>
136  * <td style=min-width:50px>y</td>
137  * <td style=min-width:50px>n</td>
138  * <td style=min-width:50px>y</td>
139  * <td style=min-width:50px>y</td>
140  * <td style=min-width:50px>match classes</td>
141  * <td style=min-width:50px>testIncludes12</td>
142  * </tr>
143  * <tr>
144  * <td style=min-width:50px>y</td>
145  * <td style=min-width:50px>y</td>
146  * <td style=min-width:50px>n</td>
147  * <td style=min-width:50px>n</td>
148  * <td style=min-width:50px>y (wildcard pattern)</td>
149  * <td style=min-width:50px>testIncludes13</td>
150  * </tr>
151  * <tr>
152  * <td style=min-width:50px>y</td>
153  * <td style=min-width:50px>y</td>
154  * <td style=min-width:50px>n</td>
155  * <td style=min-width:50px>y</td>
156  * <td style=min-width:50px>match methods</td>
157  * <td style=min-width:50px>testIncludes14</td>
158  * </tr>
159  * <tr>
160  * <td style=min-width:50px>y</td>
161  * <td style=min-width:50px>y</td>
162  * <td style=min-width:50px>y</td>
163  * <td style=min-width:50px>n</td>
164  * <td style=min-width:50px>match classes</td>
165  * <td style=min-width:50px>testIncludes15</td>
166  * </tr>
167  * <tr>
168  * <td style=min-width:50px>y</td>
169  * <td style=min-width:50px>y</td>
170  * <td style=min-width:50px>y</td>
171  * <td style=min-width:50px>y</td>
172  * <td style=min-width:50px>match all</td>
173  * <td style=min-width:50px>testIncludes16</td>
174  * </tr>
175  * </table>
176  * <p>
177  * <p>
178  * Exclusive test patters:<p>
179  *
180  * <table cellspacing=0 border=1>
181  * <tr>
182  * <td style=min-width:50px> test</td>
183  * <td style=min-width:50px></td>
184  * <td style=min-width:50px> pattern</td>
185  * <td style=min-width:50px></td>
186  * <td style=min-width:50px></td>
187  * <td style=min-width:50px></td>
188  * </tr>
189  * <tr>
190  * <td style=min-width:50px>class</td>
191  * <td style=min-width:50px>method</td>
192  * <td style=min-width:50px>class</td>
193  * <td style=min-width:50px>method</td>
194  * <td style=min-width:50px>shouldRunAsExclusive</td>
195  * <td style=min-width:50px></td>
196  * </tr>
197  * <tr>
198  * <td style=min-width:50px>n</td>
199  * <td style=min-width:50px>n</td>
200  * <td style=min-width:50px>n</td>
201  * <td style=min-width:50px>n</td>
202  * <td style=min-width:50px>n (wildcard pattern)</td>
203  * <td style=min-width:50px>testExcludes1</td>
204  * </tr>
205  * <tr>
206  * <td style=min-width:50px>n</td>
207  * <td style=min-width:50px>n</td>
208  * <td style=min-width:50px>n</td>
209  * <td style=min-width:50px>y</td>
210  * <td style=min-width:50px>n (suppose suite and custome filter)</td>
211  * <td style=min-width:50px>testExcludes2</td>
212  * </tr>
213  * <tr>
214  * <td style=min-width:50px>n</td>
215  * <td style=min-width:50px>n</td>
216  * <td style=min-width:50px>y</td>
217  * <td style=min-width:50px>n</td>
218  * <td style=min-width:50px>n (suppose Suite)</td>
219  * <td style=min-width:50px>testExcludes3</td>
220  * </tr>
221  * <tr>
222  * <td style=min-width:50px>n</td>
223  * <td style=min-width:50px>n</td>
224  * <td style=min-width:50px>y</td>
225  * <td style=min-width:50px>y</td>
226  * <td style=min-width:50px>n (suppose Suite)</td>
227  * <td style=min-width:50px>testExcludes4</td>
228  * </tr>
229  * <tr>
230  * <td style=min-width:50px>n</td>
231  * <td style=min-width:50px>y</td>
232  * <td style=min-width:50px>n</td>
233  * <td style=min-width:50px>n</td>
234  * <td style=min-width:50px>n (wildcard pattern)</td>
235  * <td style=min-width:50px>testExcludes5</td>
236  * </tr>
237  * <tr>
238  * <td style=min-width:50px>n</td>
239  * <td style=min-width:50px>y</td>
240  * <td style=min-width:50px>n</td>
241  * <td style=min-width:50px>y</td>
242  * <td style=min-width:50px>match methods</td>
243  * <td style=min-width:50px>testExcludes6</td>
244  * </tr>
245  * <tr>
246  * <td style=min-width:50px>n</td>
247  * <td style=min-width:50px>y</td>
248  * <td style=min-width:50px>y</td>
249  * <td style=min-width:50px>n</td>
250  * <td style=min-width:50px>n (due to Cucumber)</td>
251  * <td style=min-width:50px>testExcludes7</td>
252  * </tr>
253  * <tr>
254  * <td style=min-width:50px>n</td>
255  * <td style=min-width:50px>y</td>
256  * <td style=min-width:50px>y</td>
257  * <td style=min-width:50px>y</td>
258  * <td style=min-width:50px>n (due to Cucumber)</td>
259  * <td style=min-width:50px>testExcludes8</td>
260  * </tr>
261  * <tr>
262  * <td style=min-width:50px>y</td>
263  * <td style=min-width:50px>n</td>
264  * <td style=min-width:50px>n</td>
265  * <td style=min-width:50px>n</td>
266  * <td style=min-width:50px>n (wildcard pattern)</td>
267  * <td style=min-width:50px>testExcludes9</td>
268  * </tr>
269  * <tr>
270  * <td style=min-width:50px>y</td>
271  * <td style=min-width:50px>n</td>
272  * <td style=min-width:50px>n</td>
273  * <td style=min-width:50px>y</td>
274  * <td style=min-width:50px>n (suppose suite and custome filter)</td>
275  * <td style=min-width:50px>testExcludes10</td>
276  * </tr>
277  * <tr>
278  * <td style=min-width:50px>y</td>
279  * <td style=min-width:50px>n</td>
280  * <td style=min-width:50px>y</td>
281  * <td style=min-width:50px>n</td>
282  * <td style=min-width:50px>match classes</td>
283  * <td style=min-width:50px>testExcludes11</td>
284  * </tr>
285  * <tr>
286  * <td style=min-width:50px>y</td>
287  * <td style=min-width:50px>n</td>
288  * <td style=min-width:50px>y</td>
289  * <td style=min-width:50px>y</td>
290  * <td style=min-width:50px>n (cannot exclude in dir.scanner)</td>
291  * <td style=min-width:50px>testExcludes12</td>
292  * </tr>
293  * <tr>
294  * <td style=min-width:50px>y</td>
295  * <td style=min-width:50px>y</td>
296  * <td style=min-width:50px>n</td>
297  * <td style=min-width:50px>n</td>
298  * <td style=min-width:50px>n (wildcard pattern)</td>
299  * <td style=min-width:50px>testExcludes13</td>
300  * </tr>
301  * <tr>
302  * <td style=min-width:50px>y</td>
303  * <td style=min-width:50px>y</td>
304  * <td style=min-width:50px>n</td>
305  * <td style=min-width:50px>y</td>
306  * <td style=min-width:50px>match methods</td>
307  * <td style=min-width:50px>testExcludes14</td>
308  * </tr>
309  * <tr>
310  * <td style=min-width:50px>y</td>
311  * <td style=min-width:50px>y</td>
312  * <td style=min-width:50px>y</td>
313  * <td style=min-width:50px>n</td>
314  * <td style=min-width:50px>match classes</td>
315  * <td style=min-width:50px>testExcludes15</td>
316  * </tr>
317  * <tr>
318  * <td style=min-width:50px>y</td>
319  * <td style=min-width:50px>y</td>
320  * <td style=min-width:50px>y</td>
321  * <td style=min-width:50px>y</td>
322  * <td style=min-width:50px>match all</td>
323  * <td style=min-width:50px>testExcludes16</td>
324  * </tr>
325  * </table>
326  */
327 public class FundamentalFilterTest
328 {
329     @Test
330     public void testIncludes1()
331     {
332         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
333         assertThat( pattern.matchAsInclusive( null, null ), is( true ) );
334     }
335 
336     @Test
337     public void testIncludes2()
338     {
339         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
340         assertThat( pattern.matchAsInclusive( null, null ), is( true ) );
341     }
342 
343     @Test
344     public void testIncludes3()
345     {
346         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
347         assertThat( pattern.matchAsInclusive( null, null ), is( true ) );
348     }
349 
350     @Test
351     public void testIncludes4()
352     {
353         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
354         assertThat( pattern.matchAsInclusive( null, null ), is( true ) );
355     }
356 
357     @Test
358     public void testIncludes5()
359     {
360         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
361         assertThat( pattern.matchAsInclusive( null, "method" ), is( true ) );
362     }
363 
364     @Test
365     public void testIncludes6()
366     {
367         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
368         assertThat( pattern.matchAsInclusive( null, "method" ), is( true ) );
369         assertThat( pattern.matchAsInclusive( null, "otherMethod" ), is( false ) );
370     }
371 
372     /**
373      * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL.
374      */
375     @Test
376     public void testIncludes7()
377     {
378         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
379         assertThat( pattern.matchAsInclusive( null, "method" ), is( true ) );
380     }
381 
382     /**
383      * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL.
384      */
385     @Test
386     public void testIncludes8()
387     {
388         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
389         assertThat( pattern.matchAsInclusive( null, "method" ), is( true ) );
390         assertThat( pattern.matchAsInclusive( null, "otherMethod" ), is( true ) );
391     }
392 
393     @Test
394     public void testIncludes9()
395     {
396         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
397         assertThat( pattern.matchAsInclusive( "Test.class", null ), is( true ) );
398     }
399 
400     @Test
401     public void testIncludes10()
402     {
403         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
404         assertThat( pattern.matchAsInclusive( "Test.class", null ), is( true ) );
405     }
406 
407     @Test
408     public void testIncludes11()
409     {
410         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
411         assertThat( pattern.matchAsInclusive( "Test.class", null ), is( true ) );
412         assertThat( pattern.matchAsInclusive( "Other.class", null ), is( false ) );
413     }
414 
415     @Test
416     public void testIncludes12()
417     {
418         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
419         assertThat( pattern.matchAsInclusive( "Test.class", null ), is( true ) );
420         assertThat( pattern.matchAsInclusive( "Other.class", null ), is( false ) );
421     }
422 
423     @Test
424     public void testIncludes13()
425     {
426         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
427         assertThat( pattern.matchAsInclusive( "Test.class", "method" ), is( true ) );
428     }
429 
430     @Test
431     public void testIncludes14()
432     {
433         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
434         assertThat( pattern.matchAsInclusive( "Test.class", "method" ), is( true ) );
435         assertThat( pattern.matchAsInclusive( "Test.class", "otherMethod" ), is( false ) );
436     }
437 
438     @Test
439     public void testIncludes15()
440     {
441         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
442         assertThat( pattern.matchAsInclusive( "Test.class", "method" ), is( true ) );
443         assertThat( pattern.matchAsInclusive( "Other.class", "method" ), is( false ) );
444     }
445 
446     @Test
447     public void testIncludes16()
448     {
449         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
450         assertThat( pattern.matchAsInclusive( "Test.class", "method" ), is( true ) );
451         assertThat( pattern.matchAsInclusive( "Test.class", "otherMethod" ), is( false ) );
452         assertThat( pattern.matchAsInclusive( "Other.class", "method" ), is( false ) );
453         assertThat( pattern.matchAsInclusive( "Other.class", "otherMethod" ), is( false ) );
454     }
455 
456     @Test
457     public void testExcludes1()
458     {
459         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
460         assertThat( pattern.matchAsExclusive( null, null ), is( false ) );
461     }
462 
463     @Test
464     public void testExcludes2()
465     {
466         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
467         assertThat( pattern.matchAsExclusive( null, null ), is( false ) );
468     }
469 
470     @Test
471     public void testExcludes3()
472     {
473         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
474         assertThat( pattern.matchAsExclusive( null, null ), is( false ) );
475     }
476 
477     @Test
478     public void testExcludes4()
479     {
480         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
481         assertThat( pattern.matchAsExclusive( null, null ), is( false ) );
482     }
483 
484     @Test
485     public void testExcludes5()
486     {
487         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
488         assertThat( pattern.matchAsExclusive( null, "method" ), is( false ) );
489     }
490 
491     @Test
492     public void testExcludes6()
493     {
494         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
495         assertThat( pattern.matchAsExclusive( null, "method" ), is( true ) );
496         assertThat( pattern.matchAsExclusive( null, "otherMethod" ), is( false ) );
497     }
498 
499     /**
500      * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL.
501      */
502     @Test
503     public void testExcludes7()
504     {
505         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
506         assertThat( pattern.matchAsExclusive( null, "method" ), is( false ) );
507     }
508 
509     /**
510      * Does not throw NPE due to Cucumber has test class NULL and test method NOT NULL.
511      */
512     @Test
513     public void testExcludes8()
514     {
515         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
516         assertThat( pattern.matchAsExclusive( null, "method" ), is( false ) );
517         assertThat( pattern.matchAsExclusive( null, "otherMethod" ), is( false ) );
518     }
519 
520     @Test
521     public void testExcludes9()
522     {
523         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
524         assertThat( pattern.matchAsExclusive( "Test.class", null ), is( false ) );
525     }
526 
527     @Test
528     public void testExcludes10()
529     {
530         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
531         assertThat( pattern.matchAsExclusive( "Test.class", null ), is( false ) );
532     }
533 
534     @Test
535     public void testExcludes11()
536     {
537         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
538         assertThat( pattern.matchAsExclusive( "Test.class", null ), is( true ) );
539         assertThat( pattern.matchAsExclusive( "Other.class", null ), is( false ) );
540     }
541 
542     @Test
543     public void testExcludes12()
544     {
545         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
546         assertThat( pattern.matchAsExclusive( "Test.class", null ), is( false ) );
547         assertThat( pattern.matchAsExclusive( "Other.class", null ), is( false ) );
548     }
549 
550     @Test
551     public void testExcludes13()
552     {
553         ResolvedTest pattern = new ResolvedTest( (String) null, null, false );
554         assertThat( pattern.matchAsExclusive( "Test.class", "method" ), is( false ) );
555     }
556 
557     @Test
558     public void testExcludes14()
559     {
560         ResolvedTest pattern = new ResolvedTest( (String) null, "method", false );
561         assertThat( pattern.matchAsExclusive( "Test.class", "method" ), is( true ) );
562         assertThat( pattern.matchAsExclusive( "Test.class", "otherMethod" ), is( false ) );
563     }
564 
565     @Test
566     public void testExcludes15()
567     {
568         ResolvedTest pattern = new ResolvedTest( "Test", null, false );
569         assertThat( pattern.matchAsExclusive( "Test.class", "method" ), is( true ) );
570         assertThat( pattern.matchAsExclusive( "Other.class", "method" ), is( false ) );
571     }
572 
573     @Test
574     public void testExcludes16()
575     {
576         ResolvedTest pattern = new ResolvedTest( "Test", "method", false );
577         assertThat( pattern.matchAsExclusive( "Test.class", "method" ), is( true ) );
578         assertThat( pattern.matchAsExclusive( "Test.class", "otherMethod" ), is( false ) );
579         assertThat( pattern.matchAsExclusive( "Other.class", "method" ), is( false ) );
580         assertThat( pattern.matchAsExclusive( "Other.class", "otherMethod" ), is( false ) );
581     }
582 }