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 org.apache.maven.surefire.util.TestsToRun;
23 import org.apache.maven.surefire.util.internal.StringUtils;
24
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import org.junit.runner.Description;
33 import org.junit.runner.notification.Failure;
34
35 import static org.apache.maven.surefire.common.junit4.JUnit4RunListener.isFailureInsideJUnitItself;
36
37
38
39
40
41
42
43
44 public class JUnit4ProviderUtil
45 {
46
47
48
49
50
51
52
53 public static Map<Class<?>, Set<String>> generateFailingTests( List<Failure> allFailures, TestsToRun testsToRun )
54 {
55 Map<Class<?>, Set<String>> testClassMethods = new HashMap<Class<?>, Set<String>>();
56
57 for ( Failure failure : allFailures )
58 {
59 if ( !isFailureInsideJUnitItself( failure ) )
60 {
61
62 String[] testMethodClass = StringUtils.split( failure.getTestHeader(), "(" );
63 String testMethod = testMethodClass[0];
64 String testClass = StringUtils.split( testMethodClass[1], ")" )[0];
65 Class testClassObj = testsToRun.getClassByName( testClass );
66
67 if ( testClassObj == null )
68 {
69 continue;
70 }
71
72 Set<String> failingMethods = testClassMethods.get( testClassObj );
73 if ( failingMethods == null )
74 {
75 failingMethods = new HashSet<String>();
76 failingMethods.add( testMethod );
77 testClassMethods.put( testClassObj, failingMethods );
78 }
79 else
80 {
81 failingMethods.add( testMethod );
82 }
83 }
84 }
85 return testClassMethods;
86 }
87
88
89
90
91
92
93
94 public static Set<String> generateFailingTests( List<Failure> allFailures )
95 {
96 Set<String> failingMethods = new HashSet<String>();
97
98 for ( Failure failure : allFailures )
99 {
100 if ( !isFailureInsideJUnitItself( failure ) )
101 {
102
103 String testMethod = StringUtils.split( failure.getTestHeader(), "(" )[0];
104 failingMethods.add( testMethod );
105 }
106 }
107 return failingMethods;
108 }
109
110 public static Description createSuiteDescription( Collection<Class<?>> classes )
111 {
112 JUnit4Reflector reflector = new JUnit4Reflector();
113 return reflector.createRequest( classes.toArray( new Class[classes.size()] ) )
114 .getRunner()
115 .getDescription();
116 }
117
118 }