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.report.RunListener;
26
27 import org.junit.runner.Description;
28 import org.junit.runner.Result;
29
30 public class JUnitCoreRunListener
31 extends JUnit4RunListener
32 {
33 private final Map<String, TestSet> classMethodCounts;
34
35
36
37
38
39 public JUnitCoreRunListener( RunListener reporter, Map<String, TestSet> classMethodCounts )
40 {
41 super( reporter );
42 this.classMethodCounts = classMethodCounts;
43 }
44
45
46
47
48
49
50 public void testRunStarted( Description description )
51 throws Exception
52 {
53 fillTestCountMap( description );
54 reporter.testSetStarting( null );
55 }
56
57 @Override
58 public void testRunFinished( Result result )
59 throws Exception
60 {
61 reporter.testSetCompleted( null );
62 }
63
64 private void fillTestCountMap( Description description )
65 {
66 final ArrayList<Description> children = description.getChildren();
67
68 TestSet testSet = new TestSet( description );
69 Class<?> itemTestClass = null;
70 for ( Description item : children )
71 {
72 if ( item.isTest() && item.getMethodName() != null )
73 {
74 testSet.incrementTestMethodCount();
75 if ( itemTestClass == null )
76 {
77 itemTestClass = item.getTestClass();
78 }
79 }
80 else if ( item.getChildren().size() > 0 )
81 {
82 fillTestCountMap( item );
83 }
84 else
85 {
86 classMethodCounts.put( item.getClassName(), testSet );
87 }
88 }
89 if ( itemTestClass != null )
90 {
91 classMethodCounts.put( itemTestClass.getName(), testSet );
92 }
93 }
94
95 }