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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. protected void print(String msg) {
  12. System.out.println(msg);
  13. }
  14. protected void print(Exception e) {
  15. e.printStackTrace();
  16. }
  17. protected void setUp() throws Exception {
  18. sloader = ClassPool.getDefault();
  19. dloader = new ClassPool(null);
  20. dloader.appendSystemPath();
  21. dloader.insertClassPath(".");
  22. cloader = new Loader(dloader);
  23. }
  24. protected Object make(String name) throws Exception {
  25. return cloader.loadClass(name).getConstructor().newInstance();
  26. }
  27. protected int invoke(Object target, String method) throws Exception {
  28. Method m = target.getClass().getMethod(method, new Class[0]);
  29. Object res = m.invoke(target, new Object[0]);
  30. return ((Integer)res).intValue();
  31. }
  32. protected int invoke(Object target, String method, int arg)
  33. throws Exception {
  34. Method m =
  35. target.getClass().getMethod(method, new Class[] { int.class });
  36. Object res = m.invoke(target, new Object[] { Integer.valueOf(arg)});
  37. return ((Integer) res).intValue();
  38. }
  39. }