1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
34
35
36
37
38 public class TestSet implements Serializable {
39
40
41
42
43 private static final long serialVersionUID = 114777557084672201L;
44
45
46
47
48 private Header header;
49
50
51
52
53 private Plan plan;
54
55
56
57
58 private List<TapResult> tapLines = new LinkedList<TapResult>();
59
60
61
62
63 private List<TestResult> testResults = new LinkedList<TestResult>();
64
65
66
67
68 private List<BailOut> bailOuts = new LinkedList<BailOut>();
69
70
71
72
73 private List<Comment> comments = new LinkedList<Comment>();
74
75
76
77
78 private Footer footer;
79
80
81
82
83 public TestSet() {
84 super();
85 }
86
87
88
89
90 public Header getHeader() {
91 return this.header;
92 }
93
94
95
96
97 public void setHeader(Header header) {
98 this.header = header;
99 }
100
101
102
103
104 public Plan getPlan() {
105 return this.plan;
106 }
107
108
109
110
111 public void setPlan(Plan plan) {
112 this.plan = plan;
113 }
114
115
116
117
118
119 public List<TapResult> getTapLines() {
120 return this.tapLines;
121 }
122
123
124
125
126 public List<TestResult> getTestResults() {
127 return this.testResults;
128 }
129
130
131
132
133 public int getNextTestNumber() {
134 return (this.testResults.size() + 1);
135 }
136
137
138
139
140 public List<BailOut> getBailOuts() {
141 return this.bailOuts;
142 }
143
144
145
146
147 public List<Comment> getComments() {
148 return this.comments;
149 }
150
151
152
153
154
155
156
157 public boolean addTapLine(TapResult tapLine) {
158 return this.tapLines.add(tapLine);
159 }
160
161
162
163
164
165
166
167
168
169 public boolean addTestResult(TestResult testResult) {
170 if (testResult.getTestNumber() == null ||
171 testResult.getTestNumber() <= 0) {
172 testResult.setTestNumber(this.testResults.size() + 1);
173 }
174 this.testResults.add(testResult);
175 return this.tapLines.add(testResult);
176 }
177
178
179
180
181
182 public boolean addBailOut(BailOut bailOut) {
183 this.bailOuts.add(bailOut);
184 return this.tapLines.add(bailOut);
185 }
186
187
188
189
190 public boolean addComment(Comment comment) {
191 this.comments.add(comment);
192 return this.tapLines.add(comment);
193 }
194
195
196
197
198
199
200
201 protected boolean removeTapLine(TapResult tapLine) {
202 return this.tapLines.remove(tapLine);
203 }
204
205
206
207
208
209
210
211 public boolean removeTestResult(TestResult testResult) {
212 boolean flag = false;
213 if (this.tapLines.remove(testResult)) {
214 this.testResults.remove(testResult);
215 flag = true;
216 }
217 return flag;
218 }
219
220
221
222
223
224
225
226 public boolean removeBailOut(BailOut bailOut) {
227 boolean flag = false;
228 if (this.tapLines.remove(bailOut)) {
229 this.bailOuts.remove(bailOut);
230 flag = true;
231 }
232 return flag;
233 }
234
235
236
237
238
239
240
241 public boolean removeComment(Comment comment) {
242 boolean flag = false;
243 if (this.tapLines.remove(comment)) {
244 this.comments.remove(comment);
245 flag = true;
246 }
247 return flag;
248 }
249
250
251
252
253
254 public int getNumberOfTapLines() {
255 return this.tapLines.size();
256 }
257
258
259
260
261 public int getNumberOfTestResults() {
262 return this.testResults.size();
263 }
264
265
266
267
268 public int getNumberOfBailOuts() {
269 return this.bailOuts.size();
270 }
271
272
273
274
275 public int getNumberOfComments() {
276 return this.comments.size();
277 }
278
279
280
281
282 public Footer getFooter() {
283 return this.footer;
284 }
285
286
287
288
289 public void setFooter(Footer footer) {
290 this.footer = footer;
291 }
292
293
294
295
296 public boolean hasBailOut() {
297 boolean isBailOut = false;
298
299 for (TapResult tapLine : tapLines) {
300 if (tapLine instanceof BailOut) {
301 isBailOut = true;
302 break;
303 }
304 }
305
306 return isBailOut;
307 }
308
309
310
311
312
313 public Boolean containsOk() {
314 Boolean containsOk = false;
315
316 for (TestResult testResult : this.testResults) {
317 if (testResult.getStatus().equals(StatusValues.OK)) {
318 containsOk = true;
319 break;
320 }
321 }
322
323 return containsOk;
324 }
325
326
327
328
329
330 public Boolean containsNotOk() {
331 Boolean containsNotOk = false;
332
333 for (TestResult testResult : this.testResults) {
334 if (testResult.getStatus().equals(StatusValues.NOT_OK)) {
335 containsNotOk = true;
336 break;
337 }
338 }
339
340 return containsNotOk;
341 }
342
343
344
345
346
347 public Boolean containsBailOut() {
348 return this.bailOuts.size() > 0;
349 }
350
351
352
353
354
355 public TestResult getTestResult(Integer testNumber) {
356 TestResult foundTestResult = null;
357
358 for (TestResult testResult : this.testResults) {
359 if (testResult.getTestNumber() != null &&
360 testResult.getTestNumber().equals(testNumber)) {
361 foundTestResult = testResult;
362 break;
363 }
364 }
365
366 return foundTestResult;
367 }
368
369 }