01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.testutil;
04:
05: import junit.framework.*;
06: import java.lang.reflect.Method;
07:
08: public class TestSuiteMaker {
09: public static Test makeSuite(String name, Class[] tests) {
10: TestSuite suite = new TestSuite(name);
11: for (int i = 0; i < tests.length; i++) {
12: Class test = tests[i];
13: try {
14: if (isSuite(test))
15: suite.addTest(getSuite(test));
16: else
17: suite.addTest(new TestSuite(test));
18: } catch (Exception e) {
19: System.err.println("Problem adding test to suite: "
20: + test.getName());
21: }
22: }
23: return suite;
24: }
25:
26: public static boolean isSuite(Class test) {
27: Method suite = getSuiteMethod(test);
28: return suite != null;
29: }
30:
31: private static Method getSuiteMethod(Class test) {
32: Method suite = null;
33: try {
34: suite = test.getDeclaredMethod("suite", new Class[] {});
35: } catch (NoSuchMethodException e) {
36: }
37: return suite;
38: }
39:
40: public static Test getSuite(Class test) throws Exception {
41: Method suite = getSuiteMethod(test);
42: return (Test) suite.invoke(null, new Object[] {});
43: }
44: }
|