1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.proxy.invoker;
19 import junit.framework.TestCase;
20 import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory;
21 import org.apache.commons.proxy.util.Echo;
22
23 import java.lang.reflect.InvocationHandler;
24 import java.lang.reflect.Method;
25
26 public class TestInvocationHandlerAdapter extends TestCase
27 {
28 public void testMethodInvocation() throws Exception
29 {
30 InvocationHandlerTester tester = new InvocationHandlerTester();
31 final Echo echo = ( Echo ) new JavassistProxyFactory().createInvokerProxy( new InvocationHandlerAdapter( tester ), new Class[] { Echo.class } );
32 echo.echoBack( "hello" );
33 assertEquals( Echo.class.getMethod( "echoBack", new Class[] { String.class } ), tester.method );
34 assertSame( echo, tester.proxy );
35 assertNotNull( tester.arguments );
36 assertEquals( 1, tester.arguments.length );
37 assertEquals( "hello", tester.arguments[0] );
38 }
39
40 private class InvocationHandlerTester implements InvocationHandler
41 {
42 private Object proxy;
43 private Method method;
44 private Object[] arguments;
45
46 public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
47 {
48 this.proxy = proxy;
49 this.method = method;
50 this.arguments = args;
51 return null;
52 }
53 }
54 }