View Javadoc
1   package org.apache.maven.surefire.common.junit3;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.surefire.testset.TestSetFailedException;
23  
24  import junit.framework.TestCase;
25  import junit.framework.TestResult;
26  
27  /**
28   * @author Kristian Rosenvold
29   */
30  public class JUnit3TestCheckerTest
31      extends TestCase
32  {
33      private final JUnit3TestChecker jUnit3TestChecker = new JUnit3TestChecker( this.getClass().getClassLoader() );
34  
35      public void testValidJunit4Annotated()
36          throws TestSetFailedException
37      {
38          assertTrue( jUnit3TestChecker.accept( JUnit3TestCheckerTest.class ) );
39      }
40  
41      public void testValidJunit4itsAJunit3Test()
42          throws TestSetFailedException
43      {
44          assertTrue( jUnit3TestChecker.accept( AlsoValid.class ) );
45      }
46  
47      public void testValidJunitSubclassWithoutOwnTestmethods()
48          throws TestSetFailedException
49      {
50          assertTrue( jUnit3TestChecker.accept( SubClassWithoutOwnTestMethods.class ) );
51      }
52  
53      public void testInvalidTest()
54          throws TestSetFailedException
55      {
56          assertFalse( jUnit3TestChecker.accept( NotValidTest.class ) );
57      }
58  
59      public void testDontAcceptAbstractClasses()
60      {
61          assertFalse( jUnit3TestChecker.accept( BaseClassWithTest.class ) );
62      }
63  
64      public void testSuiteOnlyTest()
65      {
66          assertTrue( jUnit3TestChecker.accept( SuiteOnlyTest.class ) );
67      }
68  
69      public void testCustomSuiteOnlyTest()
70      {
71          assertTrue( jUnit3TestChecker.accept( CustomSuiteOnlyTest.class ) );
72      }
73  
74      public void testIinnerClassNotAutomaticallyTc()
75      {
76          assertTrue( jUnit3TestChecker.accept( NestedTC.class ) );
77          assertFalse( jUnit3TestChecker.accept( NestedTC.Inner.class ) );
78      }
79  
80  
81      public static class AlsoValid
82          extends TestCase
83      {
84          public void testSomething()
85          {
86  
87          }
88      }
89  
90      public static class SuiteOnlyTest
91      {
92          public static junit.framework.Test suite()
93          {
94              return null;
95          }
96      }
97  
98      public static class CustomSuiteOnlyTest
99      {
100         public static MySuite2 suite()
101         {
102             return null;
103         }
104     }
105 
106     public static class MySuite2
107         implements junit.framework.Test
108     {
109         public int countTestCases()
110         {
111             return 0;
112         }
113 
114         public void run( TestResult testResult )
115         {
116         }
117     }
118 
119 
120     public static class NotValidTest
121     {
122         /**
123          * @noinspection UnusedDeclaration
124          */
125         public void testSomething()
126         {
127         }
128     }
129 
130     public abstract static class BaseClassWithTest
131         extends TestCase
132     {
133         /**
134          * @noinspection UnusedDeclaration
135          */
136         public void testWeAreAlsoATest()
137         {
138         }
139     }
140 
141     public static class SubClassWithoutOwnTestMethods
142         extends BaseClassWithTest
143     {
144     }
145 
146     class NestedTC
147         extends TestCase
148     {
149         public class Inner
150         {
151 
152         }
153     }
154 
155 }