1 10 package org.nanocontainer.aop.dynaop; 11 12 import dynaop.Invocation; 13 import dynaop.Proxy; 14 import dynaop.ProxyContext; 15 import org.aopalliance.intercept.MethodInvocation; 16 import org.jmock.Mock; 17 import org.jmock.MockObjectTestCase; 18 19 import java.lang.reflect.Method ; 20 21 24 public class InvocationAdapterTestCase extends MockObjectTestCase { 25 26 private Mock mockInvocation = mock(Invocation.class); 27 private MethodInvocation invocationAdapter = new InvocationAdapter((Invocation) mockInvocation.proxy()); 28 private Mock mockProxy = mock(Proxy.class); 29 private Mock mockProxyContext = mock(ProxyContext.class); 30 31 public void testProceed() throws Throwable { 32 mockInvocation.expects(once()).method("proceed").will(returnValue("result")); 33 Object result = invocationAdapter.proceed(); 34 assertEquals("result", result); 35 } 36 37 public void testGetArguments() { 38 Object [] args = {"a", "b", "c"}; 39 mockInvocation.expects(once()).method("getArguments").will(returnValue(args)); 40 Object [] actualArgs = invocationAdapter.getArguments(); 41 assertEquals(args, actualArgs); 42 } 43 44 public void testGetMethod() throws SecurityException , NoSuchMethodException { 45 Method method = String .class.getMethod("length", new Class []{}); 46 mockInvocation.expects(once()).method("getMethod").will(returnValue(method)); 47 Method actualMethod = invocationAdapter.getMethod(); 48 assertEquals(method, actualMethod); 49 } 50 51 public void testGetStaticPart() throws SecurityException , NoSuchMethodException { 52 Method method = String .class.getMethod("length", new Class []{}); 53 mockInvocation.expects(once()).method("getMethod").will(returnValue(method)); 54 Object staticPart = invocationAdapter.getStaticPart(); 55 assertEquals(method, staticPart); 56 } 57 58 public void testGetThis() { 59 mockInvocation.expects(once()).method("getProxy").will(returnValue(mockProxy.proxy())); 60 mockProxy.expects(once()).method("getProxyContext").will(returnValue(mockProxyContext.proxy())); 61 mockProxyContext.expects(once()).method("unwrap").will(returnValue("target")); 62 Object target = invocationAdapter.getThis(); 63 assertEquals("target", target); 64 } 65 66 } | Popular Tags |