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.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.BCTest;
29  import org.apache.maven.surefire.group.match.GroupMatcher;
30  import org.apache.maven.surefire.group.match.SingleGroupMatcher;
31  import org.junit.BeforeClass;
32  import org.junit.Test;
33  
34  import static org.junit.Assert.assertFalse;
35  import static org.junit.runner.Description.createSuiteDescription;
36  import static org.junit.runner.Description.createTestDescription;
37  
38  /**
39   * Before JUnit 4.12, @Category annotation was not @Inherited. These tests make sure the implied contract is honored.
40   */
41  public class GroupMatcherCategoryFilterPreJUnit412Test {
42      private GroupMatcherCategoryFilter cut;
43  
44      @BeforeClass
45      public static void printVersion() {
46          System.out.println(Version.id());
47      }
48  
49      @Test
50      public void shouldNotMatchIncludedCategoryInParent() {
51          GroupMatcher included =
52                  new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
53          GroupMatcher excluded = null;
54          cut = new GroupMatcherCategoryFilter(included, excluded);
55          assertFalse(cut.shouldRun(createSuiteDescription(BCTest.class)));
56          assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
57      }
58  
59      @Test
60      public void shouldNotMatchIncludedCategoryInHierarchy() {
61          GroupMatcher included =
62                  new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryC");
63          GroupMatcher excluded = null;
64          cut = new GroupMatcherCategoryFilter(included, excluded);
65          assertFalse(cut.shouldRun(createSuiteDescription(ABCTest.class)));
66          assertFalse(cut.shouldRun(createSuiteDescription(BCTest.class)));
67          assertFalse(cut.shouldRun(createSuiteDescription(ATest.class)));
68      }
69  
70      @Test
71      public void shouldNotMatchIncludedCategoryInParentWhenSelfHasAnother() {
72          GroupMatcher included =
73                  new SingleGroupMatcher("org.apache.maven.surefire.common.junit48.tests.group.marker.CategoryB");
74          GroupMatcher excluded = null;
75          cut = new GroupMatcherCategoryFilter(included, excluded);
76          assertFalse(cut.shouldRun(createSuiteDescription(ABCTest.class)));
77          assertFalse(cut.shouldRun(createTestDescription(ABCTest.class, "abc")));
78          assertFalse(cut.shouldRun(createSuiteDescription(ABCParameterizedTest.class)));
79          assertFalse(cut.shouldRun(createTestDescription(ABCParameterizedTest.class, "abc")));
80      }
81  
82      /**
83       *
84       */
85      public static class JUnit4SuiteTest extends TestCase {
86          public static junit.framework.Test suite() {
87              TestSuite suite = new TestSuite();
88              suite.addTest(new JUnit4TestAdapter(GroupMatcherCategoryFilterPreJUnit412Test.class));
89              return suite;
90          }
91      }
92  }