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 java.text.NumberFormat;
23 import java.util.Locale;
24
25 import org.apache.maven.surefire.report.ReportEntry;
26 import org.apache.maven.surefire.report.StackTraceWriter;
27
28
29
30
31 public class WrappedReportEntry
32 implements ReportEntry
33 {
34 private final ReportEntry original;
35
36 private final ReportEntryType reportEntryType;
37
38 private final Integer elapsed;
39
40 private final Utf8RecodingDeferredFileOutputStream stdout;
41
42 private final Utf8RecodingDeferredFileOutputStream stdErr;
43
44 private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH );
45
46 private static final int MS_PER_SEC = 1000;
47
48 static final String NL = System.getProperty( "line.separator" );
49
50 public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
51 Utf8RecodingDeferredFileOutputStream stdout, Utf8RecodingDeferredFileOutputStream stdErr )
52 {
53 this.original = original;
54 this.reportEntryType = reportEntryType;
55 this.elapsed = estimatedElapsed;
56 this.stdout = stdout;
57 this.stdErr = stdErr;
58 }
59
60 public Integer getElapsed()
61 {
62 return elapsed;
63 }
64
65 public ReportEntryType getReportEntryType()
66 {
67 return reportEntryType;
68 }
69
70 public Utf8RecodingDeferredFileOutputStream getStdout()
71 {
72 return stdout;
73 }
74
75 public Utf8RecodingDeferredFileOutputStream getStdErr()
76 {
77 return stdErr;
78 }
79
80 public String getSourceName()
81 {
82 return original.getSourceName();
83 }
84
85 public String getName()
86 {
87 return original.getName();
88 }
89
90 public String getGroup()
91 {
92 return original.getGroup();
93 }
94
95 public StackTraceWriter getStackTraceWriter()
96 {
97 return original.getStackTraceWriter();
98 }
99
100 public String getMessage()
101 {
102 return original.getMessage();
103 }
104
105 public String getStackTrace( boolean trimStackTrace )
106 {
107 StackTraceWriter writer = original.getStackTraceWriter();
108 if ( writer == null )
109 {
110 return null;
111 }
112 return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
113 }
114
115 public String elapsedTimeAsString()
116 {
117 return elapsedTimeAsString( getElapsed() );
118 }
119
120 String elapsedTimeAsString( long runTime )
121 {
122 return numberFormat.format( (double) runTime / MS_PER_SEC );
123 }
124
125 public String getReportName()
126 {
127 final int i = getName().lastIndexOf( "(" );
128 return i > 0 ? getName().substring( 0, i ) : getName();
129 }
130
131 public String getReportName( String suffix )
132 {
133 return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName();
134 }
135
136 public String getOutput( boolean trimStackTrace )
137 {
138 StringBuilder buf = new StringBuilder();
139
140 buf.append( getElapsedTimeSummary() );
141
142 buf.append( " <<< " ).append( getReportEntryType().toString().toUpperCase() ).append( "!" ).append( NL );
143
144 buf.append( getStackTrace( trimStackTrace ) );
145
146 return buf.toString();
147 }
148
149 public String getElapsedTimeSummary()
150 {
151 StringBuilder reportContent = new StringBuilder();
152 reportContent.append( getName() );
153 reportContent.append( " Time elapsed: " );
154 reportContent.append( elapsedTimeAsString() );
155 reportContent.append( " sec" );
156
157 return reportContent.toString();
158 }
159
160 public boolean isErrorOrFailure()
161 {
162 ReportEntryType thisType = getReportEntryType();
163 return ReportEntryType.failure == thisType || ReportEntryType.error == thisType;
164 }
165
166 public boolean isSkipped()
167 {
168 return ReportEntryType.skipped == getReportEntryType();
169 }
170
171 public boolean isSucceeded()
172 {
173 return ReportEntryType.success == getReportEntryType();
174 }
175
176 public String getNameWithGroup()
177 {
178 return original.getNameWithGroup();
179 }
180 }