1 package org.jacorb.test.common; 2 3 23 24 import java.lang.reflect.Method ; 25 import java.net.*; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 35 36 public class TestUtils 37 { 38 private static final String [] STRING_ARRAY_TEMPLATE = new String [0]; 39 private static String testHome = null; 40 41 51 public static String [] getTestMethods(Class clazz) 52 { 53 return getTestMethods(clazz, "test"); 54 } 55 56 public static String [] getTestMethods(Class clazz, String prefix) 57 { 58 Method [] methods = clazz.getMethods(); 59 60 List result = new ArrayList (); 61 62 for (int x = 0; x < methods.length; ++x) 63 { 64 if (methods[x].getName().startsWith(prefix)) 65 { 66 if (methods[x].getParameterTypes().length == 0) 67 { 68 result.add(methods[x].getName()); 69 } 70 } 71 } 72 73 return (String []) result.toArray(STRING_ARRAY_TEMPLATE); 74 } 75 76 79 public static String testHome() 80 { 81 if (testHome == null) 82 { 83 URL url = TestUtils.class.getResource("/."); 84 String result = url.toString(); 85 if (result.matches("file:/.*?/classes/")) 86 result = result.substring (5, result.length() - 9); 89 else 90 throw new RuntimeException ("cannot find test home"); 91 testHome = result; 92 } 93 return testHome; 94 } 95 } | Popular Tags |