diff options
author | Shigeru Chiba <chiba@chibas.net> | 2015-03-16 21:49:16 +0900 |
---|---|---|
committer | Shigeru Chiba <chiba@chibas.net> | 2015-03-16 21:49:16 +0900 |
commit | bbecd7c489662c68af12b0e56265d52b7b2a644d (patch) | |
tree | 338a3fc7f1831eb57d80855f94819eea392d8775 /src/test | |
parent | d045a7f1ec0e5f2067459352426a4c987c4a1a7a (diff) | |
parent | 7bb3c3936757923e69d1c10c914ead32b9399eee (diff) | |
download | javassist-bbecd7c489662c68af12b0e56265d52b7b2a644d.tar.gz javassist-bbecd7c489662c68af12b0e56265d52b7b2a644d.zip |
Merge pull request #26 from m8rten/master
Added call back feature to CtBehaviour
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/tools/CallbackTest.java | 40 | ||||
-rw-r--r-- | src/test/test/javassist/tools/DummyClass.java | 8 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/test/javassist/tools/CallbackTest.java b/src/test/javassist/tools/CallbackTest.java new file mode 100644 index 00000000..96632bda --- /dev/null +++ b/src/test/javassist/tools/CallbackTest.java @@ -0,0 +1,40 @@ +package javassist.tools; + +import javassist.*; +import junit.framework.TestCase; +import test.javassist.tools.DummyClass; + +import static javassist.tools.Callback.*; + +public class CallbackTest extends TestCase { + + public void testSomeCallbacks() throws Exception { + + // Get class and method to change + ClassPool pool = ClassPool.getDefault(); + CtClass classToChange = pool.get("test.javassist.tools.DummyClass"); + CtMethod methodToChange = classToChange.getDeclaredMethod("dummyMethod"); + + // Insert after + methodToChange.insertAfter(new Callback("Thread.currentThread(), dummyString") { + @Override + public void result(Object... objects) { + assertEquals(objects[0], Thread.currentThread()); + assertEquals(objects[1], "dummyStringValue"); + } + }.sourceCode()); + + // Insert after using utility method + insertAfter(methodToChange, new Callback("Thread.currentThread(), dummyString") { + @Override + public void result(Object... objects) { + assertEquals(objects[0], Thread.currentThread()); + assertEquals(objects[1], "dummyStringValue"); + } + }); + + // Change class and invoke method; + classToChange.toClass(); + new DummyClass().dummyMethod(); + } +} diff --git a/src/test/test/javassist/tools/DummyClass.java b/src/test/test/javassist/tools/DummyClass.java new file mode 100644 index 00000000..020aa55d --- /dev/null +++ b/src/test/test/javassist/tools/DummyClass.java @@ -0,0 +1,8 @@ +package test.javassist.tools; + +public class DummyClass { + + private String dummyString = "dummyStringValue"; + + public void dummyMethod(){} +} |