1 package org.testng.junit; 2 3 import java.lang.reflect.Method; 4 import java.lang.reflect.Modifier; 5 import junit.framework.Test; 6 7 /** 8 * 9 * @author lukas 10 */ 11 public class JUnit3TestRecognizer implements JUnitTestRecognizer { 12 JUnit3TestRecognizer()13 public JUnit3TestRecognizer() { 14 } 15 isTest(Class c)16 public boolean isTest(Class c) { 17 //class implementing junit.framework.Test with at least one test* method 18 if (Test.class.isAssignableFrom(c)) { 19 boolean haveTest = false; 20 for (Method m : c.getMethods()) { 21 if (m.getName().startsWith("test")) { 22 haveTest = true; 23 break; 24 } 25 } 26 if (haveTest) { 27 return true; 28 } 29 } 30 try { 31 //or a class with public static Test suite() method 32 Method m = c.getDeclaredMethod("suite"); 33 if (Modifier.isPublic(m.getModifiers()) && Modifier.isStatic(m.getModifiers())) { 34 return m.getReturnType().isAssignableFrom(Test.class); 35 } 36 } catch (Throwable t) { 37 return false; 38 } 39 return false; 40 } 41 } 42