1 8 9 package test.javax.management; 10 11 import java.security.Permission ; 12 import java.security.PermissionCollection ; 13 14 import test.MX4JTestCase; 15 16 19 public class PermissionTestCase extends MX4JTestCase 20 { 21 public PermissionTestCase(String s) 22 { 23 super(s); 24 } 25 26 protected void shouldBeEqual(Permission p1, Permission p2) 27 { 28 if (!p1.equals(p2)) fail("Permission " + p1 + " should be equal to Permission " + p2); 29 if (p1.hashCode() != p2.hashCode()) fail("Permission " + p1 + " should have hashCode equal to Permission " + p2); 30 } 31 32 protected void shouldImply(Permission p1, Permission p2) 33 { 34 if (p1.equals(p2)) 35 { 36 if (!imply(p1, p2)) fail("Permission " + p1 + " should imply Permission " + p2); 38 if (!imply(p2, p1)) fail("Permission " + p2 + " should imply Permission " + p1); 39 } 40 else 41 { 42 if (!imply(p1, p2)) fail("Permission " + p1 + " should imply Permission " + p2); 44 if (imply(p2, p1)) fail("Permission " + p2 + " should not imply Permission " + p1); 45 } 46 } 47 48 protected void shouldNotImply(Permission p1, Permission p2) 49 { 50 if (p1.equals(p2)) fail("Permissions cannot be equal"); 51 if (imply(p1, p2)) fail("Permission " + p1 + " should not imply Permission " + p2); 52 if (imply(p2, p1)) fail("Permission " + p2 + " should not imply Permission " + p1); 53 } 54 55 protected boolean imply(Permission p1, Permission p2) 56 { 57 PermissionCollection pc = p1.newPermissionCollection(); 58 if (pc == null) 59 { 60 return p1.implies(p2); 62 } 63 else 64 { 65 return pc.implies(p2); 66 } 67 } 68 } 69 | Popular Tags |