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 18package org.apache.harmony.security.tests.java.security; 19 20import java.io.FilePermission; 21import java.security.AccessControlException; 22 23public class AccessControlException2Test extends junit.framework.TestCase { 24 FilePermission filePermission; 25 26 AccessControlException acException; 27 28 AccessControlException acException1; 29 30 /** 31 * @tests java.security.AccessControlException#AccessControlException(java.lang.String) 32 */ 33 public void test_ConstructorLjava_lang_String() { 34 // Test for method 35 // java.security.AccessControlException(java.lang.String) 36 assertTrue("AccessControlException's toString() should have returned " 37 + "'java.security.AccessControlException: test message' but " 38 + "returned: " + acException.toString(), acException.toString() 39 .equals("java.security.AccessControlException: test message")); 40 } 41 42 /** 43 * @tests java.security.AccessControlException#AccessControlException(java.lang.String, 44 * java.security.Permission) 45 */ 46 public void test_ConstructorLjava_lang_StringLjava_security_Permission() { 47 // Test for method 48 // java.security.AccessControlException(java.lang.String, 49 // java.security.Permission) 50 assertTrue("AccessControlException's toString() should have returned " 51 + "'java.security.AccessControlException: test message " 52 + "(java.io.FilePermission /* read)' but returned: " 53 + acException1.toString(), acException1.toString().equals( 54 "java.security.AccessControlException: test message")); 55 } 56 57 /** 58 * @tests java.security.AccessControlException#getPermission() 59 */ 60 public void test_getPermission() { 61 // Test for method java.security.Permission 62 // java.security.AccessControlException.getPermission() 63 // make sure getPermission returns null when it's not set 64 assertNull( 65 "getPermission should have returned null if no permission was set", 66 acException.getPermission()); 67 assertTrue( 68 "getPermission should have returned the permission we assigned to it", 69 acException1.getPermission() == filePermission); 70 } 71 72 /** 73 * Sets up the fixture, for example, open a network connection. This method 74 * is called before a test is executed. 75 */ 76 protected void setUp() { 77 filePermission = new FilePermission("/*", "read"); 78 acException = new AccessControlException("test message"); 79 acException1 = new AccessControlException("test message", 80 filePermission); 81 } 82}