Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TestSet |
|
| 1.4482758620689655;1.448 |
1 | /* | |
2 | * The MIT License | |
3 | * | |
4 | * Copyright (c) 2010 tap4j team (see AUTHORS) | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | package org.tap4j.model; | |
25 | ||
26 | import java.io.Serializable; | |
27 | import java.util.LinkedList; | |
28 | import java.util.List; | |
29 | ||
30 | import org.tap4j.util.StatusValues; | |
31 | ||
32 | /** | |
33 | * A Test Set is the top element in a TAP File. It holds references to the | |
34 | * Header, Plan, List of Test Results and the rest of elements in TAP spec. | |
35 | * | |
36 | * @since 1.0 | |
37 | */ | |
38 | public class TestSet implements Serializable { | |
39 | ||
40 | /** | |
41 | * Serial Version UID. | |
42 | */ | |
43 | private static final long serialVersionUID = 114777557084672201L; | |
44 | ||
45 | /** | |
46 | * TAP Header. | |
47 | */ | |
48 | private Header header; | |
49 | ||
50 | /** | |
51 | * TAP Plan. | |
52 | */ | |
53 | private Plan plan; | |
54 | ||
55 | /** | |
56 | * List of TAP Lines. | |
57 | */ | |
58 | 0 | private List<TapElement> tapLines = new LinkedList<TapElement>(); |
59 | ||
60 | /** | |
61 | * List of Test Results. | |
62 | */ | |
63 | 0 | private List<TestResult> testResults = new LinkedList<TestResult>(); |
64 | ||
65 | /** | |
66 | * List of Bail Outs. | |
67 | */ | |
68 | 0 | private List<BailOut> bailOuts = new LinkedList<BailOut>(); |
69 | ||
70 | /** | |
71 | * List of comments. | |
72 | */ | |
73 | 0 | private List<Comment> comments = new LinkedList<Comment>(); |
74 | ||
75 | /** | |
76 | * TAP Footer. | |
77 | */ | |
78 | private Footer footer; | |
79 | ||
80 | /** | |
81 | * Default constructor. | |
82 | */ | |
83 | public TestSet() { | |
84 | 0 | super(); |
85 | 0 | } |
86 | ||
87 | /** | |
88 | * @return TAP Header. | |
89 | */ | |
90 | public Header getHeader() { | |
91 | 0 | return this.header; |
92 | } | |
93 | ||
94 | /** | |
95 | * @param header TAP Header. | |
96 | */ | |
97 | public void setHeader(Header header) { | |
98 | 0 | this.header = header; |
99 | 0 | } |
100 | ||
101 | /** | |
102 | * @return TAP Plan. | |
103 | */ | |
104 | public Plan getPlan() { | |
105 | 0 | return this.plan; |
106 | } | |
107 | ||
108 | /** | |
109 | * @param plan TAP Plan. | |
110 | */ | |
111 | public void setPlan(Plan plan) { | |
112 | 0 | this.plan = plan; |
113 | 0 | } |
114 | ||
115 | /** | |
116 | * @return List of TAP Lines. These lines may be either a TestResult or a | |
117 | * BailOut. | |
118 | */ | |
119 | public List<TapElement> getTapLines() { | |
120 | 0 | return tapLines; |
121 | } | |
122 | ||
123 | /** | |
124 | * @return List of Test Results. | |
125 | */ | |
126 | public List<TestResult> getTestResults() { | |
127 | 0 | return this.testResults; |
128 | } | |
129 | ||
130 | /** | |
131 | * @return Next test number. | |
132 | */ | |
133 | public int getNextTestNumber() { | |
134 | 0 | return this.testResults.size() + 1; |
135 | } | |
136 | ||
137 | /** | |
138 | * @return List of Bail Outs. | |
139 | */ | |
140 | public List<BailOut> getBailOuts() { | |
141 | 0 | return this.bailOuts; |
142 | } | |
143 | ||
144 | /** | |
145 | * @return List of Comments. | |
146 | */ | |
147 | public List<Comment> getComments() { | |
148 | 0 | return this.comments; |
149 | } | |
150 | ||
151 | /** | |
152 | * Adds a new TAP Line. | |
153 | * | |
154 | * @param tapLine TAP Line. | |
155 | * @return True if the TAP Line could be added into the list successfully. | |
156 | */ | |
157 | public boolean addTapLine(TapResult tapLine) { | |
158 | 0 | return this.tapLines.add(tapLine); |
159 | } | |
160 | ||
161 | /** | |
162 | * Adds a TestResult into the list of TestResults. If the TestResult Test | |
163 | * Number is null or less than or equals to zero it is changed to the next | |
164 | * Test Number in the sequence. | |
165 | * | |
166 | * @param testResult TAP TestResult. | |
167 | * @return Whether could add to TestResult list or not. | |
168 | */ | |
169 | public boolean addTestResult(TestResult testResult) { | |
170 | 0 | if (testResult.getTestNumber() == null |
171 | 0 | || testResult.getTestNumber() <= 0) { |
172 | 0 | testResult.setTestNumber(this.testResults.size() + 1); |
173 | } | |
174 | 0 | this.testResults.add(testResult); |
175 | 0 | return this.tapLines.add(testResult); |
176 | } | |
177 | ||
178 | /** | |
179 | * @param bailOut Bail Out. | |
180 | * @return Whether could add to BailOut list or not. | |
181 | */ | |
182 | public boolean addBailOut(BailOut bailOut) { | |
183 | 0 | this.bailOuts.add(bailOut); |
184 | 0 | return this.tapLines.add(bailOut); |
185 | } | |
186 | ||
187 | /** | |
188 | * @param comment Comment. Whether could add to Comment list or not. | |
189 | * @return True if could successfully add the comment. | |
190 | */ | |
191 | public boolean addComment(Comment comment) { | |
192 | 0 | comments.add(comment); |
193 | 0 | return tapLines.add(comment); |
194 | } | |
195 | ||
196 | /** | |
197 | * Removes a TAP Line from the list. | |
198 | * | |
199 | * @param tapLine TAP Line object. | |
200 | * @return True if could successfully remove the TAP Line from the list. | |
201 | */ | |
202 | protected boolean removeTapLine(TapResult tapLine) { | |
203 | 0 | return this.tapLines.remove(tapLine); |
204 | } | |
205 | ||
206 | /** | |
207 | * Removes a Test Result from the list. | |
208 | * | |
209 | * @param testResult Test Result. | |
210 | * @return True if could successfully remove the Test Result from the list. | |
211 | */ | |
212 | public boolean removeTestResult(TestResult testResult) { | |
213 | 0 | boolean flag = false; |
214 | 0 | if (this.tapLines.remove(testResult)) { |
215 | 0 | this.testResults.remove(testResult); |
216 | 0 | flag = true; |
217 | } | |
218 | 0 | return flag; |
219 | } | |
220 | ||
221 | /** | |
222 | * Removes a Bail Out from the list. | |
223 | * | |
224 | * @param bailOut Bail Out object. | |
225 | * @return True if could successfully remove the Bail Out from the list. | |
226 | */ | |
227 | public boolean removeBailOut(BailOut bailOut) { | |
228 | 0 | boolean flag = false; |
229 | 0 | if (this.tapLines.remove(bailOut)) { |
230 | 0 | this.bailOuts.remove(bailOut); |
231 | 0 | flag = true; |
232 | } | |
233 | 0 | return flag; |
234 | } | |
235 | ||
236 | /** | |
237 | * Removes a Comment from the list. | |
238 | * | |
239 | * @param comment Comment. | |
240 | * @return True if could successfully remove the Comment from the list. | |
241 | */ | |
242 | public boolean removeComment(Comment comment) { | |
243 | 0 | boolean flag = false; |
244 | 0 | if (this.tapLines.remove(comment)) { |
245 | 0 | this.comments.remove(comment); |
246 | 0 | flag = true; |
247 | } | |
248 | 0 | return flag; |
249 | } | |
250 | ||
251 | /** | |
252 | * @return Number of TAP Lines. It includes Test Results, Bail Outs and | |
253 | * Comments (the footer is not included). | |
254 | */ | |
255 | public int getNumberOfTapLines() { | |
256 | 0 | return this.tapLines.size(); |
257 | } | |
258 | ||
259 | /** | |
260 | * @return Number of Test Results. | |
261 | */ | |
262 | public int getNumberOfTestResults() { | |
263 | 0 | return this.testResults.size(); |
264 | } | |
265 | ||
266 | /** | |
267 | * @return Number of Bail Outs. | |
268 | */ | |
269 | public int getNumberOfBailOuts() { | |
270 | 0 | return this.bailOuts.size(); |
271 | } | |
272 | ||
273 | /** | |
274 | * @return Number of Comments. | |
275 | */ | |
276 | public int getNumberOfComments() { | |
277 | 0 | return this.comments.size(); |
278 | } | |
279 | ||
280 | /** | |
281 | * @return Footer | |
282 | */ | |
283 | public Footer getFooter() { | |
284 | 0 | return this.footer; |
285 | } | |
286 | ||
287 | /** | |
288 | * @param footer Footer | |
289 | */ | |
290 | public void setFooter(Footer footer) { | |
291 | 0 | this.footer = footer; |
292 | 0 | } |
293 | ||
294 | /** | |
295 | * @return <code>true</code> if it has any Bail Out statement, | |
296 | * <code>false</code> otherwise. | |
297 | */ | |
298 | public boolean hasBailOut() { | |
299 | 0 | boolean isBailOut = false; |
300 | ||
301 | 0 | for (TapElement tapLine : tapLines) { |
302 | 0 | if (tapLine instanceof BailOut) { |
303 | 0 | isBailOut = true; |
304 | 0 | break; |
305 | } | |
306 | 0 | } |
307 | ||
308 | 0 | return isBailOut; |
309 | } | |
310 | ||
311 | /** | |
312 | * @return <code>true</code> if it contains OK status, <code>false</code> | |
313 | * otherwise. | |
314 | */ | |
315 | public Boolean containsOk() { | |
316 | 0 | Boolean containsOk = false; |
317 | ||
318 | 0 | for (TestResult testResult : this.testResults) { |
319 | 0 | if (testResult.getStatus().equals(StatusValues.OK)) { |
320 | 0 | containsOk = true; |
321 | 0 | break; |
322 | } | |
323 | 0 | } |
324 | ||
325 | 0 | return containsOk; |
326 | } | |
327 | ||
328 | /** | |
329 | * @return <code>true</code> if it contains NOT OK status, | |
330 | * <code>false</code> otherwise. | |
331 | */ | |
332 | public Boolean containsNotOk() { | |
333 | 0 | Boolean containsNotOk = false; |
334 | ||
335 | 0 | for (TestResult testResult : this.testResults) { |
336 | 0 | if (testResult.getStatus().equals(StatusValues.NOT_OK)) { |
337 | 0 | containsNotOk = true; |
338 | 0 | break; |
339 | } | |
340 | 0 | } |
341 | ||
342 | 0 | return containsNotOk; |
343 | } | |
344 | ||
345 | /** | |
346 | * @return <code>true</code> if it contains BAIL OUT!, <code>false</code> | |
347 | * otherwise. | |
348 | */ | |
349 | public Boolean containsBailOut() { | |
350 | 0 | return this.bailOuts.size() > 0; |
351 | } | |
352 | ||
353 | /** | |
354 | * @param testNumber test result number. | |
355 | * @return Test Result with given number. | |
356 | */ | |
357 | public TestResult getTestResult(Integer testNumber) { | |
358 | 0 | TestResult foundTestResult = null; |
359 | 0 | for (TestResult testResult : this.testResults) { |
360 | 0 | if (testResult.getTestNumber().equals(testNumber)) { |
361 | 0 | foundTestResult = testResult; |
362 | 0 | break; |
363 | } | |
364 | 0 | } |
365 | 0 | return foundTestResult; |
366 | } | |
367 | ||
368 | } |