1 package org.apache.maven.surefire.common.junit4;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 import org.junit.runner.Description;
27 import org.junit.runner.manipulation.Filter;
28 import org.junit.runner.notification.Failure;
29
30 import static org.apache.maven.surefire.util.internal.StringUtils.isBlank;
31 import static org.junit.runner.Description.TEST_MECHANISM;
32
33
34
35
36
37
38
39
40 public final class JUnit4ProviderUtil
41 {
42 private JUnit4ProviderUtil()
43 {
44 throw new IllegalStateException( "Cannot instantiate." );
45 }
46
47
48
49
50
51
52
53 public static Set<Description> generateFailingTestDescriptions( List<Failure> allFailures )
54 {
55 Set<Description> failingTestDescriptions = new HashSet<Description>();
56
57 for ( Failure failure : allFailures )
58 {
59 Description description = failure.getDescription();
60 if ( description.isTest() && !isFailureInsideJUnitItself( description ) )
61 {
62 failingTestDescriptions.add( description );
63 }
64 }
65 return failingTestDescriptions;
66 }
67
68 public static boolean isFailureInsideJUnitItself( Description failure )
69 {
70 return TEST_MECHANISM.equals( failure );
71 }
72
73
74
75
76
77
78 public static ClassMethod cutTestClassAndMethod( Description description )
79 {
80 String name = description.getDisplayName();
81 String clazz = null;
82 String method = null;
83 if ( name != null )
84 {
85
86
87 name = name.trim();
88 if ( name.endsWith( ")" ) )
89 {
90 int classBracket = name.lastIndexOf( '(' );
91 if ( classBracket != -1 )
92 {
93 clazz = tryBlank( name.substring( classBracket + 1, name.length() - 1 ) );
94 method = tryBlank( name.substring( 0, classBracket ) );
95 }
96 }
97 }
98 return new ClassMethod( clazz, method );
99 }
100
101 private static String tryBlank( String s )
102 {
103 s = s.trim();
104 return isBlank( s ) ? null : s;
105 }
106
107 public static Filter createMatchAnyDescriptionFilter( Iterable<Description> descriptions )
108 {
109 return new MatchDescriptions( descriptions );
110 }
111 }