01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package test.javax.management;
10:
11: import java.security.Permission;
12: import java.security.PermissionCollection;
13:
14: import test.MX4JTestCase;
15:
16: /**
17: * @version $Revision: 1.3 $
18: */
19: public class PermissionTestCase extends MX4JTestCase {
20: public PermissionTestCase(String s) {
21: super (s);
22: }
23:
24: protected void shouldBeEqual(Permission p1, Permission p2) {
25: if (!p1.equals(p2))
26: fail("Permission " + p1 + " should be equal to Permission "
27: + p2);
28: if (p1.hashCode() != p2.hashCode())
29: fail("Permission " + p1
30: + " should have hashCode equal to Permission " + p2);
31: }
32:
33: protected void shouldImply(Permission p1, Permission p2) {
34: if (p1.equals(p2)) {
35: // Test identity
36: if (!imply(p1, p2))
37: fail("Permission " + p1 + " should imply Permission "
38: + p2);
39: if (!imply(p2, p1))
40: fail("Permission " + p2 + " should imply Permission "
41: + p1);
42: } else {
43: // Test antisymmetry
44: if (!imply(p1, p2))
45: fail("Permission " + p1 + " should imply Permission "
46: + p2);
47: if (imply(p2, p1))
48: fail("Permission " + p2
49: + " should not imply Permission " + p1);
50: }
51: }
52:
53: protected void shouldNotImply(Permission p1, Permission p2) {
54: if (p1.equals(p2))
55: fail("Permissions cannot be equal");
56: if (imply(p1, p2))
57: fail("Permission " + p1 + " should not imply Permission "
58: + p2);
59: if (imply(p2, p1))
60: fail("Permission " + p2 + " should not imply Permission "
61: + p1);
62: }
63:
64: protected boolean imply(Permission p1, Permission p2) {
65: PermissionCollection pc = p1.newPermissionCollection();
66: if (pc == null) {
67: // No PermissionCollection provided, go directly to the Permission
68: return p1.implies(p2);
69: } else {
70: return pc.implies(p2);
71: }
72: }
73: }
|