1 4 package com.tc.object.bytecode; 5 6 import com.tc.object.BaseDSOTestCase; 7 8 import java.lang.reflect.Method ; 9 10 public class ClassAdapterTestBase extends BaseDSOTestCase { 11 protected void invokeMethod(Class c, Object instance, String name, Class [] paramTypes, Object [] paramValues) 12 throws Exception { 13 invokeMethod(c, instance, name, paramTypes, paramValues, true); 14 } 15 16 protected Object invokeMethod(Class c, Object instance, String name, Class [] paramTypes, Object [] paramValues, 17 boolean failOnException) throws Exception { 18 try { 19 Method putMethod = c.getDeclaredMethod(removeDescriptionIfNecessary(name), paramTypes); 20 putMethod.setAccessible(true); 21 22 return putMethod.invoke(instance, paramValues); 23 } catch (Exception e) { 24 if (failOnException) { 25 e.printStackTrace(); 26 fail("Caught exception: " + e); 27 } 28 throw e; 29 } 30 } 31 32 private String removeDescriptionIfNecessary(String methodName) { 33 int index = methodName.indexOf('('); 34 if (index < 0) { 35 return methodName; 36 } else { 37 return methodName.substring(0, index); 38 } 39 } 40 } | Popular Tags |