    1   /* Copyright 2004 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
    27   * ConfigAttributeDefinition}.
    28   *
    29   * @author Ben Alex
    30   * @version $Id: AbstractMethodDefinitionSourceTests.java,v 1.3 2005/11/25 04:17:24 benalex Exp $
    31   */
    32  public class AbstractMethodDefinitionSourceTests extends TestCase {
    33      //~ Constructors ===========================================================
    34
    35      public AbstractMethodDefinitionSourceTests() {
    36          super();
    37      }
    38
    39      public AbstractMethodDefinitionSourceTests(String arg0) {
    40          super(arg0);
    41      }
    42
    43      //~ Methods ================================================================
    44
    45      public final void setUp() throws Exception {
    46          super.setUp();
    47      }
    48
    49      public static void main(String[] args) {
    50          junit.textui.TestRunner.run(AbstractMethodDefinitionSourceTests.class);
    51      }
    52
    53      public void testDoesNotSupportAnotherObject() {
    54          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false,
    55                  true);
    56          assertFalse(mds.supports(String.class));
    57      }
    58
    59      public void testGetAttributesForANonMethodInvocation() {
    60          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false,
    61                  true);
    62
    63          try {
    64              mds.getAttributes(new String());
    65              fail("Should have thrown IllegalArgumentException");
    66          } catch (IllegalArgumentException expected) {
    67              assertTrue(true);
    68          }
    69      }
    70
    71      public void testGetAttributesForANullObject() {
    72          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false,
    73                  true);
    74
    75          try {
    76              mds.getAttributes(null);
    77              fail("Should have thrown IllegalArgumentException");
    78          } catch (IllegalArgumentException expected) {
    79              assertTrue(true);
    80          }
    81      }
    82
    83      public void testGetAttributesForMethodInvocation() {
    84          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false,
    85                  true);
    86
    87          try {
    88              mds.getAttributes(new SimpleMethodInvocation());
    89              fail("Should have thrown UnsupportedOperationException");
    90          } catch (UnsupportedOperationException expected) {
    91              assertTrue(true);
    92          }
    93      }
    94
    95      public void testSupportsMethodInvocation() {
    96          MockMethodDefinitionSource mds = new MockMethodDefinitionSource(false,
    97                  true);
    98          assertTrue(mds.supports(MethodInvocation.class));
    99      }
    100 }