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 import org.apache.maven.shared.utils.io.SelectorUtils;
23 import org.junit.runner.Description;
24 import org.junit.runner.manipulation.Filter;
25
26 import java.util.Map;
27 import java.util.Set;
28
29
30
31
32 final class FailingMethodFilter
33 extends Filter
34 {
35
36 private final Map<Class<?>, Set<String>> failingClassMethodPatterns;
37
38 public FailingMethodFilter( Map<Class<?>, Set<String>> failingClassMethodPatterns )
39 {
40 this.failingClassMethodPatterns = failingClassMethodPatterns;
41 }
42
43 @Override
44 public boolean shouldRun( Description description )
45 {
46 return isDescriptionMatch( description );
47 }
48
49 private boolean isDescriptionMatch( Description description )
50 {
51 if ( description.getTestClass() == null || description.getMethodName() == null )
52 {
53 for ( Description childrenDescription : description.getChildren() )
54 {
55 if ( isDescriptionMatch( childrenDescription ) )
56 {
57 return true;
58 }
59 }
60 return false;
61 }
62
63 Set<String> testMethodPatterns = failingClassMethodPatterns.get( description.getTestClass() );
64 String testMethod = description.getMethodName();
65 return testMethodPatterns != null && matchMethod( testMethodPatterns, testMethod );
66 }
67
68 private static boolean matchMethod( Set<String> patterns, String methodName )
69 {
70 for ( String pattern : patterns )
71 {
72 if ( SelectorUtils.match( pattern, methodName ) )
73 {
74 return true;
75 }
76 }
77 return false;
78 }
79
80 @Override
81 public String describe()
82 {
83 return "By failing class method";
84 }
85 }