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