1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.surefire.report;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25 import static org.apache.maven.shared.utils.StringUtils.isNotBlank;
26
27
28
29
30 public final class ReportTestCase {
31 private String fullClassName;
32
33 private String className;
34
35 private String fullName;
36
37 private String name;
38
39 private float time;
40
41 private String failureMessage;
42
43 private String failureType;
44
45 private String failureErrorLine;
46
47 private String failureDetail;
48
49 private boolean hasFailure;
50
51 private boolean hasError;
52
53 private boolean hasSkipped;
54
55 private List<FlakyError> flakyErrors = new ArrayList<>();
56
57 private List<FlakyFailure> flakyFailures = new ArrayList<>();
58
59 public String getName() {
60 return name;
61 }
62
63 public ReportTestCase setName(String name) {
64 this.name = name;
65 return this;
66 }
67
68 public String getFullClassName() {
69 return fullClassName;
70 }
71
72 public ReportTestCase setFullClassName(String name) {
73 fullClassName = name;
74 return this;
75 }
76
77 public String getClassName() {
78 return className;
79 }
80
81 public ReportTestCase setClassName(String name) {
82 className = name;
83 return this;
84 }
85
86 public float getTime() {
87 return time;
88 }
89
90 public ReportTestCase setTime(float time) {
91 this.time = time;
92 return this;
93 }
94
95 public String getFullName() {
96 return fullName;
97 }
98
99 public ReportTestCase setFullName(String fullName) {
100 this.fullName = fullName;
101 return this;
102 }
103
104 public String getFailureMessage() {
105 return failureMessage;
106 }
107
108 private ReportTestCase setFailureMessage(String failureMessage) {
109 this.failureMessage = failureMessage;
110 return this;
111 }
112
113 public String getFailureType() {
114 return failureType;
115 }
116
117 public String getFailureErrorLine() {
118 return failureErrorLine;
119 }
120
121 public ReportTestCase setFailureErrorLine(String failureErrorLine) {
122 this.failureErrorLine = failureErrorLine;
123 return this;
124 }
125
126 public String getFailureDetail() {
127 return failureDetail;
128 }
129
130 public ReportTestCase setFailureDetail(String failureDetail) {
131 this.failureDetail = failureDetail;
132 return this;
133 }
134
135 public ReportTestCase setFailure(String message, String type) {
136 hasFailure = isNotBlank(type);
137 hasError = false;
138 hasSkipped = false;
139 return setFailureMessage(message).setFailureType(type);
140 }
141
142 public ReportTestCase setError(String message, String type) {
143 hasFailure = false;
144 hasError = isNotBlank(type);
145 hasSkipped = false;
146 return setFailureMessage(message).setFailureType(type);
147 }
148
149 public ReportTestCase setSkipped(String message) {
150 hasFailure = false;
151 hasError = false;
152 hasSkipped = isNotBlank(message);
153 return setFailureMessage(message).setFailureType("skipped");
154 }
155
156 public boolean isSuccessful() {
157 return !hasFailure() && !hasError() && !hasSkipped();
158 }
159
160 public boolean hasFailure() {
161 return hasFailure;
162 }
163
164 public boolean hasError() {
165 return hasError;
166 }
167
168 public boolean hasSkipped() {
169 return hasSkipped;
170 }
171
172 public boolean hasFlakes() {
173 return !flakyErrors.isEmpty() || !flakyFailures.isEmpty();
174 }
175
176 public void addFlakyError(FlakyError flakyError) {
177 flakyErrors.add(flakyError);
178 }
179
180 public List<FlakyError> getFlakyErrors() {
181 return Collections.unmodifiableList(flakyErrors);
182 }
183
184 public void addFlakyFailure(FlakyFailure flakyFailure) {
185 flakyFailures.add(flakyFailure);
186 }
187
188 public List<FlakyFailure> getFlakyFailures() {
189 return Collections.unmodifiableList(flakyFailures);
190 }
191
192
193
194
195 @Override
196 public String toString() {
197 return fullName;
198 }
199
200 private ReportTestCase setFailureType(String failureType) {
201 this.failureType = failureType;
202 return this;
203 }
204
205 public static class FlakyFailure {
206
207 private String message;
208
209 private String type;
210
211 private String stackTrace;
212
213 FlakyFailure(String message, String type) {
214 this.message = message;
215 this.type = type;
216 }
217
218 public String getMessage() {
219 return message;
220 }
221
222 public String getType() {
223 return type;
224 }
225
226 public void setStackTrace(String stackTrace) {
227 this.stackTrace = stackTrace;
228 }
229
230 public String getStackTrace() {
231 return stackTrace;
232 }
233 }
234
235 public static class FlakyError {
236
237 private String message;
238
239 private String type;
240
241 private String stackTrace;
242
243 FlakyError(String message, String type) {
244 this.message = message;
245 this.type = type;
246 }
247
248 public String getMessage() {
249 return message;
250 }
251
252 public String getType() {
253 return type;
254 }
255
256 public void setStackTrace(String stackTrace) {
257 this.stackTrace = stackTrace;
258 }
259
260 public String getStackTrace() {
261 return stackTrace;
262 }
263 }
264 }