1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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*/ 22 23package tests.java.security; 24 25import dalvik.annotation.TestTargetClass; 26import dalvik.annotation.TestTargets; 27import dalvik.annotation.TestLevel; 28import dalvik.annotation.TestTargetNew; 29 30import java.security.AllPermission; 31import java.security.BasicPermission; 32import java.security.PermissionCollection; 33import java.security.UnresolvedPermission; 34 35import junit.framework.TestCase; 36@TestTargetClass(AllPermission.class) 37/** 38 * Tests for <code>AllPermission</code> 39 * 40 */ 41public class AllPermissionTest extends TestCase { 42 43 public static void main(String[] args) { 44 junit.textui.TestRunner.run(AllPermissionTest.class); 45 } 46 47 /** 48 * Test all constructors: an object is created, name and actions are ignored 49 */ 50 @TestTargets({ 51 @TestTargetNew( 52 level = TestLevel.COMPLETE, 53 notes = "", 54 method = "AllPermission", 55 args = {} 56 ), 57 @TestTargetNew( 58 level = TestLevel.COMPLETE, 59 notes = "", 60 method = "AllPermission", 61 args = {java.lang.String.class, java.lang.String.class} 62 ) 63 }) 64 public void testCtor() 65 { 66 AllPermission a1 = new AllPermission(); 67 assertEquals("<all permissions>", a1.getName()); 68 assertEquals("<all actions>", a1.getActions()); 69 70 a1 = new AllPermission("sdfsdfwe&^$", "*&IUGJKHVB764"); 71 assertEquals("<all permissions>", a1.getName()); 72 assertEquals("<all actions>", a1.getActions()); 73 74 a1 = new AllPermission(null, ""); 75 assertEquals("<all permissions>", a1.getName()); 76 assertEquals("<all actions>", a1.getActions()); 77 } 78 79 /** Any of AllPermission instances are equal and have the same hash code */ 80 @TestTargetNew( 81 level = TestLevel.COMPLETE, 82 notes = "", 83 method = "equals", 84 args = {java.lang.Object.class} 85 ) 86 public void testEquals() 87 { 88 AllPermission a1 = new AllPermission(); 89 AllPermission a2 = new AllPermission(); 90 assertTrue(a1.equals(a2)); 91 assertTrue(a1.hashCode() == a2.hashCode()); 92 assertFalse(a1.equals(null)); 93 assertFalse(a1.equals(new BasicPermission("hgf"){})); 94 } 95 96 /** AllPermission implies any other permission */ 97 @TestTargetNew( 98 level = TestLevel.PARTIAL, 99 notes = "Null parameter checking missed", 100 method = "implies", 101 args = {java.security.Permission.class} 102 ) 103 public void testImplies() 104 { 105 AllPermission a1 = new AllPermission(); 106 assertTrue(a1.implies(new AllPermission())); 107 assertTrue(a1.implies(new BasicPermission("2323"){})); 108 assertTrue(a1.implies(new UnresolvedPermission("2323", "", "", null))); 109 } 110 111 /** newPermissionCollection() returns a new AllPermissionCollection on every invocation. */ 112 @TestTargetNew( 113 level = TestLevel.COMPLETE, 114 notes = "", 115 method = "newPermissionCollection", 116 args = {} 117 ) 118 public void testCollection() 119 { 120 AllPermission a1 = new AllPermission(); 121 PermissionCollection pc1 = a1.newPermissionCollection(); 122 PermissionCollection pc2 = a1.newPermissionCollection(); 123// assertTrue((pc1 instanceof AllPermissionCollection) && (pc2 instanceof AllPermissionCollection)); 124 assertNotSame(pc1, pc2); 125 } 126} 127