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 org.apache.harmony.security.tests.java.security;
22:
23: import java.security.*;
24: import java.util.*;
25:
26: import junit.framework.TestCase;
27:
28: /**
29: * Tests for <code>PermissionCollection</code>
30: *
31: */
32:
33: public class PermissionCollectionTest extends TestCase {
34:
35: public static void main(String[] args) {
36: junit.textui.TestRunner.run(PermissionCollectionTest.class);
37: }
38:
39: /**
40: * Constructor for PermissionCollectionTest.
41: * @param arg0
42: */
43: public PermissionCollectionTest(String arg0) {
44: super (arg0);
45: }
46:
47: // Bare extension to instantiate abstract PermissionCollection class
48: private static final class RealPermissionCollection extends
49: PermissionCollection {
50: final private Collection col;
51:
52: public RealPermissionCollection(Collection col) {
53: this .col = col;
54: }
55:
56: public void add(Permission permission) {
57: }
58:
59: public Enumeration elements() {
60: return col == null ? null : Collections.enumeration(col);
61: }
62:
63: public boolean implies(Permission permission) {
64: return false;
65: }
66: }
67:
68: /** Test read-only flag. Should be false by default and can be set once forever. */
69: public void testReadOnly() {
70: PermissionCollection pc = new RealPermissionCollection(null);
71: assertFalse("should not be read-only by default", pc
72: .isReadOnly());
73: pc.setReadOnly();
74: assertTrue("explicitly set read-only", pc.isReadOnly());
75: pc.setReadOnly();
76: assertTrue("more calls to setReadOnly() should not harm", pc
77: .isReadOnly());
78: }
79: }
|