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
25
26
27
28 public class WrappedReportEntry
29 implements ReportEntry
30 {
31 private static final String NL = System.getProperty( "line.separator" );
32
33 private final ReportEntry original;
34
35 private final ReportEntryType reportEntryType;
36
37 private final Integer elapsed;
38
39 private final Utf8RecodingDeferredFileOutputStream stdout;
40
41 private final Utf8RecodingDeferredFileOutputStream stdErr;
42
43 public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed,
44 Utf8RecodingDeferredFileOutputStream stdout,
45 Utf8RecodingDeferredFileOutputStream stdErr )
46 {
47 this.original = original;
48 this.reportEntryType = reportEntryType;
49 this.elapsed = estimatedElapsed;
50 this.stdout = stdout;
51 this.stdErr = stdErr;
52 }
53
54 public Integer getElapsed()
55 {
56 return elapsed;
57 }
58
59 public ReportEntryType getReportEntryType()
60 {
61 return reportEntryType;
62 }
63
64 public Utf8RecodingDeferredFileOutputStream getStdout()
65 {
66 return stdout;
67 }
68
69 public Utf8RecodingDeferredFileOutputStream getStdErr()
70 {
71 return stdErr;
72 }
73
74 public String getSourceName()
75 {
76 return original.getSourceName();
77 }
78
79 public String getName()
80 {
81 return original.getName();
82 }
83
84 public String getClassMethodName()
85 {
86 return getSourceName() + "." + 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 w = original.getStackTraceWriter();
107 return w == null ? null : ( trimStackTrace ? w.writeTrimmedTraceToString() : w.writeTraceToString() );
108 }
109
110 public String elapsedTimeAsString()
111 {
112 return elapsedTimeAsString( getElapsed() );
113 }
114
115 String elapsedTimeAsString( long runTime )
116 {
117 return ReporterUtils.formatElapsedTime( runTime );
118 }
119
120 public String getReportName()
121 {
122 final int i = getName().lastIndexOf( "(" );
123 return i > 0 ? getName().substring( 0, i ) : getName();
124 }
125
126 public String getReportName( String suffix )
127 {
128 return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName();
129 }
130
131 public String getOutput( boolean trimStackTrace )
132 {
133 return getElapsedTimeSummary() + " <<< " + getReportEntryType().toString().toUpperCase() + "!" + NL
134 + getStackTrace( trimStackTrace );
135 }
136
137 public String getElapsedTimeVerbose()
138 {
139 return "Time elapsed: " + elapsedTimeAsString() + " sec";
140 }
141
142 public String getElapsedTimeSummary()
143 {
144 return getName() + " " + getElapsedTimeVerbose();
145 }
146
147 public boolean isErrorOrFailure()
148 {
149 ReportEntryType thisType = getReportEntryType();
150 return ReportEntryType.FAILURE == thisType || ReportEntryType.ERROR == thisType;
151 }
152
153 public boolean isSkipped()
154 {
155 return ReportEntryType.SKIPPED == getReportEntryType();
156 }
157
158 public boolean isSucceeded()
159 {
160 return ReportEntryType.SUCCESS == getReportEntryType();
161 }
162
163 public String getNameWithGroup()
164 {
165 return original.getNameWithGroup();
166 }
167 }