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,
52 Utf8RecodingDeferredFileOutputStream stdErr )
53 {
54 this.original = original;
55 this.reportEntryType = reportEntryType;
56 this.elapsed = estimatedElapsed;
57 this.stdout = stdout;
58 this.stdErr = stdErr;
59 }
60
61 public Integer getElapsed()
62 {
63 return elapsed;
64 }
65
66 public ReportEntryType getReportEntryType()
67 {
68 return reportEntryType;
69 }
70
71 public Utf8RecodingDeferredFileOutputStream getStdout()
72 {
73 return stdout;
74 }
75
76 public Utf8RecodingDeferredFileOutputStream getStdErr()
77 {
78 return stdErr;
79 }
80
81 public String getSourceName()
82 {
83 return original.getSourceName();
84 }
85
86 public String getName()
87 {
88 return original.getName();
89 }
90
91 public String getClassMethodName()
92 {
93 return getSourceName() + "." + getName();
94 }
95
96 public String getGroup()
97 {
98 return original.getGroup();
99 }
100
101 public StackTraceWriter getStackTraceWriter()
102 {
103 return original.getStackTraceWriter();
104 }
105
106 public String getMessage()
107 {
108 return original.getMessage();
109 }
110
111 public String getStackTrace( boolean trimStackTrace )
112 {
113 StackTraceWriter writer = original.getStackTraceWriter();
114 if ( writer == null )
115 {
116 return null;
117 }
118 return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
119 }
120
121 public String elapsedTimeAsString()
122 {
123 return elapsedTimeAsString( getElapsed() );
124 }
125
126 String elapsedTimeAsString( long runTime )
127 {
128 return numberFormat.format( (double) runTime / MS_PER_SEC );
129 }
130
131 public String getReportName()
132 {
133 final int i = getName().lastIndexOf( "(" );
134 return i > 0 ? getName().substring( 0, i ) : getName();
135 }
136
137 public String getReportName( String suffix )
138 {
139 return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName();
140 }
141
142 public String getOutput( boolean trimStackTrace )
143 {
144 StringBuilder buf = new StringBuilder();
145
146 buf.append( getElapsedTimeSummary() );
147
148 buf.append( " <<< " ).append( getReportEntryType().toString().toUpperCase() ).append( "!" ).append( NL );
149
150 buf.append( getStackTrace( trimStackTrace ) );
151
152 return buf.toString();
153 }
154
155 public String getElapsedTimeSummary()
156 {
157 StringBuilder reportContent = new StringBuilder();
158 reportContent.append( getName() );
159 reportContent.append( " Time elapsed: " );
160 reportContent.append( elapsedTimeAsString() );
161 reportContent.append( " sec" );
162
163 return reportContent.toString();
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 public String getNameWithGroup()
183 {
184 return original.getNameWithGroup();
185 }
186 }