1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.woopi.ant.taskdefs.junit;
19 import java.util.Enumeration;
20 import java.util.Hashtable;
21 import java.util.Properties;
22 import java.util.Vector;
23 import org.apache.tools.ant.Project;
24
25 /***
26 * <p> Run a single JUnit test.
27 *
28 * <p> The JUnit test is actually run by {@link JUnitTestRunner}.
29 * So read the doc comments for that class :)
30 *
31 * @since Ant 1.2
32 *
33 * @see JUnitTask
34 * @see JUnitTestRunner
35 */
36 public class JUnitTest extends BaseTest implements Cloneable {
37
38 /*** the name of the test case */
39 private String name = null;
40
41 /*** the name of the result file */
42 private String outfile = null;
43
44
45
46
47 private long runs, failures, errors;
48 private long runTime;
49
50
51 private Properties props = null;
52
53 public JUnitTest() {
54 }
55
56 public JUnitTest(String name) {
57 this.name = name;
58 }
59
60 public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure,
61 boolean filtertrace) {
62 this.name = name;
63 this.haltOnError = haltOnError;
64 this.haltOnFail = haltOnFailure;
65 this.filtertrace = filtertrace;
66 }
67
68 /***
69 * Set the name of the test class.
70 */
71 public void setName(String value) {
72 name = value;
73 }
74
75 /***
76 * Set the name of the output file.
77 */
78 public void setOutfile(String value) {
79 outfile = value;
80 }
81
82 /***
83 * Get the name of the test class.
84 */
85 public String getName() {
86 return name;
87 }
88
89 /***
90 * Get the name of the output file
91 *
92 * @return the name of the output file.
93 */
94 public String getOutfile() {
95 return outfile;
96 }
97
98 public void setCounts(long runs, long failures, long errors) {
99 this.runs = runs;
100 this.failures = failures;
101 this.errors = errors;
102 }
103
104 public void setRunTime(long runTime) {
105 this.runTime = runTime;
106 }
107
108 public long runCount() {
109 return runs;
110 }
111
112 public long failureCount() {
113 return failures;
114 }
115
116 public long errorCount() {
117 return errors;
118 }
119
120 public long getRunTime() {
121 return runTime;
122 }
123
124 public Properties getProperties() {
125 return props;
126 }
127
128 public void setProperties(Hashtable p) {
129 props = new Properties();
130 for (Enumeration e = p.keys(); e.hasMoreElements();) {
131 Object key = e.nextElement();
132 props.put(key, p.get(key));
133 }
134 }
135
136 public boolean shouldRun(Project p) {
137 if (ifProperty != null && p.getProperty(ifProperty) == null) {
138 return false;
139 } else if (unlessProperty != null
140 && p.getProperty(unlessProperty) != null) {
141 return false;
142 }
143
144 return true;
145 }
146
147 public FormatterElement[] getFormatters() {
148 FormatterElement[] fes = new FormatterElement[formatters.size()];
149 formatters.copyInto(fes);
150 return fes;
151 }
152
153 /***
154 * Convenient method to add formatters to a vector
155 */
156 void addFormattersTo(Vector v) {
157 final int count = formatters.size();
158 for (int i = 0; i < count; i++) {
159 v.addElement(formatters.elementAt(i));
160 }
161 }
162
163 /***
164 * @since Ant 1.5
165 */
166 public Object clone() {
167 try {
168 JUnitTest t = (JUnitTest) super.clone();
169 t.props = props == null ? null : (Properties) props.clone();
170 t.formatters = (Vector) formatters.clone();
171 return t;
172 } catch (CloneNotSupportedException e) {
173
174 return this;
175 }
176 }
177 }