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