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 java.lang.reflect.Method;
23 import java.lang.reflect.Modifier;
24 import org.apache.maven.surefire.NonAbstractClassFilter;
25 import org.apache.maven.surefire.util.ReflectionUtils;
26 import org.apache.maven.surefire.util.ScannerFilter;
27
28
29
30
31
32
33
34
35
36 public class JUnit3TestChecker
37 implements ScannerFilter
38 {
39 private final Class junitClass;
40
41 private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
42
43
44 private final NonAbstractClassFilter nonAbstractClassFilter = new NonAbstractClassFilter();
45
46
47 public JUnit3TestChecker( ClassLoader testClassLoader )
48 {
49 junitClass = ReflectionUtils.tryLoadClass( testClassLoader, "junit.framework.Test" );
50 }
51
52 public boolean accept( Class testClass )
53 {
54 return nonAbstractClassFilter.accept( testClass ) && isValidJUnit3Test( testClass );
55 }
56
57 private boolean isValidJUnit3Test( Class testClass )
58 {
59 return junitClass != null && ( junitClass.isAssignableFrom( testClass ) || isSuiteOnly( testClass ) );
60 }
61
62 public boolean isSuiteOnly( Class testClass )
63 {
64 final Method suite = ReflectionUtils.tryGetMethod( testClass, "suite", EMPTY_CLASS_ARRAY );
65 if ( suite != null )
66 {
67
68 final int modifiers = suite.getModifiers();
69 if ( Modifier.isPublic( modifiers ) && Modifier.isStatic( modifiers ) )
70 {
71 return junit.framework.Test.class.isAssignableFrom( suite.getReturnType() );
72 }
73 }
74 return false;
75 }
76
77 }