Refactory: removed unnecessary imports.
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / testpool / TestPool.java
1 /*************************************************************************
2  * @author Ali Echihabi (ali_echihabi@ieee.org, ali.echihabi@souss.ca)
3  *
4  * Plugin for PHP unit Testing.
5  * www.phpeclipse.de
6  * 
7  *************************************************************************/
8
9 package net.sourceforge.phpeclipse.phpunit.testpool;
10
11 import java.util.HashMap;
12
13 public class TestPool {
14
15         // private TestSuite currentParentTestSuite;
16         private HashMap tests;
17
18         private TestSuite root;
19
20         private TestSuite currentTestSuite;
21
22         /**
23          * 
24          */
25         public TestPool(String rootTitle) {
26
27                 tests = new HashMap();
28                 root = null;
29                 currentTestSuite = root;
30
31         }
32
33         /**
34          * @param test
35          */
36         public void addTest(TestCase test) {
37
38                 tests.put(test.getTestID(), test);
39
40                 currentTestSuite.addTestCase(test);
41
42                 // if we run all tests. then this is the end of this test suite.
43                 if (currentTestSuite != root && currentTestSuite.isFinished()) {
44
45                         currentTestSuite = currentTestSuite.getParent();
46
47                 }
48
49         }
50
51         /**
52          * @param suite
53          * @param numTestsRunSinceStartOfTestSuite
54          */
55         public void addTestSuite(TestSuite suite) {
56
57                 if (root == null) {
58                         root = suite;
59                 } else {
60
61                         // add as sibling
62                         currentTestSuite.addTestSuite(suite);
63                         suite.setParent(currentTestSuite);
64
65                 }
66
67                 currentTestSuite = suite;
68         }
69
70         /**
71          * @return
72          */
73         public TestSuite getRoot() {
74
75                 return root;
76         }
77
78         /**
79          * @param r
80          */
81         public void setRoot(TestSuite r) {
82                 this.root = r;
83         }
84
85         /**
86          * @param testID
87          * @return
88          */
89         public TestCase getTest(String testID) {
90
91                 return (TestCase) tests.get(testID);
92         }
93
94         public String toString() {
95
96                 String string = "";
97
98                 //TestSuite node = root;
99
100                 string = root.toString();
101
102                 return string;
103
104         }
105
106         public int getNumTestsOverall() {
107
108                 int total = root.getNumTestCasesExpected();
109                 System.out.println("total: " + total);
110                 return total;
111
112         }
113
114         public int getNumTestsRun() {
115
116                 return tests.size();
117
118         }
119
120         public int getNumFailures() {
121
122                 int total = 0;
123
124                 // Iterator i = tests.keySet().iterator();
125                 // String key = "";
126                 // while (i.hasNext()) {
127                 //                      
128                 //                      
129                 // key = (String) i.next();
130                 // TestCase element = (TestCase) tests.get(key);
131                 //                      
132                 //                      
133                 // if(element.isFailure())
134                 // total++;
135                 //                      
136                 // }
137
138                 return total;
139         }
140
141         public int getNumErrors() {
142
143                 int total = 0;
144
145                 // Iterator i = tests.keySet().iterator();
146                 // String key = "";
147                 // while (i.hasNext()) {
148                 //                      
149                 //                      
150                 // key = (String) i.next();
151                 // TestCase element = (TestCase) tests.get(key);
152                 //                                              
153                 // if(element.isError())
154                 // total++;
155                 //                      
156                 // }
157
158                 return total;
159
160         }
161
162 }