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 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
protected AbstractReporter( boolean trimStackTrace ) |
61 | 0 | { |
62 | 0 | this.trimStackTrace = trimStackTrace; |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
public void writeMessage( byte[] b, int off, int len ) |
67 | |
{ |
68 | |
|
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
public void testSetStarting( ReportEntry report ) |
74 | |
throws ReporterException |
75 | |
{ |
76 | 0 | testSetStartTime = System.currentTimeMillis(); |
77 | 0 | } |
78 | |
|
79 | |
public void testSetCompleted( ReportEntry report ) |
80 | |
throws ReporterException |
81 | |
{ |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void testStarting( ReportEntry report ) |
89 | |
{ |
90 | 0 | startTime = System.currentTimeMillis(); |
91 | 0 | } |
92 | |
|
93 | |
public void testSucceeded( ReportEntry report ) |
94 | |
{ |
95 | 0 | endTest(); |
96 | 0 | } |
97 | |
|
98 | |
public void testSkipped( ReportEntry report ) |
99 | |
{ |
100 | 0 | ++skipped; |
101 | |
|
102 | 0 | endTest(); |
103 | 0 | } |
104 | |
|
105 | |
public void testError( ReportEntry report, String stdOut, String stdErr ) |
106 | |
{ |
107 | 0 | ++errors; |
108 | 0 | endTest(); |
109 | 0 | } |
110 | |
|
111 | |
public void testFailed( ReportEntry report, String stdOut, String stdErr ) |
112 | |
{ |
113 | 0 | ++failures; |
114 | 0 | endTest(); |
115 | 0 | } |
116 | |
|
117 | |
private void endTest() |
118 | |
{ |
119 | 0 | ++completedCount; |
120 | |
|
121 | 0 | endTime = System.currentTimeMillis(); |
122 | |
|
123 | |
|
124 | 0 | if ( startTime == 0 ) |
125 | |
{ |
126 | 0 | startTime = endTime; |
127 | |
} |
128 | 0 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
int getNumErrors() |
135 | |
{ |
136 | 0 | return errors; |
137 | |
} |
138 | |
|
139 | |
int getNumSkipped() |
140 | |
{ |
141 | 0 | return skipped; |
142 | |
} |
143 | |
|
144 | |
int getNumFailures() |
145 | |
{ |
146 | 0 | return failures; |
147 | |
} |
148 | |
|
149 | |
int getNumTests() |
150 | |
{ |
151 | 0 | return completedCount; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public void reset() |
159 | |
{ |
160 | 0 | errors = 0; |
161 | |
|
162 | 0 | skipped = 0; |
163 | |
|
164 | 0 | failures = 0; |
165 | |
|
166 | 0 | completedCount = 0; |
167 | |
|
168 | 0 | } |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
String elapsedTimeAsString( long runTime ) |
175 | |
{ |
176 | 0 | return numberFormat.format( (double) runTime / MS_PER_SEC ); |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
String getStackTrace( ReportEntry report ) |
186 | |
{ |
187 | 0 | StackTraceWriter writer = report.getStackTraceWriter(); |
188 | 0 | if ( writer == null ) |
189 | |
{ |
190 | 0 | return null; |
191 | |
} |
192 | 0 | return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString(); |
193 | |
} |
194 | |
|
195 | |
long getActualRunTime( ReportEntry reportEntry ) |
196 | |
{ |
197 | 0 | final Integer clientSpecifiedElapsed = reportEntry.getElapsed(); |
198 | 0 | return clientSpecifiedElapsed != null ? clientSpecifiedElapsed.intValue() : endTime - startTime; |
199 | |
} |
200 | |
|
201 | |
void deleteIfExisting( File reportFile ) |
202 | |
{ |
203 | 0 | if ( reportFile.exists() ) |
204 | |
{ |
205 | |
|
206 | 0 | reportFile.delete(); |
207 | |
} |
208 | 0 | } |
209 | |
} |