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