summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-06-14 16:46:08 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-06-14 16:46:08 +0000
commit08deb0e6bc17f84f6bda03a29a7c2d3a8610a1ef (patch)
tree432f2b1e208343bfac623221b13c99c7cfd4ee27 /src/test
parent13a2b0372d589d95b8f00ba6a54189ceb6191db2 (diff)
downloadjavassist-08deb0e6bc17f84f6bda03a29a7c2d3a8610a1ef.tar.gz
javassist-08deb0e6bc17f84f6bda03a29a7c2d3a8610a1ef.zip
test cases taken from 3.12 for JBPAPP9257
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@638 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/test')
-rw-r--r--src/test/javassist/JvstTest.java1
-rw-r--r--src/test/test/javassist/proxy/Foo.java16
-rw-r--r--src/test/test/javassist/proxy/JBPAPP9257Test.java65
3 files changed, 82 insertions, 0 deletions
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());
+ }
+}