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 super( reporter );
54 this.classMethodCounts = classMethodCounts;
55 }
56
57
58
59
60
61
62 public void testRunStarted( Description description )
63 throws Exception
64 {
65 fillTestCountMap( description );
66 reporter.testSetStarting( null );
67 }
68
69 @Override
70 public void testRunFinished( Result result )
71 throws Exception
72 {
73 reporter.testSetCompleted( null );
74 }
75
76 private void fillTestCountMap( Description description )
77 {
78 final ArrayList<Description> children = description.getChildren();
79
80 TestSet testSet = new TestSet( description );
81 String itemTestClassName = null;
82 for ( Description item : children )
83 {
84 if ( !item.isTest() )
85 {
86 fillTestCountMap( item );
87 }
88 else
89 {
90 if ( item.getMethodName() != null )
91 {
92 testSet.incrementTestMethodCount();
93 if ( itemTestClassName == null )
94 {
95 itemTestClassName = item.getClassName();
96 }
97 }
98 else
99 {
100 classMethodCounts.put( item.getClassName(), new TestSet( item ) );
101 }
102 }
103 }
104 if ( itemTestClassName != null )
105 {
106 classMethodCounts.put( itemTestClassName, testSet );
107 }
108 }
109
110 @Override
111 protected StackTraceWriter createStackTraceWriter( Failure failure )
112 {
113 return new JUnit46StackTraceWriter( failure );
114 }
115 }