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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 import java.util.concurrent.atomic.AtomicInteger;
44
45 import org.junit.runner.Description;
46 import org.junit.runner.Result;
47 import org.junit.runner.notification.Failure;
48 import org.junit.runner.notification.RunListener;
49
50
51
52
53 public class DiagnosticRunListener
54 extends RunListener
55 {
56 private final AtomicInteger numTestStarted = new AtomicInteger();
57
58 private final AtomicInteger numTestFailed = new AtomicInteger();
59
60 private final AtomicInteger numTestAssumptionsFailed = new AtomicInteger();
61
62 private final AtomicInteger numTestFinished = new AtomicInteger();
63
64 private final AtomicInteger numTestIgnored = new AtomicInteger();
65
66 private final boolean printToConsole;
67
68 private final RunListener target;
69
70
71 private void print( String event, Description description )
72 {
73 if ( printToConsole )
74 {
75 System.out.println( Thread.currentThread().toString() + ", event = " + event + ", " + description );
76 }
77 }
78
79 private void print( String event, Result description )
80 {
81 if ( printToConsole )
82 {
83 System.out.println( Thread.currentThread().toString() + ", event = " + event + ", " + description );
84 }
85 }
86
87 private void print( String event, Failure description )
88 {
89 if ( printToConsole )
90 {
91 System.out.println( Thread.currentThread().toString() + ", event = " + event + ", " + description );
92 }
93 }
94
95 public DiagnosticRunListener( boolean printToConsole, RunListener target )
96 {
97 this.printToConsole = printToConsole;
98 this.target = target;
99 }
100
101 @Override
102 public void testRunStarted( Description description )
103 throws Exception
104 {
105 print( "testRunStarted", description );
106 if ( target != null )
107 {
108 target.testRunStarted( description );
109 }
110 }
111
112 @Override
113 public void testRunFinished( Result result )
114 throws Exception
115 {
116 print( "testRunFinished", result );
117 if ( target != null )
118 {
119 target.testRunFinished( result );
120 }
121 }
122
123 @Override
124 public void testStarted( Description description )
125 throws Exception
126 {
127 numTestStarted.incrementAndGet();
128 print( "testStarted", description );
129 if ( target != null )
130 {
131 target.testStarted( description );
132 }
133 }
134
135 @Override
136 public void testFinished( Description description )
137 throws Exception
138 {
139 numTestFinished.incrementAndGet();
140 print( "testFinished", description );
141 if ( target != null )
142 {
143 target.testFinished( description );
144 }
145 }
146
147 @Override
148 public void testFailure( Failure failure )
149 throws Exception
150 {
151 numTestFailed.incrementAndGet();
152 print( "testFailure", failure );
153 if ( target != null )
154 {
155 target.testFailure( failure );
156 }
157 }
158
159 @Override
160 public void testAssumptionFailure( Failure failure )
161 {
162 numTestAssumptionsFailed.incrementAndGet();
163 print( "testAssumptionFailure", failure );
164 if ( target != null )
165 {
166 target.testAssumptionFailure( failure );
167 }
168 }
169
170 @Override
171 public void testIgnored( Description description )
172 throws Exception
173 {
174 numTestIgnored.incrementAndGet();
175 print( "testIgnored", description );
176 if ( target != null )
177 {
178 target.testIgnored( description );
179 }
180 }
181
182 @Override
183 public String toString()
184 {
185 return "DiagnosticRunListener{" + "numTestIgnored=" + numTestIgnored + ", numTestStarted=" + numTestStarted
186 + ", numTestFailed=" + numTestFailed + ", numTestAssumptionsFailed=" + numTestAssumptionsFailed
187 + ", numTestFinished=" + numTestFinished + '}';
188 }
189 }