aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/HotswapTest.java
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2017-04-16 23:42:05 +0900
committerchibash <chiba@javassist.org>2017-04-16 23:42:05 +0900
commitd5ea6843af8ca063f56d5356b5e29156c25f035e (patch)
tree749a5afc02a35eb269d2c029a72c515a3a4cccd3 /src/test/javassist/HotswapTest.java
parent25fdc6bafad29e4b1c7b0f4b340641a4d7f8c476 (diff)
downloadjavassist-d5ea6843af8ca063f56d5356b5e29156c25f035e.tar.gz
javassist-d5ea6843af8ca063f56d5356b5e29156c25f035e.zip
adds javassist.util.HotSwapAgent
Diffstat (limited to 'src/test/javassist/HotswapTest.java')
-rw-r--r--src/test/javassist/HotswapTest.java34
1 files changed, 34 insertions, 0 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());
+ }
+}