You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JvstTestRoot.java 1.5KB

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