KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > devtools > junit > launcher > LauncherSelectedTest


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.devtools.junit.launcher;
19
20 import java.lang.reflect.InvocationTargetException JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.sape.carbon.core.bootstrap.test.BootStrapperTest;
28 import org.sape.carbon.core.util.reflection.ClassFinder;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34 import javax.swing.SwingUtilities JavaDoc;
35
36 /**
37  * jUnit test harness that works in tandem with the TestLauncher to allow
38  * a user to graphically select tests from the system to execute.
39  * <p>
40  * This test harness should not be called directly, instead it should
41  * launched through the TestLauncher. Direct calls to this harness
42  * will result in successfully running no useful tests.
43  * </p>
44  *
45  * Copyright 2003 Sapient
46  * @since carbon 2.1
47  * @author Jordan Reed, August 2003
48  * @version $Revision: 1.1 $($Author: jdreed $ / $Date: 2003/08/13 02:36:11 $)
49  */

50 public class LauncherSelectedTest extends TestCase {
51     public LauncherSelectedTest(String JavaDoc name) {
52         super(name);
53     }
54
55     /**
56      * This method retrieves the list of tests from a static
57      * public variable inside the TestLauncher and will then
58      * add all tests from that Set into the suite for return.
59      *
60      * @return a list of all tests from the TestLauncher
61      */

62     public static Test suite() {
63         TestSuite suite = new TestSuite();
64
65         // Add this magical test which must always be run first to
66
// make sure Carbon is up and bootstrapped correctly.
67
suite.addTest(BootStrapperTest.suite());
68
69         Iterator JavaDoc testClassIterator = TestLauncher.selectedClasses.iterator();
70         while(testClassIterator.hasNext()) {
71             String JavaDoc testClassName = (String JavaDoc) testClassIterator.next();
72
73         try {
74             Class JavaDoc testClass = Class.forName(testClassName);
75             Method JavaDoc suiteMethod = testClass.getMethod("suite", null);
76             if (Modifier.isStatic(suiteMethod.getModifiers())) {
77                 suite.addTest((Test) suiteMethod.invoke(null, null));
78             }
79
80         // don't care about any of these exceptions, if they occur
81
// just eat them an move on to the next test case
82
} catch(SecurityException JavaDoc e) {
83         } catch(IllegalArgumentException JavaDoc e) {
84         } catch(ClassNotFoundException JavaDoc e) {
85         } catch(NoSuchMethodException JavaDoc e) {
86         } catch(IllegalAccessException JavaDoc e) {
87         } catch(InvocationTargetException JavaDoc e) {
88         }
89         }
90
91         return suite;
92     }
93
94 }
95
Popular Tags