1 package org.apache.maven.surefire.common.junit3;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.testset.TestSetFailedException;
23
24 import junit.framework.TestCase;
25 import junit.framework.TestResult;
26
27
28
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 @Override
110 public int countTestCases()
111 {
112 return 0;
113 }
114
115 @Override
116 public void run( TestResult testResult )
117 {
118 }
119 }
120
121
122 public static class NotValidTest
123 {
124 public void testSomething()
125 {
126 }
127 }
128
129 public abstract static class BaseClassWithTest
130 extends TestCase
131 {
132 public void testWeAreAlsoATest()
133 {
134 }
135 }
136
137 public static class SubClassWithoutOwnTestMethods
138 extends BaseClassWithTest
139 {
140 }
141
142 class NestedTC
143 extends TestCase
144 {
145 public class Inner
146 {
147
148 }
149 }
150
151 }