diff options
author | marten.hedborg <marten.hedborg@gmail.com> | 2015-03-15 18:37:30 +0100 |
---|---|---|
committer | marten.hedborg <marten.hedborg@gmail.com> | 2015-03-15 18:37:30 +0100 |
commit | 89e50989d08c15ee15efe6c8427e56b97c572317 (patch) | |
tree | 0fcd60ebc69e448d60fdb2957f84f632fa62c12b /src/test/javassist | |
parent | 1025384fe04e05dee846b8db3fd6c9de853c7012 (diff) | |
download | javassist-89e50989d08c15ee15efe6c8427e56b97c572317.tar.gz javassist-89e50989d08c15ee15efe6c8427e56b97c572317.zip |
Changed Callback so that CtBehaviour is independet of Callback. Added testcase
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(); + } +} |