01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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: * Tests {@link GrantedAuthorityImpl}.
22: *
23: * @author Ben Alex
24: * @version $Id: GrantedAuthorityImplTests.java 1496 2006-05-23 13:38:33Z benalex $
25: */
26: public class GrantedAuthorityImplTests extends TestCase {
27: //~ Constructors ===================================================================================================
28:
29: public GrantedAuthorityImplTests() {
30: super ();
31: }
32:
33: public GrantedAuthorityImplTests(String arg0) {
34: super (arg0);
35: }
36:
37: //~ Methods ========================================================================================================
38:
39: public static void main(String[] args) {
40: junit.textui.TestRunner.run(GrantedAuthorityImplTests.class);
41: }
42:
43: public final void setUp() throws Exception {
44: super .setUp();
45: }
46:
47: public void testObjectEquals() throws Exception {
48: GrantedAuthorityImpl auth1 = new GrantedAuthorityImpl("TEST");
49: GrantedAuthorityImpl auth2 = new GrantedAuthorityImpl("TEST");
50: assertEquals(auth1, auth2);
51:
52: String authString1 = "TEST";
53: assertEquals(auth1, authString1);
54:
55: String authString2 = "NOT_EQUAL";
56: assertTrue(!auth1.equals(authString2));
57:
58: GrantedAuthorityImpl auth3 = new GrantedAuthorityImpl(
59: "NOT_EQUAL");
60: assertTrue(!auth1.equals(auth3));
61:
62: MockGrantedAuthorityImpl mock1 = new MockGrantedAuthorityImpl(
63: "TEST");
64: assertEquals(auth1, mock1);
65:
66: MockGrantedAuthorityImpl mock2 = new MockGrantedAuthorityImpl(
67: "NOT_EQUAL");
68: assertTrue(!auth1.equals(mock2));
69:
70: Integer int1 = new Integer(222);
71: assertTrue(!auth1.equals(int1));
72: }
73:
74: public void testToString() {
75: GrantedAuthorityImpl auth = new GrantedAuthorityImpl("TEST");
76: assertEquals("TEST", auth.toString());
77: }
78:
79: //~ Inner Classes ==================================================================================================
80:
81: private class MockGrantedAuthorityImpl implements GrantedAuthority {
82: private String role;
83:
84: public MockGrantedAuthorityImpl(String role) {
85: this .role = role;
86: }
87:
88: private MockGrantedAuthorityImpl() {
89: super ();
90: }
91:
92: public String getAuthority() {
93: return this.role;
94: }
95: }
96: }
|