001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.test;
020:
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.ArrayList;
024:
025: /**
026: * Default implementation of the <tt>TestSuite</tt> interface.
027: *
028: * @author <a href="mailto:vhardy@apache.lorg">Vincent Hardy</a>
029: * @version $Id: DefaultTestSuite.java 482118 2006-12-04 09:52:54Z dvholten $
030: */
031: public class DefaultTestSuite extends AbstractTest implements TestSuite {
032: /**
033: * This Test's name
034: */
035: private String name = null;
036:
037: /**
038: * Stores the list of child tests
039: */
040: protected List tests = new ArrayList();
041:
042: /**
043: * Adds a <tt>Test</tt> to the suite
044: */
045: public void addTest(Test test) {
046: if (test == null) {
047: throw new IllegalArgumentException();
048: }
049:
050: test.setParent(this );
051: tests.add(test);
052: }
053:
054: /**
055: * Removes a <tt>Test</tt> from the suite.
056: */
057: public void removeTest(Test test) {
058: tests.remove(test);
059: }
060:
061: /**
062: * Runs the tests and returns a report
063: */
064: public TestReport runImpl() {
065: Iterator iter = tests.iterator();
066:
067: DefaultTestSuiteReport report = new DefaultTestSuiteReport(this );
068:
069: while (iter.hasNext()) {
070: Test t = (Test) iter.next();
071: System.err.println("Running " + t.getName());
072: TestReport tr = t.run();
073: if (tr == null) {
074: System.out.println("ERROR" + t.getId()
075: + " returned a null report");
076: }
077: report.addReport(tr);
078: }
079:
080: return report;
081: }
082:
083: public String getName() {
084: if (name != null) {
085: return name;
086: }
087:
088: String id = getId();
089: if (id != null && !"".equals(id)) {
090: return id;
091: }
092:
093: return this .getClass().getName();
094: }
095:
096: public void setName(String name) {
097: if (name == null && !"".equals(name)) { // ?? logic ??
098: throw new IllegalArgumentException();
099: }
100:
101: this .name = name;
102: }
103:
104: public Test[] getChildrenTests() {
105: Test[] children = new Test[tests.size()];
106: tests.toArray(children);
107: return children;
108: }
109:
110: /**
111: * Returns the number of child tests
112: */
113: public int getChildrenCount() {
114: return tests.size();
115: }
116:
117: }
|