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.io.File; |
23 | |
import java.text.NumberFormat; |
24 | |
import java.util.Locale; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public abstract class AbstractReporter |
31 | |
implements Reporter |
32 | |
{ |
33 | |
int completedCount; |
34 | |
|
35 | |
int errors; |
36 | |
|
37 | |
int failures; |
38 | |
|
39 | |
private long startTime; |
40 | |
|
41 | |
private long endTime; |
42 | |
|
43 | 0 | private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH ); |
44 | |
|
45 | 0 | static final String NL = System.getProperty( "line.separator" ); |
46 | |
|
47 | |
private static final int MS_PER_SEC = 1000; |
48 | |
|
49 | |
long testSetStartTime; |
50 | |
|
51 | |
int skipped; |
52 | |
|
53 | |
private final boolean trimStackTrace; |
54 | |
|
55 | |
private final ReporterConfiguration reporterConfiguration; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
AbstractReporter( ReporterConfiguration reporterConfiguration ) |
63 | 0 | { |
64 | 0 | this.reporterConfiguration = reporterConfiguration; |
65 | 0 | this.trimStackTrace = reporterConfiguration.isTrimStackTrace().booleanValue(); |
66 | 0 | } |
67 | |
|
68 | |
boolean isTimedOut() |
69 | |
{ |
70 | 0 | return reporterConfiguration.isTimedOut(); |
71 | |
} |
72 | |
|
73 | |
public void writeFooter( String footer ) |
74 | |
{ |
75 | 0 | writeMessage( footer ); |
76 | 0 | } |
77 | |
|
78 | |
public void runStarting() |
79 | |
{ |
80 | 0 | } |
81 | |
|
82 | |
public void runCompleted() |
83 | |
{ |
84 | 0 | } |
85 | |
|
86 | |
public void testSetStarting( ReportEntry report ) |
87 | |
throws ReporterException |
88 | |
{ |
89 | 0 | testSetStartTime = System.currentTimeMillis(); |
90 | 0 | } |
91 | |
|
92 | |
public void testSetCompleted( ReportEntry report ) |
93 | |
throws ReporterException |
94 | |
{ |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public void testStarting( ReportEntry report ) |
102 | |
{ |
103 | 0 | startTime = System.currentTimeMillis(); |
104 | 0 | } |
105 | |
|
106 | |
public void testSucceeded( ReportEntry report ) |
107 | |
{ |
108 | 0 | endTest(); |
109 | 0 | } |
110 | |
|
111 | |
public void testSkipped( ReportEntry report ) |
112 | |
{ |
113 | 0 | ++skipped; |
114 | |
|
115 | 0 | endTest(); |
116 | 0 | } |
117 | |
|
118 | |
public void testError( ReportEntry report, String stdOut, String stdErr ) |
119 | |
{ |
120 | 0 | ++errors; |
121 | 0 | endTest(); |
122 | 0 | } |
123 | |
|
124 | |
public void testFailed( ReportEntry report, String stdOut, String stdErr ) |
125 | |
{ |
126 | 0 | ++failures; |
127 | 0 | endTest(); |
128 | 0 | } |
129 | |
|
130 | |
private void endTest() |
131 | |
{ |
132 | 0 | ++completedCount; |
133 | |
|
134 | 0 | endTime = System.currentTimeMillis(); |
135 | |
|
136 | |
|
137 | 0 | if ( startTime == 0 ) |
138 | |
{ |
139 | 0 | startTime = endTime; |
140 | |
} |
141 | 0 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
int getNumErrors() |
148 | |
{ |
149 | 0 | return errors; |
150 | |
} |
151 | |
|
152 | |
int getNumSkipped() |
153 | |
{ |
154 | 0 | return skipped; |
155 | |
} |
156 | |
|
157 | |
int getNumFailures() |
158 | |
{ |
159 | 0 | return failures; |
160 | |
} |
161 | |
|
162 | |
int getNumTests() |
163 | |
{ |
164 | 0 | return completedCount; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
public void reset() |
172 | |
{ |
173 | 0 | errors = 0; |
174 | |
|
175 | 0 | skipped = 0; |
176 | |
|
177 | 0 | failures = 0; |
178 | |
|
179 | 0 | completedCount = 0; |
180 | |
|
181 | 0 | } |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
String elapsedTimeAsString( long runTime ) |
188 | |
{ |
189 | 0 | return numberFormat.format( (double) runTime / MS_PER_SEC ); |
190 | |
} |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
String getStackTrace( ReportEntry report ) |
199 | |
{ |
200 | 0 | StackTraceWriter writer = report.getStackTraceWriter(); |
201 | 0 | if ( writer == null ) |
202 | |
{ |
203 | 0 | return null; |
204 | |
} |
205 | 0 | return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString(); |
206 | |
} |
207 | |
|
208 | |
long getActualRunTime( ReportEntry reportEntry ) |
209 | |
{ |
210 | 0 | final Integer clientSpecifiedElapsed = reportEntry.getElapsed(); |
211 | 0 | return clientSpecifiedElapsed != null ? clientSpecifiedElapsed.intValue() : endTime - startTime; |
212 | |
} |
213 | |
|
214 | |
|
215 | |
public void testError( ReportEntry report ) |
216 | |
{ |
217 | 0 | } |
218 | |
|
219 | |
|
220 | |
public void testFailed( ReportEntry report ) |
221 | |
{ |
222 | 0 | } |
223 | |
|
224 | |
|
225 | |
public void testAssumptionFailure( ReportEntry report ) |
226 | |
{ |
227 | 0 | } |
228 | |
|
229 | |
void deleteIfExisting( File reportFile ) |
230 | |
{ |
231 | 0 | if ( reportFile.exists() ) |
232 | |
{ |
233 | |
|
234 | 0 | reportFile.delete(); |
235 | |
} |
236 | 0 | } |
237 | |
} |