Search in sources :

Example 1 with MethodInterceptor

use of org.apache.shiro.aop.MethodInterceptor in project shiro by apache.

the class AopAllianceMethodInterceptorAdapterTest method testInvoke.

@Test
public void testInvoke() throws Throwable {
    MethodInvocation allianceInvocation = createMock(MethodInvocation.class);
    MethodInterceptor mockShiroInterceptor = createMock(MethodInterceptor.class);
    expect(mockShiroInterceptor.invoke(anyObject(AopAllianceMethodInvocationAdapter.class))).andAnswer(new IAnswer<Object>() {

        public Object answer() throws Throwable {
            return getCurrentArguments()[0];
        }
    });
    final Object expectedValue = new Object();
    expect(allianceInvocation.proceed()).andReturn(expectedValue);
    replay(mockShiroInterceptor, allianceInvocation);
    AopAllianceMethodInterceptorAdapter underTest = new AopAllianceMethodInterceptorAdapter(mockShiroInterceptor);
    Object invocation = underTest.invoke(allianceInvocation);
    Object value = ((AopAllianceMethodInvocationAdapter) invocation).proceed();
    assertSame("Adapter invocation returned a different value.", expectedValue, value);
    verify(mockShiroInterceptor, allianceInvocation);
}
Also used : MethodInterceptor(org.apache.shiro.aop.MethodInterceptor) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)1 MethodInterceptor (org.apache.shiro.aop.MethodInterceptor)1 Test (org.junit.Test)1