]> source.dussan.org Git - javassist.git/commitdiff
test cases taken from 3.12 for JBPAPP9257
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Thu, 14 Jun 2012 16:46:08 +0000 (16:46 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Thu, 14 Jun 2012 16:46:08 +0000 (16:46 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@638 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/test/javassist/JvstTest.java
src/test/test/javassist/proxy/Foo.java [new file with mode: 0644]
src/test/test/javassist/proxy/JBPAPP9257Test.java [new file with mode: 0644]

index f646506bef9c63c1c78856455cf4165b5b274a63..16d91390ee0fe3b4687583b11a5b35fb68bf69db 100644 (file)
@@ -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 (file)
index 0000000..fd9e6e3
--- /dev/null
@@ -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 (file)
index 0000000..0de0729
--- /dev/null
@@ -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());
+    }
+}