source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.6 KB
Line 
1/*
2 * Copyright 2000-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs.optional.junit;
19
20import java.util.Enumeration;
21import java.util.Hashtable;
22import java.util.Properties;
23import java.util.Vector;
24import org.apache.tools.ant.Project;
25
26/**
27 * <p> Run a single JUnit test.
28 *
29 * <p> The JUnit test is actually run by {@link JUnitTestRunner}.
30 * So read the doc comments for that class :)
31 *
32 * @since Ant 1.2
33 *
34 * @see JUnitTask
35 * @see JUnitTestRunner
36 */
37public class JUnitTest extends BaseTest implements Cloneable {
38
39 /** the name of the test case */
40 private String name = null;
41
42 /** the name of the result file */
43 private String outfile = null;
44
45 // @todo this is duplicating TestResult information. Only the time is not
46 // part of the result. So we'd better derive a new class from TestResult
47 // and deal with it. (SB)
48 private long runs, failures, errors;
49 private long runTime;
50
51 // Snapshot of the system properties
52 private Properties props = null;
53
54 public JUnitTest() {
55 }
56
57 public JUnitTest(String name) {
58 this.name = name;
59 }
60
61 public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure,
62 boolean filtertrace) {
63 this.name = name;
64 this.haltOnError = haltOnError;
65 this.haltOnFail = haltOnFailure;
66 this.filtertrace = filtertrace;
67 }
68
69 /**
70 * Set the name of the test class.
71 */
72 public void setName(String value) {
73 name = value;
74 }
75
76 /**
77 * Set the name of the output file.
78 */
79 public void setOutfile(String value) {
80 outfile = value;
81 }
82
83 /**
84 * Get the name of the test class.
85 */
86 public String getName() {
87 return name;
88 }
89
90 /**
91 * Get the name of the output file
92 *
93 * @return the name of the output file.
94 */
95 public String getOutfile() {
96 return outfile;
97 }
98
99 public void setCounts(long runs, long failures, long errors) {
100 this.runs = runs;
101 this.failures = failures;
102 this.errors = errors;
103 }
104
105 public void setRunTime(long runTime) {
106 this.runTime = runTime;
107 }
108
109 public long runCount() {
110 return runs;
111 }
112
113 public long failureCount() {
114 return failures;
115 }
116
117 public long errorCount() {
118 return errors;
119 }
120
121 public long getRunTime() {
122 return runTime;
123 }
124
125 public Properties getProperties() {
126 return props;
127 }
128
129 public void setProperties(Hashtable p) {
130 props = new Properties();
131 for (Enumeration e = p.keys(); e.hasMoreElements();) {
132 Object key = e.nextElement();
133 props.put(key, p.get(key));
134 }
135 }
136
137 public boolean shouldRun(Project p) {
138 if (ifProperty != null && p.getProperty(ifProperty) == null) {
139 return false;
140 } else if (unlessProperty != null
141 && p.getProperty(unlessProperty) != null) {
142 return false;
143 }
144
145 return true;
146 }
147
148 public FormatterElement[] getFormatters() {
149 FormatterElement[] fes = new FormatterElement[formatters.size()];
150 formatters.copyInto(fes);
151 return fes;
152 }
153
154 /**
155 * Convenient method to add formatters to a vector
156 */
157 void addFormattersTo(Vector v) {
158 final int count = formatters.size();
159 for (int i = 0; i < count; i++) {
160 v.addElement(formatters.elementAt(i));
161 }
162 }
163
164 /**
165 * @since Ant 1.5
166 */
167 public Object clone() {
168 try {
169 JUnitTest t = (JUnitTest) super.clone();
170 t.props = props == null ? null : (Properties) props.clone();
171 t.formatters = (Vector) formatters.clone();
172 return t;
173 } catch (CloneNotSupportedException e) {
174 // plain impossible
175 return this;
176 }
177 }
178}
Note: See TracBrowser for help on using the repository browser.