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.

JvstTest5.java 1.4KB

12345678910111213141516171819202122232425262728293031323334
  1. package javassist;
  2. public class JvstTest5 extends JvstTestRoot {
  3. public JvstTest5(String name) {
  4. super(name);
  5. }
  6. public void testDollarClassInStaticMethod() throws Exception {
  7. CtClass cc = sloader.makeClass("test5.DollarClass");
  8. CtMethod m = CtNewMethod.make("public static int run(){ return $class.getName().length(); }", cc);
  9. cc.addMethod(m);
  10. m = CtNewMethod.make("public int run2(){ return $class.getName().length(); }", cc);
  11. cc.addMethod(m);
  12. cc.writeFile();
  13. Object obj = make(cc.getName());
  14. assertEquals(cc.getName().length(), invoke(obj, "run"));
  15. assertEquals(cc.getName().length(), invoke(obj, "run2"));
  16. }
  17. public void testSuperDefaultMethodCall() throws Exception {
  18. CtClass cc = sloader.get("test5.DefaultMethod");
  19. CtMethod m = CtNewMethod.make("public int run(){ return test5.DefaultMethodIntf.super.foo(); }", cc);
  20. cc.addMethod(m);
  21. m = CtNewMethod.make("public int run2(){ return test5.DefaultMethodIntf.baz(); }", cc);
  22. cc.addMethod(m);
  23. m = CtNewMethod.make("public int run3(){ return test5.DefaultMethodIntf.super.baz(); }", cc);
  24. cc.addMethod(m);
  25. cc.writeFile();
  26. Object obj = make(cc.getName());
  27. assertEquals(1, invoke(obj, "run"));
  28. assertEquals(10, invoke(obj, "run2"));
  29. assertEquals(10, invoke(obj, "run3"));
  30. }
  31. }