1 | |
package org.apache.maven.surefire.report; |
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.util.internal.ByteBuffer; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collections; |
26 | |
import java.util.Iterator; |
27 | |
import java.util.List; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class TestSetRunListener |
44 | |
implements RunListener, RunReporter, Reporter, ConsoleOutputReceiver |
45 | |
{ |
46 | |
private final RunStatistics globalStats; |
47 | |
|
48 | |
private final MulticastingReporter multicastingReporter; |
49 | |
|
50 | 0 | private final List testStdOut = Collections.synchronizedList( new ArrayList() ); |
51 | |
|
52 | 0 | private final List testStdErr = Collections.synchronizedList( new ArrayList() ); |
53 | |
|
54 | |
|
55 | |
public TestSetRunListener( List reports, RunStatistics globalStats ) |
56 | 0 | { |
57 | 0 | multicastingReporter = new MulticastingReporter( reports ); |
58 | 0 | this.globalStats = globalStats; |
59 | 0 | } |
60 | |
|
61 | |
public void writeMessage( String message ) |
62 | |
{ |
63 | 0 | multicastingReporter.writeMessage( message ); |
64 | 0 | } |
65 | |
|
66 | |
public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) |
67 | |
{ |
68 | 0 | ByteBuffer byteBuffer = new ByteBuffer( buf, off, len ); |
69 | 0 | if ( stdout ) |
70 | |
{ |
71 | 0 | testStdOut.add( byteBuffer ); |
72 | |
} |
73 | |
else |
74 | |
{ |
75 | 0 | testStdErr.add( byteBuffer ); |
76 | |
} |
77 | 0 | multicastingReporter.writeMessage( new String( buf, off, len ) ); |
78 | 0 | } |
79 | |
|
80 | |
public void writeDetailMessage( String message ) |
81 | |
{ |
82 | 0 | multicastingReporter.writeDetailMessage( message ); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void runStarting() |
90 | |
{ |
91 | 0 | multicastingReporter.runStarting(); |
92 | 0 | } |
93 | |
|
94 | |
public void runCompleted() |
95 | |
{ |
96 | 0 | multicastingReporter.runCompleted(); |
97 | 0 | multicastingReporter.writeFooter( "" ); |
98 | 0 | multicastingReporter.writeFooter( "Results :" ); |
99 | 0 | multicastingReporter.writeFooter( "" ); |
100 | 0 | if ( globalStats.hadFailures() ) |
101 | |
{ |
102 | 0 | multicastingReporter.writeFooter( "Failed tests: " ); |
103 | 0 | for ( Iterator iterator = this.globalStats.getFailureSources().iterator(); iterator.hasNext(); ) |
104 | |
{ |
105 | 0 | multicastingReporter.writeFooter( " " + iterator.next() ); |
106 | |
} |
107 | 0 | multicastingReporter.writeFooter( "" ); |
108 | |
} |
109 | 0 | if ( globalStats.hadErrors() ) |
110 | |
{ |
111 | 0 | writeFooter( "Tests in error: " ); |
112 | 0 | for ( Iterator iterator = this.globalStats.getErrorSources().iterator(); iterator.hasNext(); ) |
113 | |
{ |
114 | 0 | multicastingReporter.writeFooter( " " + iterator.next() ); |
115 | |
} |
116 | 0 | multicastingReporter.writeFooter( "" ); |
117 | |
} |
118 | 0 | multicastingReporter.writeFooter( globalStats.getSummary() ); |
119 | 0 | multicastingReporter.writeFooter( "" ); |
120 | 0 | } |
121 | |
|
122 | |
public void writeFooter( String footer ) |
123 | |
{ |
124 | 0 | multicastingReporter.writeFooter( footer ); |
125 | 0 | } |
126 | |
|
127 | |
|
128 | |
public void testSetStarting( ReportEntry report ) |
129 | |
throws ReporterException |
130 | |
{ |
131 | 0 | multicastingReporter.testSetStarting( report ); |
132 | 0 | } |
133 | |
|
134 | |
public void testSetCompleted( ReportEntry report ) |
135 | |
{ |
136 | 0 | multicastingReporter.testSetCompleted( report ); |
137 | 0 | multicastingReporter.reset(); |
138 | 0 | } |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public void testStarting( ReportEntry report ) |
145 | |
{ |
146 | 0 | multicastingReporter.testStarting( report ); |
147 | 0 | } |
148 | |
|
149 | |
public void testSucceeded( ReportEntry report ) |
150 | |
{ |
151 | 0 | clearCapturedContent(); |
152 | 0 | globalStats.incrementCompletedCount(); |
153 | 0 | multicastingReporter.testSucceeded( report ); |
154 | 0 | } |
155 | |
|
156 | |
public void testError( ReportEntry reportEntry ) |
157 | |
{ |
158 | 0 | testError( reportEntry, getAsString( testStdOut ), getAsString( testStdErr ) ); |
159 | 0 | } |
160 | |
|
161 | |
public void testError( ReportEntry reportEntry, String stdOutLog, String stdErrLog ) |
162 | |
{ |
163 | 0 | multicastingReporter.testError( reportEntry, stdOutLog, stdErrLog ); |
164 | 0 | globalStats.incrementErrorsCount(); |
165 | 0 | globalStats.incrementCompletedCount(); |
166 | 0 | globalStats.addErrorSource( reportEntry.getName(), reportEntry.getStackTraceWriter() ); |
167 | 0 | clearCapturedContent(); |
168 | 0 | } |
169 | |
|
170 | |
public void testFailed( ReportEntry reportEntry ) |
171 | |
{ |
172 | 0 | testFailed( reportEntry, getAsString( testStdOut ), getAsString( testStdErr ) ); |
173 | 0 | } |
174 | |
|
175 | |
public void testFailed( ReportEntry reportEntry, String stdOutLog, String stdErrLog ) |
176 | |
{ |
177 | 0 | multicastingReporter.testFailed( reportEntry, stdOutLog, stdErrLog ); |
178 | 0 | globalStats.incrementFailureCount(); |
179 | 0 | globalStats.incrementCompletedCount(); |
180 | 0 | globalStats.addFailureSource( reportEntry.getName(), reportEntry.getStackTraceWriter() ); |
181 | 0 | clearCapturedContent(); |
182 | 0 | } |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
public void testSkipped( ReportEntry report ) |
189 | |
{ |
190 | 0 | clearCapturedContent(); |
191 | 0 | globalStats.incrementSkippedCount(); |
192 | 0 | globalStats.incrementCompletedCount(); |
193 | 0 | multicastingReporter.testSkipped( report ); |
194 | 0 | } |
195 | |
|
196 | |
public void testAssumptionFailure( ReportEntry report ) |
197 | |
{ |
198 | 0 | testSkipped( report ); |
199 | 0 | } |
200 | |
|
201 | |
public void reset() |
202 | |
{ |
203 | 0 | multicastingReporter.reset(); |
204 | 0 | } |
205 | |
|
206 | |
public String getAsString( List byteBufferList ) |
207 | |
{ |
208 | 0 | StringBuffer stringBuffer = new StringBuffer(); |
209 | 0 | for ( Iterator iter = byteBufferList.iterator(); iter.hasNext(); ) |
210 | |
{ |
211 | 0 | ByteBuffer byteBuffer = (ByteBuffer) iter.next(); |
212 | 0 | stringBuffer.append( byteBuffer.toString() ); |
213 | 0 | } |
214 | 0 | return stringBuffer.toString(); |
215 | |
} |
216 | |
|
217 | |
public void clearCapturedContent() |
218 | |
{ |
219 | 0 | testStdErr.clear(); |
220 | 0 | testStdOut.clear(); |
221 | 0 | } |
222 | |
|
223 | |
|
224 | |
} |