1 16 17 package org.springframework.aop.framework; 18 19 import java.lang.reflect.Method ; 20 import java.util.LinkedList ; 21 import java.util.List ; 22 23 import junit.framework.TestCase; 24 import org.aopalliance.intercept.MethodInterceptor; 25 import org.aopalliance.intercept.MethodInvocation; 26 27 import org.springframework.beans.TestBean; 28 29 34 public class MethodInvocationTests extends TestCase { 35 36 44 45 70 71 public void testValidInvocation() throws Throwable { 72 Method m = Object .class.getMethod("hashCode", (Class []) null); 73 Object proxy = new Object (); 74 final Object returnValue = new Object (); 75 List is = new LinkedList (); 76 is.add(new MethodInterceptor() { 77 public Object invoke(MethodInvocation invocation) throws Throwable { 78 return returnValue; 79 } 80 }); 81 ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, null, m, null, null, is ); 84 Object rv = invocation.proceed(); 85 assertTrue("correct response", rv == returnValue); 86 } 87 88 91 public void testToStringDoesntHitTarget() throws Throwable { 92 Object target = new TestBean() { 93 public String toString() { 94 throw new UnsupportedOperationException ("toString"); 95 } 96 }; 97 final Object returnValue = new Object (); 98 List is = new LinkedList (); 99 100 Method m = Object .class.getMethod("hashCode", (Class []) null); 101 Object proxy = new Object (); 102 ReflectiveMethodInvocation invocation = 103 new ReflectiveMethodInvocation(proxy, target, m, null, null, is); 104 105 invocation.toString(); 108 } 109 110 } 111 | Popular Tags |