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.junit3;
20  
21  import junit.framework.TestCase;
22  import junit.framework.TestResult;
23  
24  /**
25   * @author Kristian Rosenvold
26   */
27  public class JUnit3TestCheckerTest extends TestCase {
28      private final JUnit3TestChecker jUnit3TestChecker =
29              new JUnit3TestChecker(this.getClass().getClassLoader());
30  
31      public void testValidJunit4Annotated() {
32          assertTrue(jUnit3TestChecker.accept(JUnit3TestCheckerTest.class));
33      }
34  
35      public void testValidJunit4itsAJunit3Test() {
36          assertTrue(jUnit3TestChecker.accept(AlsoValid.class));
37      }
38  
39      public void testValidJunitSubclassWithoutOwnTestmethods() {
40          assertTrue(jUnit3TestChecker.accept(SubClassWithoutOwnTestMethods.class));
41      }
42  
43      public void testInvalidTest() {
44          assertFalse(jUnit3TestChecker.accept(NotValidTest.class));
45      }
46  
47      public void testDontAcceptAbstractClasses() {
48          assertFalse(jUnit3TestChecker.accept(BaseClassWithTest.class));
49      }
50  
51      public void testSuiteOnlyTest() {
52          assertTrue(jUnit3TestChecker.accept(SuiteOnlyTest.class));
53      }
54  
55      public void testCustomSuiteOnlyTest() {
56          assertTrue(jUnit3TestChecker.accept(CustomSuiteOnlyTest.class));
57      }
58  
59      public void testIinnerClassNotAutomaticallyTc() {
60          assertTrue(jUnit3TestChecker.accept(NestedTC.class));
61          assertFalse(jUnit3TestChecker.accept(NestedTC.Inner.class));
62      }
63  
64      /**
65       *
66       */
67      public static class AlsoValid extends TestCase {
68          public void testSomething() {}
69      }
70  
71      /**
72       *
73       */
74      public static class SuiteOnlyTest {
75          public static junit.framework.Test suite() {
76              return null;
77          }
78      }
79  
80      /**
81       *
82       */
83      public static class CustomSuiteOnlyTest {
84          public static MySuite2 suite() {
85              return null;
86          }
87      }
88  
89      /**
90       *
91       */
92      public static class MySuite2 implements junit.framework.Test {
93          @Override
94          public int countTestCases() {
95              return 0;
96          }
97  
98          @Override
99          public void run(TestResult testResult) {}
100     }
101 
102     /**
103      *
104      */
105     public static class NotValidTest {
106         public void testSomething() {}
107     }
108 
109     /**
110      *
111      */
112     public abstract static class BaseClassWithTest extends TestCase {
113         public void testWeAreAlsoATest() {}
114     }
115 
116     /**
117      *
118      */
119     public static class SubClassWithoutOwnTestMethods extends BaseClassWithTest {}
120 
121     class NestedTC extends TestCase {
122         public class Inner {}
123     }
124 }