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 Alexander V. Astapchuk
20* @version $Revision$
21*/
22
23package org.apache.harmony.security.tests.java.security;
24
25import dalvik.annotation.TestTargetClass;
26import dalvik.annotation.TestTargets;
27import dalvik.annotation.TestLevel;
28import dalvik.annotation.TestTargetNew;
29
30import java.security.AccessControlException;
31import java.security.AllPermission;
32import java.security.Permission;
33import java.security.UnresolvedPermission;
34
35import junit.framework.TestCase;
36
37/**
38 * Unit test for AccessControlException.
39 */
40@TestTargetClass(AccessControlException.class)
41public class AccessControlExceptionTest extends TestCase {
42
43    /**
44     * Entry point for standalone run.
45     * @param args command line arguments
46     */
47    public static void main(String[] args) {
48        junit.textui.TestRunner.run(AccessControlExceptionTest.class);
49    }
50
51    /**
52     * Tests AccessControlException(String)
53     */
54    @TestTargetNew(
55        level = TestLevel.PARTIAL_COMPLETE,
56        notes = "",
57        method = "AccessControlException",
58        args = {java.lang.String.class}
59    )
60    public void testAccessControlExceptionString() {
61        new AccessControlException(null);
62        new AccessControlException("Failure");
63    }
64
65    /**
66     * Tests AccessControlException(String, Permission)
67     */
68    @TestTargetNew(
69        level = TestLevel.PARTIAL_COMPLETE,
70        notes = "",
71        method = "AccessControlException",
72        args = {java.lang.String.class, java.security.Permission.class}
73    )
74    public void testAccessControlExceptionStringPermission() {
75        Permission perm = new AllPermission();
76        AccessControlException controlException = new AccessControlException("001", perm);
77        assertEquals("exception message", "001", controlException.getMessage());
78        assertEquals("permission", perm, controlException.getPermission());
79    }
80
81    /**
82     *
83     * Tests AccessControlException.getPermission()
84     */
85    @TestTargetNew(
86        level = TestLevel.COMPLETE,
87        notes = "",
88        method = "getPermission",
89        args = {}
90    )
91    public void testGetPermission() {
92        Permission perm = new UnresolvedPermission("unresolvedType",
93                "unresolvedName", "unresolvedActions", null);
94        AccessControlException ex = new AccessControlException("001", perm);
95        assertSame(ex.getPermission(), perm);
96    }
97}
98