diff options
Diffstat (limited to 'src/test/javassist')
-rw-r--r-- | src/test/javassist/HotswapTest.java | 34 | ||||
-rw-r--r-- | src/test/javassist/JvstTest.java | 1 | ||||
-rw-r--r-- | src/test/javassist/JvstTest2.java | 1 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/test/javassist/HotswapTest.java b/src/test/javassist/HotswapTest.java new file mode 100644 index 00000000..8b4db598 --- /dev/null +++ b/src/test/javassist/HotswapTest.java @@ -0,0 +1,34 @@ +package javassist; + +import javassist.util.HotSwapAgent; +import junit.framework.TestCase; + +public class HotswapTest extends TestCase { + public static void main(String[] args) throws Exception { + // run java -javaagent:hotswap.jar javassist.HotswapTest + new HotswapTest(HotswapTest.class.getName()).testHotswap(); + } + + public HotswapTest(String name) { + super(name); + } + + public static class Foo { + public int foo() { return 1; } + } + + public void testHotswap() throws Exception { + Foo f = new Foo(); + assertEquals(1, f.foo()); + + ClassPool cp = ClassPool.getDefault(); + CtClass clazz = cp.get(Foo.class.getName()); + CtMethod m = clazz.getDeclaredMethod("foo"); + clazz.removeMethod(m); + clazz.addMethod(CtNewMethod.make("public int foo() { return 2; }", clazz)); + HotSwapAgent.redefine(Foo.class, clazz); + Foo g = new Foo(); + assertEquals(2, g.foo()); + System.out.println("Foo#foo() = " + g.foo()); + } +} diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index 550d4278..d660a335 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -1124,6 +1124,7 @@ public class JvstTest extends JvstTestRoot { suite.addTestSuite(testproxy.ProxyFactoryPerformanceTest.class); // remove? suite.addTestSuite(javassist.proxyfactory.ProxyFactoryTest.class); suite.addTestSuite(javassist.proxyfactory.Tester.class); + suite.addTestSuite(javassist.HotswapTest.class); suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class); suite.addTestSuite(test.javassist.convert.ArrayAccessReplaceTest.class); suite.addTestSuite(test.javassist.proxy.JASSIST113RegressionTest.class); diff --git a/src/test/javassist/JvstTest2.java b/src/test/javassist/JvstTest2.java index 443bbb30..ec314e12 100644 --- a/src/test/javassist/JvstTest2.java +++ b/src/test/javassist/JvstTest2.java @@ -4,7 +4,6 @@ import java.io.*; import java.net.URL; import java.lang.reflect.Method; -import javassist.bytecode.ClassFile; import javassist.expr.*; public class JvstTest2 extends JvstTestRoot { |