diff options
author | chibash <chiba@javassist.org> | 2017-04-16 23:42:05 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2017-04-16 23:42:05 +0900 |
commit | d5ea6843af8ca063f56d5356b5e29156c25f035e (patch) | |
tree | 749a5afc02a35eb269d2c029a72c515a3a4cccd3 /src/test/javassist | |
parent | 25fdc6bafad29e4b1c7b0f4b340641a4d7f8c476 (diff) | |
download | javassist-d5ea6843af8ca063f56d5356b5e29156c25f035e.tar.gz javassist-d5ea6843af8ca063f56d5356b5e29156c25f035e.zip |
adds javassist.util.HotSwapAgent
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 { |