diff options
author | chibash <chiba@javassist.org> | 2016-07-30 18:47:59 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2016-07-30 21:12:17 +0900 |
commit | d5677e4a3ac426e7c39f478c75b08b6c1c4674fc (patch) | |
tree | 2d59131579f47b0e3f891c0ff95f48d4977b0dba /src/test | |
parent | 13c7057570305ca3b6d3890ec3f509f487c6973a (diff) | |
download | javassist-d5677e4a3ac426e7c39f478c75b08b6c1c4674fc.tar.gz javassist-d5677e4a3ac426e7c39f478c75b08b6c1c4674fc.zip |
fixes a bug of ProxyFactory. It could not deal with default methods declared in an interface. https://github.com/jboss-javassist/javassist/issues/45
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test/javassist/proxy/ProxySimpleTest.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/test/javassist/proxy/ProxySimpleTest.java b/src/test/test/javassist/proxy/ProxySimpleTest.java index f37e7b8c..289895cc 100644 --- a/src/test/test/javassist/proxy/ProxySimpleTest.java +++ b/src/test/test/javassist/proxy/ProxySimpleTest.java @@ -140,4 +140,63 @@ public class ProxySimpleTest extends TestCase { public String extended() { return "ext"; } public String base2() { return super.base2() + "ext2"; } } + + String valueDefaultMethods = ""; + + public void testDefaultMethods() throws Exception { + valueDefaultMethods = ""; + ProxyFactory f = new ProxyFactory(); + f.writeDirectory = "./proxy"; + f.setSuperclass(Default3.class); + Class c = f.createClass(); + MethodHandler mi = new MethodHandler() { + public Object invoke(Object self, Method m, Method proceed, + Object[] args) throws Throwable { + valueDefaultMethods += "1"; + return proceed.invoke(self, args); // execute the original method. + } + }; + Default3 foo = (Default3)c.newInstance(); + ((Proxy)foo).setHandler(mi); + foo.foo(); + foo.bar(); + assertEquals("11", valueDefaultMethods); + } + + public void testDefaultMethods2() throws Exception { + valueDefaultMethods = ""; + ProxyFactory f = new ProxyFactory(); + f.writeDirectory = "./proxy"; + f.setInterfaces(new Class[] { Default2.class }); + Class c = f.createClass(); + MethodHandler mi = new MethodHandler() { + public Object invoke(Object self, Method m, Method proceed, + Object[] args) throws Throwable { + valueDefaultMethods += "1"; + return proceed.invoke(self, args); // execute the original method. + } + }; + Default2 foo = (Default2)c.newInstance(); + ((Proxy)foo).setHandler(mi); + foo.foo(); + foo.bar(); + assertEquals("11", valueDefaultMethods); + } + + public static interface Default1 { + default int foo() { return 0; } + default int baz() { return 2; } + } + + public static interface Default2 extends Default1 { + default int bar() { return 1; } + } + + public static class Default3 implements Default2 { + public int foo() { return Default2.super.foo(); } + } + + public static class Default4 extends Default3 { + public int baz() { return super.baz(); } + } } |