1 20 package org.apache.cactus.internal.util; 21 22 import java.lang.reflect.Method ; 23 24 import org.apache.cactus.util.ChainedRuntimeException; 25 26 import junit.framework.Test; 27 import junit.framework.TestCase; 28 29 35 public class JUnitVersionHelper 36 { 37 41 private static Method testCaseName = null; 42 43 static 44 { 45 try 46 { 47 testCaseName = TestCase.class.getMethod("getName", new Class [0]); 48 } 49 catch (NoSuchMethodException e) 50 { 51 try 53 { 54 testCaseName = TestCase.class.getMethod("name", new Class [0]); 55 } 56 catch (NoSuchMethodException e2) 57 { 58 throw new ChainedRuntimeException("Cannot find method name()"); 59 } 60 } 61 } 62 63 72 public static String getTestCaseName(Test theTest) 73 { 74 String name; 75 76 if (theTest instanceof TestCase && (testCaseName != null)) 77 { 78 try 79 { 80 name = (String ) testCaseName.invoke(theTest, new Object [0]); 81 } 82 catch (Throwable e) 83 { 84 name = "unknown"; 85 } 86 } 87 else 88 { 89 name = "unknown"; 90 } 91 92 return name; 93 } 94 } 95 | Popular Tags |