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.Permission;
24: import java.security.PermissionCollection;
25: import java.util.Arrays;
26: import java.util.Collection;
27: import java.util.Collections;
28: import java.util.Enumeration;
29:
30: import junit.framework.TestCase;
31:
32: /**
33: * Tests for <code>PermissionCollection</code>
34: *
35: */
36:
37: public class PermissionCollection_ImplTest extends TestCase {
38: // Bare extension to instantiate abstract PermissionCollection class
39: private static final class RealPermissionCollection extends
40: PermissionCollection {
41: final private Collection col;
42:
43: public RealPermissionCollection(Collection col) {
44: this .col = col;
45: }
46:
47: public void add(Permission permission) {
48: }
49:
50: public Enumeration elements() {
51: return col == null ? null : Collections.enumeration(col);
52: }
53:
54: public boolean implies(Permission permission) {
55: return false;
56: }
57: }
58:
59: /** Test toString() transformation with different elements. */
60: public void testToString() {
61: // no elements
62: PermissionCollection pc = new RealPermissionCollection(null);
63: String super String = pc.getClass().getName() + "@"
64: + Integer.toHexString(pc.hashCode());
65: assertEquals("no elements", super String + " (\n)\n", pc
66: .toString());
67:
68: // several elements
69: pc = new RealPermissionCollection(Arrays.asList(new Object[] {
70: "aaa", "bbb", "ccc" }));
71: super String = pc.getClass().getName() + "@"
72: + Integer.toHexString(pc.hashCode());
73: assertEquals("several elements", super String
74: + " (\n aaa\n bbb\n ccc\n)\n", pc.toString());
75: }
76:
77: }
|