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