1 | |
package org.apache.maven.surefire.junitcore; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Map; |
24 | |
import org.apache.maven.surefire.common.junit4.JUnit4RunListener; |
25 | |
import org.apache.maven.surefire.common.junit48.JUnit46StackTraceWriter; |
26 | |
import org.apache.maven.surefire.report.RunListener; |
27 | |
import org.apache.maven.surefire.report.StackTraceWriter; |
28 | |
|
29 | |
import org.junit.runner.Description; |
30 | |
import org.junit.runner.Result; |
31 | |
import org.junit.runner.notification.Failure; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class JUnitCoreRunListener |
43 | |
extends JUnit4RunListener |
44 | |
{ |
45 | |
private final Map<String, TestSet> classMethodCounts; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public JUnitCoreRunListener( RunListener reporter, Map<String, TestSet> classMethodCounts ) |
52 | |
{ |
53 | 28 | super( reporter ); |
54 | 28 | this.classMethodCounts = classMethodCounts; |
55 | 28 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public void testRunStarted( Description description ) |
63 | |
throws Exception |
64 | |
{ |
65 | 28 | fillTestCountMap( description ); |
66 | 28 | reporter.testSetStarting( null ); |
67 | 28 | } |
68 | |
|
69 | |
@Override |
70 | |
public void testRunFinished( Result result ) |
71 | |
throws Exception |
72 | |
{ |
73 | 26 | reporter.testSetCompleted( null ); |
74 | 26 | } |
75 | |
|
76 | |
private void fillTestCountMap( Description description ) |
77 | |
{ |
78 | 67 | final ArrayList<Description> children = description.getChildren(); |
79 | |
|
80 | 67 | TestSet testSet = new TestSet( description ); |
81 | 67 | String itemTestClassName = null; |
82 | 67 | for ( Description item : children ) |
83 | |
{ |
84 | 129 | if ( !item.isTest() ) |
85 | |
{ |
86 | 39 | fillTestCountMap( item ); |
87 | |
} |
88 | |
else |
89 | |
{ |
90 | 90 | if ( item.getMethodName() != null ) |
91 | |
{ |
92 | 88 | testSet.incrementTestMethodCount(); |
93 | 88 | if ( itemTestClassName == null ) |
94 | |
{ |
95 | 40 | itemTestClassName = item.getClassName(); |
96 | |
} |
97 | |
} |
98 | |
else |
99 | |
{ |
100 | 2 | classMethodCounts.put( item.getClassName(), new TestSet( item ) ); |
101 | |
} |
102 | |
} |
103 | |
} |
104 | 67 | if ( itemTestClassName != null ) |
105 | |
{ |
106 | 40 | classMethodCounts.put( itemTestClassName, testSet ); |
107 | |
} |
108 | 67 | } |
109 | |
|
110 | |
@Override |
111 | |
protected StackTraceWriter createStackTraceWriter( Failure failure ) |
112 | |
{ |
113 | 9 | return new JUnit46StackTraceWriter( failure ); |
114 | |
} |
115 | |
} |