ClientPermissions { public void removePermission(final String secretName, final Permissions permission) { synchronized (this.secretPermissions) { final Integer previous = this.secretPermissions.get(secretName); if (previous != null) { final Integer updated = (previous & ~permission.getCode()); if (updated == 0) { this.secretPermissions.remove(secretName); } else { this.secretPermissions.put(secretName, updated); } } } } ClientPermissions();  ClientPermissions(final Map<String, Integer> secretPermissions); void addPermission(final String secretName, final Permissions permission); void removePermission(final String secretName, final Permissions permission); boolean hasPermission(final String secretName, final Permissions permission); void clearPermission(final String secretName); void clearAllPermissions();  }
@Test public void testRemovePermission() { ClientPermissions clientPermission = new ClientPermissions(); final String secret1 = "test1"; final String secret2 = "test2"; final String secret3 = "test3"; clientPermission.addPermission(secret1, Permissions.GENERATE); Assert.assertEquals(1, clientPermission.getSecrets().size()); Assert.assertTrue(clientPermission.hasPermission(secret1, Permissions.GENERATE)); Assert.assertFalse(clientPermission.hasPermission(secret2, Permissions.GENERATE)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.DELETE)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.DISABLE)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.ENABLE)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.EXPONENTIATE)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.INFO)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.READ)); clientPermission.removePermission(secret3, Permissions.GENERATE); Assert.assertFalse(clientPermission.hasPermission(secret3, Permissions.GENERATE)); Assert.assertEquals(1, clientPermission.getSecrets().size()); clientPermission.removePermission(secret2, Permissions.GENERATE); Assert.assertFalse(clientPermission.hasPermission(secret2, Permissions.GENERATE)); Assert.assertEquals(1, clientPermission.getSecrets().size()); clientPermission.removePermission(secret1, Permissions.INFO); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.INFO)); Assert.assertEquals(1, clientPermission.getSecrets().size()); Assert.assertTrue(clientPermission.hasPermission(secret1, Permissions.GENERATE)); clientPermission.removePermission(secret1, Permissions.GENERATE); Assert.assertEquals(0, clientPermission.getSecrets().size()); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.GENERATE)); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.GENERATE)); clientPermission.removePermission(secret1, Permissions.GENERATE); Assert.assertEquals(0, clientPermission.getSecrets().size()); Assert.assertFalse(clientPermission.hasPermission(secret1, Permissions.GENERATE)); }