01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08:
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.test.xslt.lib.sequential;
21:
22: import java.util.Iterator;
23: import junit.framework.Test;
24: import junit.framework.TestResult;
25: import junit.framework.TestSuite;
26:
27: /**
28: *
29: * @author ca@netbeans.org
30: */
31:
32: public class SequentialTestSuite extends TestSuite {
33: private TestSequence m_testSequence;
34:
35: /** Creates a new instance of SequentialTestSuite */
36: public SequentialTestSuite(String name, TestSequence testSequence) {
37: super (name);
38: m_testSequence = testSequence;
39: }
40:
41: public int countTestCases() {
42: return 1; // doesn't matter
43: }
44:
45: public void run(TestResult result) {
46: try {
47: recurseTests(m_testSequence, result);
48: } finally {
49: m_testSequence.finalCleanup();
50: }
51: }
52:
53: private void recurseTests(SequentialTest sequentialTest,
54: TestResult result) {
55:
56: sequentialTest.setupOnce();
57:
58: while (true) {
59: if (result.shouldStop()) {
60: break;
61: }
62:
63: sequentialTest.setup();
64:
65: if (sequentialTest.isCompleted()) {
66: break;
67: }
68:
69: if (sequentialTest.needsExecution()) {
70: String testName = sequentialTest.getTestName().trim();
71: Test test = new SequentialTestCase(testName,
72: sequentialTest);
73: runTest(test, result);
74: }
75:
76: if (sequentialTest instanceof TestSequence) {
77: TestSequence sequence = (TestSequence) sequentialTest;
78:
79: Iterator<SequentialTest> iterator = sequence
80: .getIterator();
81: if (iterator != null) {
82: while (iterator.hasNext()) {
83: SequentialTest st = iterator.next();
84: recurseTests(st, result);
85: }
86: }
87: }
88:
89: sequentialTest.cleanup();
90: }
91:
92: sequentialTest.cleanupOnce();
93: }
94: }
|