1 // Tags: not-a-test |
|
2 // Copyright (C) 2004 by Object Refinery Limited |
|
3 // Written by David Gilbert (david.gilbert@object-refinery.com) |
|
4 // Modified by Fabien DUMINY (fduminy@jnode.org) |
|
5 |
|
6 // This file is part of Mauve Reporter. |
|
7 |
|
8 // Mauve Reporter is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2 of the License, or |
|
11 // (at your option) any later version. |
|
12 |
|
13 // Mauve Reporter is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve Reporter; if not, write to the Free Software |
|
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 package gnu.testlet.runner; |
|
22 |
|
23 import java.util.ArrayList; |
|
24 import java.util.Collections; |
|
25 import java.util.Iterator; |
|
26 import java.util.List; |
|
27 |
|
28 /** |
|
29 * Represents the result of running all the tests for a particular package. |
|
30 */ |
|
31 public class PackageResult implements Comparable, Result { |
|
32 |
|
33 /** The name of the package. */ |
|
34 private String name; |
|
35 |
|
36 /** A list containing results for each class in the package. */ |
|
37 private List classResults; |
|
38 private boolean sorted=true; |
|
39 |
|
40 /** |
|
41 * Creates a new result, initially empty. |
|
42 * |
|
43 * @param name the class name. |
|
44 */ |
|
45 PackageResult(String name) { |
|
46 this.name = name; |
|
47 classResults = new ArrayList(); |
|
48 } |
|
49 |
|
50 /** |
|
51 * Returns the package name. |
|
52 * |
|
53 * @return The package name. |
|
54 */ |
|
55 public String getName() { |
|
56 return name; |
|
57 } |
|
58 |
|
59 /** |
|
60 * Sets the package name. |
|
61 * |
|
62 * @param name the name. |
|
63 */ |
|
64 void setName(String name) { |
|
65 this.name = name; |
|
66 } |
|
67 |
|
68 /** |
|
69 * Adds a class result. |
|
70 * |
|
71 * @param result the test result. |
|
72 */ |
|
73 public void add(ClassResult result) { |
|
74 classResults.add(result); |
|
75 sorted = false; |
|
76 } |
|
77 |
|
78 /** |
|
79 * Returns an iterator that provides access to the class results. |
|
80 * |
|
81 * @return An iterator. |
|
82 */ |
|
83 public Iterator getClassIterator() { |
|
84 sortClasses(); |
|
85 return classResults.iterator(); |
|
86 } |
|
87 |
|
88 /** |
|
89 * Returns the class result for the named class. |
|
90 * |
|
91 * @param name the class name. |
|
92 * |
|
93 * @return A class result. |
|
94 */ |
|
95 public ClassResult getClassResult(String name) { |
|
96 sortClasses(); |
|
97 for (int i = 0; i < classResults.size(); i++) { |
|
98 ClassResult cr = (ClassResult) classResults.get(i); |
|
99 if (cr.getName().equals(name)) |
|
100 return cr; |
|
101 } |
|
102 return null; |
|
103 } |
|
104 |
|
105 /** |
|
106 * Returns the total number of checks performed for this package. |
|
107 * |
|
108 * @return The check count. |
|
109 */ |
|
110 public int getCheckCount() { |
|
111 int result = 0; |
|
112 Iterator iterator = getClassIterator(); |
|
113 while (iterator.hasNext()) { |
|
114 ClassResult cr = (ClassResult) iterator.next(); |
|
115 result = result + cr.getCheckCount(); |
|
116 } |
|
117 return result; |
|
118 } |
|
119 |
|
120 /** |
|
121 * Returns the number of checks with the specified status. |
|
122 * |
|
123 * @param passed the check status. |
|
124 * |
|
125 * @return The number of checks passed or failed. |
|
126 */ |
|
127 public int getCheckCount(boolean passed) { |
|
128 int result = 0; |
|
129 Iterator iterator = getClassIterator(); |
|
130 while (iterator.hasNext()) { |
|
131 ClassResult cr = (ClassResult) iterator.next(); |
|
132 result = result + cr.getCheckCount(passed); |
|
133 } |
|
134 return result; |
|
135 } |
|
136 |
|
137 /** |
|
138 * Returns the index of the specified result. |
|
139 * |
|
140 * @param result the class result. |
|
141 * |
|
142 * @return The index. |
|
143 */ |
|
144 public int indexOf(ClassResult result) { |
|
145 sortClasses(); |
|
146 return classResults.indexOf(result); |
|
147 } |
|
148 |
|
149 public int compareTo(Object obj) { |
|
150 PackageResult that = (PackageResult) obj; |
|
151 return getName().compareTo(that.getName()); |
|
152 } |
|
153 |
|
154 /** |
|
155 * Sorts the class results. |
|
156 */ |
|
157 private void sortClasses() { |
|
158 if(sorted) return; |
|
159 Collections.sort(classResults); |
|
160 sorted = true; |
|
161 } |
|
162 } |
|