1 26 27 package net.sourceforge.groboutils.junit.v1.parser; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 32 import java.lang.reflect.Method ; 33 import java.lang.reflect.InvocationTargetException ; 34 import java.lang.reflect.Constructor ; 35 36 37 44 public class JUnit3_8Creator implements ITestCreator 45 { 46 51 public boolean canCreate( Class theClass ) 52 { 53 if (!TestCase.class.isAssignableFrom( theClass )) 54 { 55 return false; 56 } 57 58 try 59 { 60 Constructor c = theClass.getConstructor( new Class [0] ); 61 return (c != null); 62 } 63 catch (Exception ex) 64 { 65 return false; 66 } 67 } 68 69 70 81 public Test createTest( Class theClass, Method method ) 82 throws InstantiationException , NoSuchMethodException , 83 InvocationTargetException , IllegalAccessException , 84 ClassCastException 85 { 86 TestCase tc; 87 try 88 { 89 tc = (TestCase)theClass.newInstance(); 90 } 91 catch (IllegalArgumentException iae) 92 { 93 StringBuffer args = new StringBuffer ( 94 "Arguments didn't match for default constructor in class " 95 ); 96 args.append( theClass.getName() ).append( "." ); 97 throw new InstantiationException ( args.toString() ); 98 } 99 tc.setName( method.getName() ); 100 return tc; 101 } 102 } 103 104 | Popular Tags |