1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity;
17
18 import junit.framework.TestCase;
19
20
21
22
23
24
25
26
27 public class GrantedAuthorityImplTests extends TestCase {
28
29
30 public GrantedAuthorityImplTests() {
31 super();
32 }
33
34 public GrantedAuthorityImplTests(String arg0) {
35 super(arg0);
36 }
37
38
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
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 }