001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.security.tests.java.security;
019:
020: import java.security.AllPermission;
021: import java.security.SecurityPermission;
022:
023: public class AllPermission2Test extends junit.framework.TestCase {
024:
025: /**
026: * @tests java.security.AllPermission#AllPermission()
027: */
028: public void test_Constructor() {
029: // Test for method java.security.AllPermission()
030: AllPermission ap = new AllPermission();
031: assertEquals("Bogus name for AllPermission \"" + ap.getName()
032: + "\".", "<all permissions>", ap.getName());
033: }
034:
035: /**
036: * @tests java.security.AllPermission#AllPermission(java.lang.String,
037: * java.lang.String)
038: */
039: public void test_ConstructorLjava_lang_StringLjava_lang_String() {
040: // Test for method java.security.AllPermission(java.lang.String,
041: // java.lang.String)
042: AllPermission ap = new AllPermission(
043: "Don't remember this stupid name", "or this action");
044: assertEquals("Bogus name for AllPermission \"" + ap.getName()
045: + "\".", "<all permissions>", ap.getName());
046: assertEquals(
047: "AllPermission constructed with actions didn't ignore them.",
048: "<all actions>", ap.getActions());
049: }
050:
051: /**
052: * @tests java.security.AllPermission#equals(java.lang.Object)
053: */
054: public void test_equalsLjava_lang_Object() {
055: // Test for method boolean
056: // java.security.AllPermission.equals(java.lang.Object)
057: assertTrue("Two AllPermissions not equal to each other.",
058: new AllPermission().equals(new AllPermission()));
059: assertTrue("AllPermission equals a SecurityPermission.",
060: !(new AllPermission().equals(new SecurityPermission(
061: "ugh!"))));
062: }
063:
064: /**
065: * @tests java.security.AllPermission#getActions()
066: */
067: public void test_getActions() {
068: AllPermission ap = new AllPermission();
069: // Test for method java.lang.String
070: // java.security.AllPermission.getActions()
071: assertTrue("AllPermission has non-empty actions. ("
072: + ap.getActions() + ")", ap.getActions().equals(
073: "<all actions>"));
074: }
075:
076: /**
077: * @tests java.security.AllPermission#hashCode()
078: */
079: public void test_hashCode() {
080: final int ALLPERMISSION_HASH = 1;
081: // Test for method int java.security.AllPermission.hashCode()
082: AllPermission TestAllPermission = new AllPermission();
083: assertTrue("AllPermission hashCode is wrong. Should have been "
084: + ALLPERMISSION_HASH + " but was "
085: + TestAllPermission.hashCode(), TestAllPermission
086: .hashCode() == ALLPERMISSION_HASH);
087: }
088:
089: /**
090: * @tests java.security.AllPermission#implies(java.security.Permission)
091: */
092: public void test_impliesLjava_security_Permission() {
093: // Test for method boolean
094: // java.security.AllPermission.implies(java.security.Permission)
095: assertTrue("AllPermission does not imply a AllPermission.",
096: new AllPermission().implies(new AllPermission()));
097: assertTrue(
098: "AllPermission does not imply a SecurityPermission.",
099: new AllPermission().implies(new SecurityPermission(
100: "ugh!")));
101: assertTrue("SecurityPermission implies AllPermission.",
102: !(new SecurityPermission("ugh!")
103: .implies(new AllPermission())));
104: }
105: }
|