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