• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package javassist;
2 
3 import junit.framework.*;
4 import java.lang.reflect.Method;
5 
6 public class JvstTestRoot extends TestCase {
7     // the directory where all compiled class files are found.
8     public static final String PATH = "../../target/test-classes/";
9 
10     // the directory where javassist.jar is found.
11     public static final String JAR_PATH = "../../";
12 
13     ClassPool sloader, dloader;
14     Loader cloader;
15 
JvstTestRoot(String name)16     public JvstTestRoot(String name) {
17         super(name);
18     }
19 
print(String msg)20     protected void print(String msg) {
21         System.out.println(msg);
22     }
23 
print(Exception e)24     protected void print(Exception e) {
25         e.printStackTrace();
26     }
27 
setUp()28     protected void setUp() throws Exception {
29         sloader = ClassPool.getDefault();
30         dloader = new ClassPool(null);
31         dloader.appendSystemPath();
32         dloader.insertClassPath(".");
33         cloader = new Loader(dloader);
34     }
35 
make(String name)36     protected Object make(String name) throws Exception {
37         return cloader.loadClass(name).getConstructor().newInstance();
38     }
39 
invoke(Object target, String method)40     protected int invoke(Object target, String method) throws Exception {
41         Method m = target.getClass().getMethod(method, new Class[0]);
42         Object res = m.invoke(target, new Object[0]);
43         return ((Integer)res).intValue();
44     }
45 
invoke(Object target, String method, int arg)46     protected int invoke(Object target, String method, int arg)
47         throws Exception {
48         Method m =
49             target.getClass().getMethod(method, new Class[] { int.class });
50         Object res = m.invoke(target, new Object[] { Integer.valueOf(arg)});
51         return ((Integer) res).intValue();
52     }
53 }
54