1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.guice.aop;
20
21 import org.aopalliance.intercept.MethodInvocation;
22 import org.apache.shiro.aop.MethodInterceptor;
23 import org.easymock.IAnswer;
24 import org.junit.Test;
25
26 import static org.easymock.EasyMock.*;
27 import static org.junit.Assert.assertSame;
28
29
30 public class AopAllianceMethodInterceptorAdapterTest {
31 @Test
32 public void testInvoke() throws Throwable {
33 MethodInvocation allianceInvocation = createMock(MethodInvocation.class);
34 MethodInterceptor mockShiroInterceptor = createMock(MethodInterceptor.class);
35 expect(mockShiroInterceptor.invoke(anyObject(AopAllianceMethodInvocationAdapter.class))).andAnswer(new IAnswer<Object>() {
36 public Object answer() throws Throwable {
37 return getCurrentArguments()[0];
38 }
39 });
40 final Object expectedValue = new Object();
41 expect(allianceInvocation.proceed()).andReturn(expectedValue);
42
43 replay(mockShiroInterceptor, allianceInvocation);
44
45 AopAllianceMethodInterceptorAdapter underTest = new AopAllianceMethodInterceptorAdapter(mockShiroInterceptor);
46 Object invocation = underTest.invoke(allianceInvocation);
47 Object value = ((AopAllianceMethodInvocationAdapter) invocation).proceed();
48
49 assertSame("Adapter invocation returned a different value.", expectedValue, value);
50
51 verify(mockShiroInterceptor, allianceInvocation);
52 }
53 }