1 package org.apache.maven.plugin.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.report.ReportEntry;
23 import org.apache.maven.surefire.report.StackTraceWriter;
24 import org.apache.maven.surefire.report.TestSetReportEntry;
25
26 import java.util.Collections;
27 import java.util.Map;
28
29 import static java.util.Collections.unmodifiableMap;
30 import static org.apache.maven.plugin.surefire.report.ReporterUtils.formatElapsedTime;
31 import static org.apache.maven.surefire.util.internal.StringUtils.NL;
32 import static org.apache.maven.surefire.util.internal.StringUtils.isBlank;
33
34
35
36
37 public class WrappedReportEntry
38 implements TestSetReportEntry
39 {
40 private final ReportEntry original;
41
42 private final ReportEntryType reportEntryType;
43
44 private final Integer elapsed;
45
46 private final Utf8RecodingDeferredFileOutputStream stdout;
47
48 private final Utf8RecodingDeferredFileOutputStream stdErr;
49
50 private final Map<String, String> systemProperties;
51
52 public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
53 Utf8RecodingDeferredFileOutputStream stdout,
54 Utf8RecodingDeferredFileOutputStream stdErr,
55 Map<String, String> systemProperties )
56 {
57 this.original = original;
58 this.reportEntryType = reportEntryType;
59 this.elapsed = estimatedElapsed;
60 this.stdout = stdout;
61 this.stdErr = stdErr;
62 this.systemProperties = unmodifiableMap( systemProperties );
63 }
64
65 public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
66 Utf8RecodingDeferredFileOutputStream stdout,
67 Utf8RecodingDeferredFileOutputStream stdErr )
68 {
69 this( original, reportEntryType, estimatedElapsed, stdout, stdErr, Collections.<String, String>emptyMap() );
70 }
71
72 @Override
73 public Integer getElapsed()
74 {
75 return elapsed;
76 }
77
78 @Override
79 public int getElapsed( int fallback )
80 {
81 return elapsed == null ? fallback : elapsed;
82 }
83
84 public ReportEntryType getReportEntryType()
85 {
86 return reportEntryType;
87 }
88
89 public Utf8RecodingDeferredFileOutputStream getStdout()
90 {
91 return stdout;
92 }
93
94 public Utf8RecodingDeferredFileOutputStream getStdErr()
95 {
96 return stdErr;
97 }
98
99 @Override
100 public String getSourceName()
101 {
102 return original.getSourceName();
103 }
104
105 @Override
106 public String getSourceText()
107 {
108 return original.getSourceText();
109 }
110
111 @Override
112 public String getName()
113 {
114 return original.getName();
115 }
116
117 @Override
118 public String getNameText()
119 {
120 return original.getNameText();
121 }
122
123 public String getClassMethodName()
124 {
125 return original.getSourceName() + "." + original.getName();
126 }
127
128 @Override
129 public String getGroup()
130 {
131 return original.getGroup();
132 }
133
134 @Override
135 public StackTraceWriter getStackTraceWriter()
136 {
137 return original.getStackTraceWriter();
138 }
139
140 @Override
141 public String getMessage()
142 {
143 return original.getMessage();
144 }
145
146 public String getStackTrace( boolean trimStackTrace )
147 {
148 StackTraceWriter w = original.getStackTraceWriter();
149 return w == null ? null : ( trimStackTrace ? w.writeTrimmedTraceToString() : w.writeTraceToString() );
150 }
151
152 public String elapsedTimeAsString()
153 {
154 return formatElapsedTime( getElapsed() );
155 }
156
157 String getReportSourceName()
158 {
159 String sourceName = getSourceName();
160 String sourceText = getSourceText();
161 return isBlank( sourceText ) ? sourceName : sourceText;
162 }
163
164 String getReportSourceName( String suffix )
165 {
166 return isBlank( suffix ) ? getReportSourceName() : getReportSourceName() + "(" + suffix + ")";
167 }
168
169 String getSourceName( String suffix )
170 {
171 return isBlank( suffix ) ? getSourceName() : getSourceName() + "(" + suffix + ")";
172 }
173
174 String getReportName()
175 {
176 String name = getName();
177 String nameText = getNameText();
178 return isBlank( nameText ) ? name : nameText;
179 }
180
181 public String getOutput( boolean trimStackTrace )
182 {
183 String outputLine = getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
184 String trimmedStackTrace = getStackTrace( trimStackTrace );
185 return trimmedStackTrace == null ? outputLine : outputLine + NL + trimmedStackTrace;
186 }
187
188 public String getElapsedTimeVerbose()
189 {
190 return "Time elapsed: " + elapsedTimeAsString() + " s";
191 }
192
193 public String getElapsedTimeSummary()
194 {
195 String description = getName() == null ? getSourceName() : getClassMethodName();
196 return description + " " + getElapsedTimeVerbose();
197 }
198
199 public boolean isErrorOrFailure()
200 {
201 ReportEntryType thisType = getReportEntryType();
202 return ReportEntryType.FAILURE == thisType || ReportEntryType.ERROR == thisType;
203 }
204
205 public boolean isSkipped()
206 {
207 return ReportEntryType.SKIPPED == getReportEntryType();
208 }
209
210 public boolean isSucceeded()
211 {
212 return ReportEntryType.SUCCESS == getReportEntryType();
213 }
214
215 @Override
216 public String getNameWithGroup()
217 {
218 return original.getNameWithGroup();
219 }
220
221 @Override
222 public String getReportNameWithGroup()
223 {
224 return original.getReportNameWithGroup();
225 }
226
227 @Override
228 public Map<String, String> getSystemProperties()
229 {
230 return systemProperties;
231 }
232 }