1b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotpackage org.junit.internal.runners; 2b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 3b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.reflect.InvocationTargetException; 4b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.reflect.Method; 5b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.lang.reflect.Modifier; 6b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 7b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport junit.framework.Test; 8b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 9b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot/** Runner for use with JUnit 3.8.x-style AllTests classes 10b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * (those that only implement a static <code>suite()</code> 11b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * method). For example: 12b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * <pre> 13b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * @RunWith(AllTests.class) 14b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * public class ProductTests { 15b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * public static junit.framework.Test suite() { 16b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * ... 17b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * } 18b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * } 19b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot * </pre> 20b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot */ 21b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotpublic class SuiteMethod extends JUnit38ClassRunner { 22b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public SuiteMethod(Class<?> klass) throws Throwable { 23b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot super(testFromSuiteMethod(klass)); 24b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 25b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 26b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public static Test testFromSuiteMethod(Class<?> klass) throws Throwable { 27b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot Method suiteMethod= null; 28b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot Test suite= null; 29b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot try { 30b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot suiteMethod= klass.getMethod("suite"); 31b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot if (! Modifier.isStatic(suiteMethod.getModifiers())) { 32b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot throw new Exception(klass.getName() + ".suite() must be static"); 33b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 34b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot suite= (Test) suiteMethod.invoke(null); // static method 35b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } catch (InvocationTargetException e) { 36b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot throw e.getCause(); 37b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 38b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return suite; 39b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 40b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot} 41