View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  public final class ReportTestCase {
28      private String fullClassName;
29  
30      private String className;
31  
32      private String fullName;
33  
34      private String name;
35  
36      private float time;
37  
38      private String failureMessage;
39  
40      private String failureType;
41  
42      private String failureErrorLine;
43  
44      private String failureDetail;
45  
46      private boolean hasFailure;
47  
48      private boolean hasError;
49  
50      private boolean hasSkipped;
51  
52      private List<FlakyError> flakyErrors = new ArrayList<>();
53  
54      private List<FlakyFailure> flakyFailures = new ArrayList<>();
55  
56      public String getName() {
57          return name;
58      }
59  
60      public ReportTestCase setName(String name) {
61          this.name = name;
62          return this;
63      }
64  
65      public String getFullClassName() {
66          return fullClassName;
67      }
68  
69      public ReportTestCase setFullClassName(String name) {
70          fullClassName = name;
71          return this;
72      }
73  
74      public String getClassName() {
75          return className;
76      }
77  
78      public ReportTestCase setClassName(String name) {
79          className = name;
80          return this;
81      }
82  
83      public float getTime() {
84          return time;
85      }
86  
87      public ReportTestCase setTime(float time) {
88          this.time = time;
89          return this;
90      }
91  
92      public String getFullName() {
93          return fullName;
94      }
95  
96      public ReportTestCase setFullName(String fullName) {
97          this.fullName = fullName;
98          return this;
99      }
100 
101     public String getFailureMessage() {
102         return failureMessage;
103     }
104 
105     private ReportTestCase setFailureMessage(String failureMessage) {
106         this.failureMessage = failureMessage;
107         return this;
108     }
109 
110     public String getFailureType() {
111         return failureType;
112     }
113 
114     public String getFailureErrorLine() {
115         return failureErrorLine;
116     }
117 
118     public ReportTestCase setFailureErrorLine(String failureErrorLine) {
119         this.failureErrorLine = failureErrorLine;
120         return this;
121     }
122 
123     public String getFailureDetail() {
124         return failureDetail;
125     }
126 
127     public ReportTestCase setFailureDetail(String failureDetail) {
128         this.failureDetail = failureDetail;
129         return this;
130     }
131 
132     public ReportTestCase setFailure(String message, String type) {
133         hasFailure = isNotBlank(type);
134         hasError = false;
135         hasSkipped = false;
136         return setFailureMessage(message).setFailureType(type);
137     }
138 
139     public ReportTestCase setError(String message, String type) {
140         hasFailure = false;
141         hasError = isNotBlank(type);
142         hasSkipped = false;
143         return setFailureMessage(message).setFailureType(type);
144     }
145 
146     public ReportTestCase setSkipped(String message) {
147         hasFailure = false;
148         hasError = false;
149         hasSkipped = isNotBlank(message);
150         return setFailureMessage(message).setFailureType("skipped");
151     }
152 
153     public boolean isSuccessful() {
154         return !hasFailure() && !hasError() && !hasSkipped();
155     }
156 
157     public boolean hasFailure() {
158         return hasFailure;
159     }
160 
161     public boolean hasError() {
162         return hasError;
163     }
164 
165     public boolean hasSkipped() {
166         return hasSkipped;
167     }
168 
169     public boolean hasFlakes() {
170         return !flakyErrors.isEmpty() || !flakyFailures.isEmpty();
171     }
172 
173     public void addFlakyError(FlakyError flakyError) {
174         flakyErrors.add(flakyError);
175     }
176 
177     public List<FlakyError> getFlakyErrors() {
178         return Collections.unmodifiableList(flakyErrors);
179     }
180 
181     public void addFlakyFailure(FlakyFailure flakyFailure) {
182         flakyFailures.add(flakyFailure);
183     }
184 
185     public List<FlakyFailure> getFlakyFailures() {
186         return Collections.unmodifiableList(flakyFailures);
187     }
188 
189     /**
190      * {@inheritDoc}
191      */
192     @Override
193     public String toString() {
194         return fullName;
195     }
196 
197     private ReportTestCase setFailureType(String failureType) {
198         this.failureType = failureType;
199         return this;
200     }
201 
202     public static class FlakyFailure {
203 
204         private String message;
205 
206         private String type;
207 
208         private String stackTrace;
209 
210         FlakyFailure(String message, String type) {
211             this.message = message;
212             this.type = type;
213         }
214 
215         public String getMessage() {
216             return message;
217         }
218 
219         public String getType() {
220             return type;
221         }
222 
223         public void setStackTrace(String stackTrace) {
224             this.stackTrace = stackTrace;
225         }
226 
227         public String getStackTrace() {
228             return stackTrace;
229         }
230     }
231 
232     public static class FlakyError {
233 
234         private String message;
235 
236         private String type;
237 
238         private String stackTrace;
239 
240         FlakyError(String message, String type) {
241             this.message = message;
242             this.type = type;
243         }
244 
245         public String getMessage() {
246             return message;
247         }
248 
249         public String getType() {
250             return type;
251         }
252 
253         public void setStackTrace(String stackTrace) {
254             this.stackTrace = stackTrace;
255         }
256 
257         public String getStackTrace() {
258             return stackTrace;
259         }
260     }
261 }