diff options
Diffstat (limited to 'src/test/javassist')
-rw-r--r-- | src/test/javassist/tools/CallbackTest.java | 40 |
1 files changed, 40 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..a37ee61d --- /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(); + } +} |