View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.shiro.guice.aop;
20  
21  import org.aopalliance.intercept.MethodInvocation;
22  import org.junit.Test;
23  
24  import java.lang.reflect.Method;
25  
26  import static org.easymock.EasyMock.*;
27  import static org.junit.Assert.assertSame;
28  
29  /**
30   * Created by IntelliJ IDEA.
31   * User: jbunting
32   * Date: 6/18/11
33   * Time: 5:02 PM
34   * To change this template use File | Settings | File Templates.
35   */
36  public class AopAllianceMethodInvocationAdapterTest {
37      @Test
38      public void testGetMethod() throws Exception {
39          MethodInvocation mock = createMock(MethodInvocation.class);
40          Method method = AopAllianceMethodInvocationAdapterTest.class.getMethod("testGetMethod");
41          expect(mock.getMethod()).andReturn(method);
42          AopAllianceMethodInvocationAdapter underTest = new AopAllianceMethodInvocationAdapter(mock);
43  
44          replay(mock);
45  
46          assertSame(method, underTest.getMethod());
47  
48          verify(mock);
49      }
50  
51      @Test
52      public void testGetArguments() throws Exception {
53          MethodInvocation mock = createMock(MethodInvocation.class);
54          Object[] args = new Object[0];
55          expect(mock.getArguments()).andReturn(args);
56          AopAllianceMethodInvocationAdapter underTest = new AopAllianceMethodInvocationAdapter(mock);
57  
58          replay(mock);
59  
60          assertSame(args, underTest.getArguments());
61  
62          verify(mock);
63      }
64  
65      @Test
66      public void testProceed() throws Throwable {
67          MethodInvocation mock = createMock(MethodInvocation.class);
68          Object value = new Object();
69          expect(mock.proceed()).andReturn(value);
70          AopAllianceMethodInvocationAdapter underTest = new AopAllianceMethodInvocationAdapter(mock);
71  
72          replay(mock);
73  
74          assertSame(value, underTest.proceed());
75  
76          verify(mock);
77      }
78  
79      @Test
80      public void testGetThis() throws Exception {
81          MethodInvocation mock = createMock(MethodInvocation.class);
82          Object value = new Object();
83          expect(mock.getThis()).andReturn(value);
84          AopAllianceMethodInvocationAdapter underTest = new AopAllianceMethodInvocationAdapter(mock);
85  
86          replay(mock);
87  
88          assertSame(value, underTest.getThis());
89  
90          verify(mock);
91      }
92  }