01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Alexey V. Varlamov
20: * @version $Revision$
21: */package java.security;
22:
23: import junit.framework.TestCase;
24:
25: /**
26: * Tests for <code>AllPermission</code>
27: *
28: */
29: public class AllPermissionTest extends TestCase {
30:
31: public static void main(String[] args) {
32: junit.textui.TestRunner.run(AllPermissionTest.class);
33: }
34:
35: /**
36: * Constructor for AllPermissionsTest.
37: * @param arg0
38: */
39: public AllPermissionTest(String arg0) {
40: super (arg0);
41: }
42:
43: /**
44: * Test all constructors: an object is created, name and actions are ignored
45: */
46: public void testCtor() {
47: AllPermission a1 = new AllPermission();
48: assertEquals("<all permissions>", a1.getName());
49: assertEquals("<all actions>", a1.getActions());
50:
51: a1 = new AllPermission("sdfsdfwe&^$", "*&IUGJKHVB764");
52: assertEquals("<all permissions>", a1.getName());
53: assertEquals("<all actions>", a1.getActions());
54:
55: a1 = new AllPermission(null, "");
56: assertEquals("<all permissions>", a1.getName());
57: assertEquals("<all actions>", a1.getActions());
58: }
59:
60: /** Any of AllPermission instances are equal and have the same hash code */
61: public void testEquals() {
62: AllPermission a1 = new AllPermission();
63: AllPermission a2 = new AllPermission();
64: assertTrue(a1.equals(a2));
65: assertTrue(a1.hashCode() == a2.hashCode());
66: assertFalse(a1.equals(null));
67: assertFalse(a1.equals(new BasicPermission("hgf") {
68: }));
69: }
70:
71: /** AllPermission implies any other permission */
72: public void testImplies() {
73: AllPermission a1 = new AllPermission();
74: assertTrue(a1.implies(new AllPermission()));
75: assertTrue(a1.implies(new BasicPermission("2323") {
76: }));
77: assertTrue(a1.implies(new UnresolvedPermission("2323", "", "",
78: null)));
79: }
80:
81: /** newPermissionCollection() returns a new AllPermissionCollection on every invocation. */
82: public void testCollection() {
83: AllPermission a1 = new AllPermission();
84: PermissionCollection pc1 = a1.newPermissionCollection();
85: PermissionCollection pc2 = a1.newPermissionCollection();
86: assertTrue((pc1 instanceof AllPermissionCollection)
87: && (pc2 instanceof AllPermissionCollection));
88: assertNotSame(pc1, pc2);
89: }
90: }
|