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
33
34
35
36 public class WrappedReportEntry
37 implements TestSetReportEntry
38 {
39 private final ReportEntry original;
40
41 private final ReportEntryType reportEntryType;
42
43 private final Integer elapsed;
44
45 private final Utf8RecodingDeferredFileOutputStream stdout;
46
47 private final Utf8RecodingDeferredFileOutputStream stdErr;
48
49 private final Map<String, String> systemProperties;
50
51 public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
52 Utf8RecodingDeferredFileOutputStream stdout,
53 Utf8RecodingDeferredFileOutputStream stdErr,
54 Map<String, String> systemProperties )
55 {
56 this.original = original;
57 this.reportEntryType = reportEntryType;
58 this.elapsed = estimatedElapsed;
59 this.stdout = stdout;
60 this.stdErr = stdErr;
61 this.systemProperties = unmodifiableMap( systemProperties );
62 }
63
64 public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
65 Utf8RecodingDeferredFileOutputStream stdout,
66 Utf8RecodingDeferredFileOutputStream stdErr )
67 {
68 this( original, reportEntryType, estimatedElapsed, stdout, stdErr, Collections.<String, String>emptyMap() );
69 }
70
71 @Override
72 public Integer getElapsed()
73 {
74 return elapsed;
75 }
76
77 public ReportEntryType getReportEntryType()
78 {
79 return reportEntryType;
80 }
81
82 public Utf8RecodingDeferredFileOutputStream getStdout()
83 {
84 return stdout;
85 }
86
87 public Utf8RecodingDeferredFileOutputStream getStdErr()
88 {
89 return stdErr;
90 }
91
92 @Override
93 public String getSourceName()
94 {
95 return original.getSourceName();
96 }
97
98 @Override
99 public String getName()
100 {
101 return original.getName();
102 }
103
104 public String getClassMethodName()
105 {
106 return getSourceName() + "." + getName();
107 }
108
109 @Override
110 public String getGroup()
111 {
112 return original.getGroup();
113 }
114
115 @Override
116 public StackTraceWriter getStackTraceWriter()
117 {
118 return original.getStackTraceWriter();
119 }
120
121 @Override
122 public String getMessage()
123 {
124 return original.getMessage();
125 }
126
127 public String getStackTrace( boolean trimStackTrace )
128 {
129 StackTraceWriter w = original.getStackTraceWriter();
130 return w == null ? null : ( trimStackTrace ? w.writeTrimmedTraceToString() : w.writeTraceToString() );
131 }
132
133 public String elapsedTimeAsString()
134 {
135 return formatElapsedTime( getElapsed() );
136 }
137
138 public String getReportName()
139 {
140 final int i = getName().lastIndexOf( "(" );
141 return i > 0 ? getName().substring( 0, i ) : getName();
142 }
143
144 public String getReportName( String suffix )
145 {
146 return suffix != null && !suffix.isEmpty() ? getReportName() + "(" + suffix + ")" : getReportName();
147 }
148
149 public String getOutput( boolean trimStackTrace )
150 {
151 String outputLine = getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
152 String trimmedStackTrace = getStackTrace( trimStackTrace );
153 return trimmedStackTrace == null ? outputLine : outputLine + NL + trimmedStackTrace;
154 }
155
156 public String getElapsedTimeVerbose()
157 {
158 return "Time elapsed: " + elapsedTimeAsString() + " s";
159 }
160
161 public String getElapsedTimeSummary()
162 {
163 return getName() + " " + getElapsedTimeVerbose();
164 }
165
166 public boolean isErrorOrFailure()
167 {
168 ReportEntryType thisType = getReportEntryType();
169 return ReportEntryType.FAILURE == thisType || ReportEntryType.ERROR == thisType;
170 }
171
172 public boolean isSkipped()
173 {
174 return ReportEntryType.SKIPPED == getReportEntryType();
175 }
176
177 public boolean isSucceeded()
178 {
179 return ReportEntryType.SUCCESS == getReportEntryType();
180 }
181
182 @Override
183 public String getNameWithGroup()
184 {
185 return original.getNameWithGroup();
186 }
187
188 @Override
189 public Map<String, String> getSystemProperties()
190 {
191 return systemProperties;
192 }
193 }