1 package org.apache.maven.surefire.common.junit48;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import org.apache.maven.surefire.NonAbstractClassFilter;
24 import org.apache.maven.surefire.common.junit4.JUnit4TestChecker;
25 import org.apache.maven.surefire.util.ScannerFilter;
26 import org.junit.experimental.runners.Enclosed;
27
28
29
30
31
32
33
34 public class JUnit48TestChecker
35 implements ScannerFilter
36 {
37 private final NonAbstractClassFilter nonAbstractClassFilter;
38
39 private final JUnit4TestChecker jUnit4TestChecker;
40
41
42 public JUnit48TestChecker( ClassLoader testClassLoader )
43 {
44 this.jUnit4TestChecker = new JUnit4TestChecker( testClassLoader );
45 this.nonAbstractClassFilter = new NonAbstractClassFilter();
46 }
47
48 public boolean accept( Class testClass )
49 {
50 return jUnit4TestChecker.accept( testClass ) || isAbstractWithEnclosedRunner( testClass );
51 }
52
53 @SuppressWarnings( { "unchecked" } )
54 private boolean isAbstractWithEnclosedRunner( Class testClass )
55 {
56 return jUnit4TestChecker.isRunWithPresentInClassLoader() && isAbstract( testClass ) && isRunWithEnclosedRunner(testClass);
57 }
58
59 private boolean isRunWithEnclosedRunner(Class testClass )
60 {
61 @SuppressWarnings( "unchecked" ) org.junit.runner.RunWith runWithAnnotation =
62 (org.junit.runner.RunWith) testClass.getAnnotation( org.junit.runner.RunWith.class );
63 return ( runWithAnnotation != null && Enclosed.class.equals( runWithAnnotation.value()));
64 }
65
66 private boolean isAbstract( Class testClass )
67 {
68 return !nonAbstractClassFilter.accept( testClass );
69 }
70 }