From 08deb0e6bc17f84f6bda03a29a7c2d3a8610a1ef Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 14 Jun 2012 16:46:08 +0000 Subject: [PATCH] test cases taken from 3.12 for JBPAPP9257 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@638 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/test/javassist/JvstTest.java | 1 + src/test/test/javassist/proxy/Foo.java | 16 +++++ .../test/javassist/proxy/JBPAPP9257Test.java | 65 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/test/test/javassist/proxy/Foo.java create mode 100644 src/test/test/javassist/proxy/JBPAPP9257Test.java diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index f646506b..16d91390 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -1122,6 +1122,7 @@ public class JvstTest extends JvstTestRoot { suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class); suite.addTestSuite(test.javassist.convert.ArrayAccessReplaceTest.class); suite.addTestSuite(test.javassist.proxy.JASSIST113RegressionTest.class); + suite.addTestSuite(test.javassist.proxy.JBPAPP9257Test.class); //suite.addTestSuite(test.javassist.proxy.ProxyCacheGCTest.class); suite.addTestSuite(test.javassist.proxy.ProxyFactoryCompatibilityTest.class); suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class); diff --git a/src/test/test/javassist/proxy/Foo.java b/src/test/test/javassist/proxy/Foo.java new file mode 100644 index 00000000..fd9e6e3b --- /dev/null +++ b/src/test/test/javassist/proxy/Foo.java @@ -0,0 +1,16 @@ +package test.javassist.proxy; + +public class Foo { + public String doSomething() { + return "I'm doing something"; + } + + public Object getHandler() { + return "This is a secret handler"; + } +} + +class Foo2 { + public String doSomething() { return "do something"; } + public String getHandler() { return "return a string"; } +} \ No newline at end of file diff --git a/src/test/test/javassist/proxy/JBPAPP9257Test.java b/src/test/test/javassist/proxy/JBPAPP9257Test.java new file mode 100644 index 00000000..0de07298 --- /dev/null +++ b/src/test/test/javassist/proxy/JBPAPP9257Test.java @@ -0,0 +1,65 @@ +package test.javassist.proxy; + +import java.lang.reflect.Method; +import javassist.util.proxy.ProxyFactory; +import javassist.util.proxy.MethodHandler; +import javassist.util.proxy.MethodFilter; +import javassist.util.proxy.ProxyObject; +import javassist.util.proxy.Proxy; +import junit.framework.TestCase; + +public class JBPAPP9257Test extends TestCase { + public void testGetHandler() throws Exception { + ProxyFactory f = new ProxyFactory(); + f.setSuperclass(Foo.class); + f.setFilter(new MethodFilter() { + public boolean isHandled(Method m) { + // ignore finalize() + return !m.getName().equals("finalize"); + } + }); + Class c = f.createClass(); + MethodHandler mi = new MethodHandler() { + public Object invoke(Object self, Method m, Method proceed, + Object[] args) throws Throwable { + System.out.println("Name: " + m.getName()); + return proceed.invoke(self, args) + "!"; // execute the original + // method. + } + }; + Foo foo = (Foo) c.newInstance(); + try { + ((ProxyObject)foo).setHandler(mi); + fail("foo is a ProxyObject!"); + } catch (ClassCastException e) {} + ((Proxy)foo).setHandler(mi); + assertEquals("I'm doing something!", foo.doSomething()); + } + + public void testGetHandler2() throws Exception { + ProxyFactory f = new ProxyFactory(); + f.setSuperclass(Foo2.class); + f.setFilter(new MethodFilter() { + public boolean isHandled(Method m) { + // ignore finalize() + return !m.getName().equals("finalize"); + } + }); + Class c = f.createClass(); + MethodHandler mi = new MethodHandler() { + public Object invoke(Object self, Method m, Method proceed, + Object[] args) throws Throwable { + System.out.println("Name: " + m.getName()); + return proceed.invoke(self, args) + "!"; // execute the original + // method. + } + }; + Foo2 foo = (Foo2)c.newInstance(); + try { + ((ProxyObject)foo).setHandler(mi); + fail("foo is a ProxyObject!"); + } catch (ClassCastException e) {} + ((Proxy)foo).setHandler(mi); + assertEquals("do something!", foo.doSomething()); + } +} -- 2.39.5