KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > ClassAdapterTestBase


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.bytecode;
5
6 import com.tc.object.BaseDSOTestCase;
7
8 import java.lang.reflect.Method JavaDoc;
9
10 public class ClassAdapterTestBase extends BaseDSOTestCase {
11   protected void invokeMethod(Class JavaDoc c, Object JavaDoc instance, String JavaDoc name, Class JavaDoc[] paramTypes, Object JavaDoc[] paramValues)
12       throws Exception JavaDoc {
13     invokeMethod(c, instance, name, paramTypes, paramValues, true);
14   }
15
16   protected Object JavaDoc invokeMethod(Class JavaDoc c, Object JavaDoc instance, String JavaDoc name, Class JavaDoc[] paramTypes, Object JavaDoc[] paramValues,
17                               boolean failOnException) throws Exception JavaDoc {
18     try {
19       Method JavaDoc putMethod = c.getDeclaredMethod(removeDescriptionIfNecessary(name), paramTypes);
20       putMethod.setAccessible(true);
21
22       return putMethod.invoke(instance, paramValues);
23     } catch (Exception JavaDoc e) {
24       if (failOnException) {
25         e.printStackTrace();
26         fail("Caught exception: " + e);
27       }
28       throw e;
29     }
30   }
31
32   private String JavaDoc removeDescriptionIfNecessary(String JavaDoc 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