Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JUnitCoreRunListener |
|
| 0.0;0 |
1 | package org.apache.maven.surefire.junitcore; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
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 | * @param reporter the report manager to log testing events to | |
38 | * @param classMethodCounts A map of methods | |
39 | */ | |
40 | public JUnitCoreRunListener( RunListener reporter, Map<String, TestSet> classMethodCounts ) | |
41 | { | |
42 | 0 | super( reporter ); |
43 | 0 | this.classMethodCounts = classMethodCounts; |
44 | 0 | } |
45 | ||
46 | /** | |
47 | * Called right before any tests from a specific class are run. | |
48 | * | |
49 | * @see org.junit.runner.notification.RunListener#testRunStarted(org.junit.runner.Description) | |
50 | */ | |
51 | public void testRunStarted( Description description ) | |
52 | throws Exception | |
53 | { | |
54 | 0 | fillTestCountMap( description ); |
55 | 0 | reporter.testSetStarting( null ); // Not entirely meaningful as we can see |
56 | 0 | } |
57 | ||
58 | @Override | |
59 | public void testRunFinished( Result result ) | |
60 | throws Exception | |
61 | { | |
62 | 0 | reporter.testSetCompleted( null ); |
63 | 0 | } |
64 | ||
65 | private void fillTestCountMap( Description description ) | |
66 | { | |
67 | 0 | final ArrayList<Description> children = description.getChildren(); |
68 | ||
69 | 0 | TestSet testSet = new TestSet( description ); |
70 | 0 | Class<?> itemTestClass = null; |
71 | 0 | for ( Description item : children ) |
72 | { | |
73 | 0 | if ( item.isTest() ) |
74 | { | |
75 | 0 | testSet.incrementTestMethodCount(); |
76 | 0 | if ( itemTestClass == null ) |
77 | { | |
78 | 0 | itemTestClass = item.getTestClass(); |
79 | } | |
80 | } | |
81 | 0 | else if ( item.getChildren().size() > 0 ) |
82 | { | |
83 | 0 | fillTestCountMap( item ); |
84 | } | |
85 | } | |
86 | 0 | if ( itemTestClass != null ) |
87 | { | |
88 | 0 | classMethodCounts.put( itemTestClass.getName(), testSet ); |
89 | } | |
90 | 0 | } |
91 | ||
92 | } |