KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > xml > schema > core > lib > sequential > SequentialTestSuite


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * 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.xml.schema.core.lib.sequential;
21
22 import java.util.Iterator JavaDoc;
23 import junit.framework.Test;
24 import junit.framework.TestResult;
25 import junit.framework.TestSuite;
26
27
28 /**
29  *
30  * @author ca@netbeans.org
31  */

32 public class SequentialTestSuite extends TestSuite {
33     private TestSequence m_testSequence;
34     
35     /** Creates a new instance of SequentialTestSuite */
36     public SequentialTestSuite(String JavaDoc 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, TestResult result) {
54         
55         sequentialTest.setupOnce();
56         
57         while (true) {
58             if (result.shouldStop()) {
59                 break;
60             }
61             
62             sequentialTest.setup();
63             
64             if (sequentialTest.isCompleted()) {
65                 break;
66             }
67             
68             if (sequentialTest.needsExecution()) {
69                 String JavaDoc testName = sequentialTest.getTestName().trim();
70                 Test test = new SequentialTestCase(testName, sequentialTest);
71                 runTest(test, result);
72             }
73             
74             if (sequentialTest instanceof TestSequence) {
75                 TestSequence sequence = (TestSequence) sequentialTest;
76                 
77                 Iterator JavaDoc<SequentialTest> iterator = sequence.getIterator();
78                 if (iterator != null) {
79                     while(iterator.hasNext()) {
80                         SequentialTest st = iterator.next();
81                         recurseTests(st, result);
82                     }
83                 }
84             }
85             
86             sequentialTest.cleanup();
87         }
88         
89         sequentialTest.cleanupOnce();
90     }
91 }
92
Popular Tags