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;
17  
18  import junit.framework.TestCase;
19  
20  
21  /**
22   * Tests {@link GrantedAuthorityImpl}.
23   *
24   * @author Ben Alex
25   * @version $Id: GrantedAuthorityImplTests.java 1496 2006-05-23 13:38:33Z benalex $
26   */
27  public class GrantedAuthorityImplTests extends TestCase {
28      //~ Constructors ===================================================================================================
29  
30      public GrantedAuthorityImplTests() {
31          super();
32      }
33  
34      public GrantedAuthorityImplTests(String arg0) {
35          super(arg0);
36      }
37  
38      //~ Methods ========================================================================================================
39  
40      public static void main(String[] args) {
41          junit.textui.TestRunner.run(GrantedAuthorityImplTests.class);
42      }
43  
44      public final void setUp() throws Exception {
45          super.setUp();
46      }
47  
48      public void testObjectEquals() throws Exception {
49          GrantedAuthorityImpl auth1 = new GrantedAuthorityImpl("TEST");
50          GrantedAuthorityImpl auth2 = new GrantedAuthorityImpl("TEST");
51          assertEquals(auth1, auth2);
52  
53          String authString1 = "TEST";
54          assertEquals(auth1, authString1);
55  
56          String authString2 = "NOT_EQUAL";
57          assertTrue(!auth1.equals(authString2));
58  
59          GrantedAuthorityImpl auth3 = new GrantedAuthorityImpl("NOT_EQUAL");
60          assertTrue(!auth1.equals(auth3));
61  
62          MockGrantedAuthorityImpl mock1 = new MockGrantedAuthorityImpl("TEST");
63          assertEquals(auth1, mock1);
64  
65          MockGrantedAuthorityImpl mock2 = new MockGrantedAuthorityImpl("NOT_EQUAL");
66          assertTrue(!auth1.equals(mock2));
67  
68          Integer int1 = new Integer(222);
69          assertTrue(!auth1.equals(int1));
70      }
71  
72      public void testToString() {
73          GrantedAuthorityImpl auth = new GrantedAuthorityImpl("TEST");
74          assertEquals("TEST", auth.toString());
75      }
76  
77      //~ Inner Classes ==================================================================================================
78  
79      private class MockGrantedAuthorityImpl implements GrantedAuthority {
80          private String role;
81  
82          public MockGrantedAuthorityImpl(String role) {
83              this.role = role;
84          }
85  
86          private MockGrantedAuthorityImpl() {
87              super();
88          }
89  
90          public String getAuthority() {
91              return this.role;
92          }
93      }
94  }