KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > test > DefaultTestSuite


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.test;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 /**
24  * Default implementation of the <tt>TestSuite</tt> interface.
25  *
26  * @author <a HREF="mailto:vhardy@apache.lorg">Vincent Hardy</a>
27  * @version $Id: DefaultTestSuite.java,v 1.7 2004/08/18 07:16:56 vhardy Exp $
28  */

29 public class DefaultTestSuite extends AbstractTest implements TestSuite {
30     /**
31      * This Test's name
32      */

33     private String JavaDoc name = null;
34
35     /**
36      * Stores the list of child tests
37      */

38     protected Vector JavaDoc tests = new Vector JavaDoc();
39
40     /**
41      * Adds a <tt>Test</tt> to the suite
42      */

43     public void addTest(Test test){
44         if(test == null){
45             throw new IllegalArgumentException JavaDoc();
46         }
47
48         test.setParent(this);
49         tests.addElement(test);
50     }
51
52     /**
53      * Removes a <tt>Test</tt> from the suite.
54      */

55     public void removeTest(Test test){
56         tests.remove(test);
57     }
58
59     /**
60      * Runs the tests and returns a report
61      */

62     public TestReport runImpl(){
63         Iterator JavaDoc iter = tests.iterator();
64
65         DefaultTestSuiteReport report
66             = new DefaultTestSuiteReport(this);
67
68         while(iter.hasNext()){
69             Test t = (Test)iter.next();
70             System.err.println("Running " + t.getName());
71             TestReport tr = t.run();
72             if (tr == null){
73                 System.out.println("ERROR" + t.getId() + " returned a null report");
74             }
75             report.addReport(tr);
76         }
77
78         return report;
79     }
80
81     public String JavaDoc getName(){
82         if(name != null){
83             return name;
84         }
85
86         String JavaDoc id = getId();
87         if(id != null && !"".equals(id)){
88             return id;
89         }
90
91         return this.getClass().getName();
92     }
93
94     public void setName(String JavaDoc name){
95         if(name == null && !"".equals(name)){
96             throw new IllegalArgumentException JavaDoc();
97         }
98
99         this.name = name;
100     }
101
102     public Test[] getChildrenTests(){
103         Test[] children = new Test[tests.size()];
104         tests.copyInto(children);
105         return children;
106     }
107
108     /**
109      * Returns the number of child tests
110      */

111     public int getChildrenCount(){
112         return tests.size();
113     }
114
115 }
116
Popular Tags