1   /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.intercept.method;
17  
18  import junit.framework.TestCase;
19  
20  import org.acegisecurity.util.SimpleMethodInvocation;
21  
22  import org.aopalliance.intercept.MethodInvocation;
23  
24  
25  /**
26   * Tests {@link AbstractMethodDefinitionSource} and associated {@link ConfigAttributeDefinition}.
27   *
28   * @author Ben Alex
29   * @version $Id: AbstractMethodDefinitionSourceTests.java 1496 2006-05-23 13:38:33Z benalex $
30   */
31  public class AbstractMethodDefinitionSourceTests extends TestCase {
32      //~ Constructors ===================================================================================================
33  
34      public AbstractMethodDefinitionSourceTests() {
35          super();
36      }
37  
38      public AbstractMethodDefinitionSourceTests(String arg0) {
39          super(arg0);
40      }
41  
42      //~ Methods ========================================================================================================
43  
44      public static void main(String[] args) {
45          junit.textui.TestRunner.run(AbstractMethodDefinitionSourceTests.class);
46      }
47  
48      public final void setUp() throws Exception {
49          super.setUp();
50      }
51  
52      public void testDoesNotSupportAnotherObject() {
53          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false, true);
54          assertFalse(mds.supports(String.class));
55      }
56  
57      public void testGetAttributesForANonMethodInvocation() {
58          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false, true);
59  
60          try {
61              mds.getAttributes(new String());
62              fail("Should have thrown IllegalArgumentException");
63          } catch (IllegalArgumentException expected) {
64              assertTrue(true);
65          }
66      }
67  
68      public void testGetAttributesForANullObject() {
69          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false, true);
70  
71          try {
72              mds.getAttributes(null);
73              fail("Should have thrown IllegalArgumentException");
74          } catch (IllegalArgumentException expected) {
75              assertTrue(true);
76          }
77      }
78  
79      public void testGetAttributesForMethodInvocation() {
80          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false, true);
81  
82          try {
83              mds.getAttributes(new SimpleMethodInvocation());
84              fail("Should have thrown UnsupportedOperationException");
85          } catch (UnsupportedOperationException expected) {
86              assertTrue(true);
87          }
88      }
89  
90      public void testSupportsMethodInvocation() {
91          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false, true);
92          assertTrue(mds.supports(MethodInvocation.class));
93      }
94  }