2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.junit3
;
18 import com
.intellij
.rt
.execution
.junit
.segments
.OutputObjectRegistry
;
19 import com
.intellij
.rt
.execution
.junit
.segments
.PoolOfDelimiters
;
20 import com
.intellij
.rt
.execution
.junit
.segments
.Packet
;
21 import junit
.framework
.Test
;
22 import junit
.framework
.TestSuite
;
24 import java
.util
.Enumeration
;
25 import java
.util
.Vector
;
27 public class TreeSender
{
28 private static void sendNode(Test test
, Packet packet
) {
29 Vector testCases
= getTestCasesOf(test
);
30 packet
.addObject(test
).addLong(testCases
.size());
31 for (int i
= 0; i
< testCases
.size(); i
++) {
32 Test nextTest
= (Test
)testCases
.get(i
);
33 sendNode(nextTest
, packet
);
37 private static Vector
getTestCasesOf(Test test
) {
38 Vector testCases
= new Vector();
39 if (test
instanceof TestRunnerUtil
.SuiteMethodWrapper
) {
40 test
= ((TestRunnerUtil
.SuiteMethodWrapper
)test
).getSuite();
42 if (test
instanceof TestSuite
) {
43 TestSuite testSuite
= (TestSuite
)test
;
45 for (Enumeration each
= testSuite
.tests(); each
.hasMoreElements();) {
46 Object childTest
= each
.nextElement();
47 if (childTest
instanceof TestSuite
&& !((TestSuite
)childTest
).tests().hasMoreElements()) continue;
48 testCases
.addElement(childTest
);
54 public static void sendSuite(OutputObjectRegistry registry
, Test suite
) {
55 Packet packet
= registry
.createPacket();
56 packet
.addString(PoolOfDelimiters
.TREE_PREFIX
);
57 sendNode(suite
, packet
);
58 packet
.addString("\n");