import javassist.util.proxy.MethodFilter;\r
import javassist.util.proxy.MethodHandler;\r
import javassist.util.proxy.ProxyObject;\r
+import javassist.util.proxy.Proxy;\r
import junit.framework.Assert;\r
import junit.framework.TestCase;\r
import java.io.*;\r
return proceed.invoke(self, args);\r
else\r
if (m.getReturnType() == int.class)\r
- return new Integer(3);\r
+ return Integer.valueOf(3);\r
else\r
return "OK";\r
}\r
ProxyFactory f = new ProxyFactory();\r
f.setSuperclass(Target.class);\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
f.writeDirectory = ".";\r
Class c = f.createClass();\r
Target obj = (Target)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor);\r
obj.m();\r
assertEquals(true, obj.m(true));\r
assertEquals((byte)1, obj.m1((byte)1));\r
ProxyFactory f = new ProxyFactory();\r
f.setSuperclass(Target1.class);\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
Class c = f.createClass();\r
Target1 obj = (Target1)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor);\r
assertEquals(null, obj.m(null));\r
assertEquals(1, interceptor.counter);\r
}\r
public void testObject() throws Exception {\r
ProxyFactory f = new ProxyFactory();\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
Class c = f.createClass();\r
Object obj = (Object)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor);\r
System.out.println(obj.toString());\r
assertEquals(2, interceptor.counter);\r
}\r
ProxyFactory f = new ProxyFactory();\r
f.writeDirectory = ".";\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
Class c = f.createClass();\r
Object obj = (Object)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor);\r
System.out.println("setter1: " + obj.toString());\r
((ProxyObject)obj).setHandler(new MethodHandler() {\r
public Object invoke(Object self, Method m, Method proceed,\r
public void testString() throws Exception {\r
ProxyFactory f = new ProxyFactory();\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
f.setSuperclass(String.class);\r
try {\r
public void testConstructor() throws Exception {\r
ProxyFactory f = new ProxyFactory();\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
f.setSuperclass(Target2.class);\r
Class c = f.createClass();\r
assertEquals(0, m1.getExceptionTypes().length);\r
assertEquals("java.io.IOException", m2.getExceptionTypes()[0].getName());\r
\r
- Target2 t2 = (Target2)con1.newInstance(new Object[] { new Integer(1) });\r
+ Target2 t2 = (Target2)con1.newInstance(new Object[] { Integer.valueOf(1) });\r
+ ((Proxy)t2).setHandler(interceptor);\r
System.out.println(t2.toString());\r
assertEquals(2, interceptor.counter);\r
\r
public void testInterface() throws Exception {\r
ProxyFactory f = new ProxyFactory();\r
Interceptor2 interceptor2 = new Interceptor2();\r
- f.setHandler(interceptor2);\r
+ // f.setHandler(interceptor2);\r
f.setFilter(finalizeRemover);\r
f.setInterfaces(new Class[] { Target3.class });\r
Class c = f.createClass();\r
Target3 obj = (Target3)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor2);\r
assertEquals("OK", obj.m());\r
System.out.println(obj.toString());\r
assertEquals(3, interceptor2.counter);\r
public void test2Interfaces() throws Exception {\r
ProxyFactory f = new ProxyFactory();\r
Interceptor2 interceptor2 = new Interceptor2();\r
- f.setHandler(interceptor2);\r
+ // f.setHandler(interceptor2);\r
f.setFilter(finalizeRemover);\r
f.setInterfaces(new Class[] { Target3.class, Target4.class });\r
Class c = f.createClass();\r
Target3 obj = (Target3)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor2);\r
assertEquals("OK", obj.m());\r
System.out.println(obj.toString());\r
assertEquals(3, interceptor2.counter);\r
\r
interceptor2.counter = 0;\r
Target4 obj4 = (Target4)c.newInstance();\r
+ ((Proxy)obj4).setHandler(interceptor2);\r
assertEquals(3, obj4.bar4());\r
assertEquals(3, obj4.foo4());\r
assertEquals(2, interceptor2.counter);\r
public void testFilter() throws Exception {\r
ProxyFactory f = new ProxyFactory();\r
Interceptor2 interceptor2 = new Interceptor2();\r
- f.setHandler(interceptor2);\r
+ // f.setHandler(interceptor2);\r
f.setFilter(finalizeRemover);\r
f.setInterfaces(new Class[] { Target3.class });\r
f.setFilter(new MethodFilter() {\r
});\r
Class c = f.createClass();\r
Target3 obj = (Target3)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor2);\r
assertEquals("OK", obj.m());\r
System.out.println(obj.toString());\r
assertEquals(1, interceptor2.counter);\r
ProxyFactory f = new ProxyFactory();\r
f.setSuperclass(Target5.class);\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
Class c = f.createClass();\r
- Target5 obj = (Target5)f.create(new Class[] { int.class }, new Object[] { new Integer(3) });\r
+ Target5 obj = (Target5)f.create(new Class[] { int.class }, new Object[] { Integer.valueOf(3) });\r
+ ((Proxy)obj).setHandler(interceptor);\r
assertEquals(3, obj.get());\r
}\r
\r
f.writeDirectory = ".";\r
f.setSuperclass(BridgeMethod.class);\r
Interceptor1 interceptor = new Interceptor1();\r
- f.setHandler(interceptor);\r
+ // f.setHandler(interceptor);\r
f.setFilter(finalizeRemover);\r
Class c = f.createClass();\r
BridgeMethod obj = (BridgeMethod)c.newInstance();\r
+ ((Proxy)obj).setHandler(interceptor);\r
Integer value = obj.m1();\r
assertEquals(7, value.intValue());\r
BridgeMethodInf inf = (BridgeMethodInf)obj;\r
ProxyFactory.classLoaderProvider = cp;\r
}\r
\r
- public void testCache() throws Exception {\r
+ @SuppressWarnings("deprecation")\r
+ public void testCache() throws Exception {\r
boolean prev = ProxyFactory.useCache;\r
ProxyFactory.useCache = true;\r
ProxyFactory f = new ProxyFactory();\r
assertEquals(c, f2.createClass());\r
ProxyFactory f3 = new ProxyFactory();\r
f3.setSuperclass(Cache1.class);\r
- f3.setHandler(new Interceptor1());\r
+ f3.setHandler(new Interceptor1()); // deprecated\r
assertFalse(c == f3.createClass());\r
+ ProxyFactory.useCache = true;\r
ProxyFactory f4 = new ProxyFactory();\r
f4.setSuperclass(Cache1.class);\r
f4.setInterfaces(new Class[] { Cache2.class });\r