1 package org.apache.maven.surefire.testng.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.surefire.testset.TestListResolver;
25 import org.testng.IMethodSelector;
26 import org.testng.IMethodSelectorContext;
27 import org.testng.ITestNGMethod;
28
29
30
31
32
33
34
35 public class MethodSelector
36 implements IMethodSelector
37 {
38 private static volatile TestListResolver testListResolver = null;
39
40 @Override
41 public void setTestMethods( List arg0 )
42 {
43 }
44
45 @Override
46 public boolean includeMethod( IMethodSelectorContext context, ITestNGMethod testngMethod, boolean isTestMethod )
47 {
48 return testngMethod.isBeforeClassConfiguration() || testngMethod.isBeforeGroupsConfiguration()
49 || testngMethod.isBeforeMethodConfiguration() || testngMethod.isBeforeSuiteConfiguration()
50 || testngMethod.isBeforeTestConfiguration() || testngMethod.isAfterClassConfiguration()
51 || testngMethod.isAfterGroupsConfiguration() || testngMethod.isAfterMethodConfiguration()
52 || testngMethod.isAfterSuiteConfiguration() || testngMethod.isAfterTestConfiguration()
53 || shouldRun( testngMethod );
54 }
55
56 public static void setTestListResolver( TestListResolver testListResolver )
57 {
58 MethodSelector.testListResolver = testListResolver;
59 }
60
61 private static boolean shouldRun( ITestNGMethod test )
62 {
63 TestListResolver resolver = testListResolver;
64 boolean hasTestResolver = resolver != null && !resolver.isEmpty();
65 if ( hasTestResolver )
66 {
67 boolean run = false;
68 for ( Class<?> clazz = test.getRealClass(); !run && clazz != Object.class; clazz = clazz.getSuperclass() )
69 {
70 run = resolver.shouldRun( clazz, test.getMethodName() );
71 }
72 return run;
73 }
74 return false;
75 }
76 }