01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.bytecode;
05:
06: import com.tc.object.BaseDSOTestCase;
07:
08: import java.lang.reflect.Method;
09:
10: public class ClassAdapterTestBase extends BaseDSOTestCase {
11: protected void invokeMethod(Class c, Object instance, String name,
12: Class[] paramTypes, Object[] paramValues) throws Exception {
13: invokeMethod(c, instance, name, paramTypes, paramValues, true);
14: }
15:
16: protected Object invokeMethod(Class c, Object instance,
17: String name, Class[] paramTypes, Object[] paramValues,
18: boolean failOnException) throws Exception {
19: try {
20: Method putMethod = c.getDeclaredMethod(
21: removeDescriptionIfNecessary(name), paramTypes);
22: putMethod.setAccessible(true);
23:
24: return putMethod.invoke(instance, paramValues);
25: } catch (Exception e) {
26: if (failOnException) {
27: e.printStackTrace();
28: fail("Caught exception: " + e);
29: }
30: throw e;
31: }
32: }
33:
34: private String removeDescriptionIfNecessary(String methodName) {
35: int index = methodName.indexOf('(');
36: if (index < 0) {
37: return methodName;
38: } else {
39: return methodName.substring(0, index);
40: }
41: }
42: }
|