Program: 5982
Project: 5982
Buggy source:
@Test public void testRBAC() throws Exception {
  Authorizer authorizer=get();
  Role admins=new Role("String_Node_Str");
  Role engineers=new Role("String_Node_Str");
  authorizer.createRole(admins);
  authorizer.createRole(engineers);
  Set<Role> roles=authorizer.listAllRoles();
  Assert.assertEquals(Collections.singleton(Arrays.asList(admins,engineers)),roles);
  try {
    authorizer.createRole(admins);
    Assert.fail(String.format("String_Node_Str",admins.getName()));
  }
 catch (  RoleAlreadyExistsException expected) {
  }
  authorizer.dropRole(admins);
  roles=authorizer.listAllRoles();
  Assert.assertEquals(Collections.singleton(engineers),roles);
  try {
    authorizer.dropRole(admins);
    Assert.fail(String.format("String_Node_Str",admins.getName()));
  }
 catch (  RoleNotFoundException expected) {
  }
  Principal spiderman=new Principal("String_Node_Str",Principal.PrincipalType.USER);
  authorizer.addRoleToPrincipal(engineers,spiderman);
  try {
    authorizer.addRoleToPrincipal(admins,spiderman);
    Assert.fail(String.format("String_Node_Str",admins,spiderman));
  }
 catch (  RoleNotFoundException expected) {
  }
  Assert.assertEquals(Collections.singleton(engineers),authorizer.listRoles(spiderman));
  NamespaceId ns1=Ids.namespace("String_Node_Str");
  verifyAuthFailure(ns1,spiderman,Action.READ);
  authorizer.grant(ns1,engineers,Collections.singleton(Action.READ));
  authorizer.enforce(ns1,spiderman,Action.READ);
  Assert.assertEquals((Collections.singleton(new Privilege(ns1,Action.READ))),authorizer.listPrivileges(spiderman));
  authorizer.revoke(ns1,engineers,(Collections.singleton(Action.READ)));
  Assert.assertEquals(Collections.EMPTY_SET,authorizer.listPrivileges(spiderman));
  verifyAuthFailure(ns1,spiderman,Action.READ);
  authorizer.removeRoleFromPrincipal(engineers,spiderman);
  Assert.assertEquals(Collections.EMPTY_SET,authorizer.listRoles(spiderman));
  try {
    authorizer.removeRoleFromPrincipal(admins,spiderman);
    Assert.fail(String.format("String_Node_Str",admins,spiderman));
  }
 catch (  RoleNotFoundException expected) {
  }
}

Fixed version (ground truth):
@Test public void testRBAC() throws Exception {
  Authorizer authorizer=get();
  Role admins=new Role("String_Node_Str");
  Role engineers=new Role("String_Node_Str");
  authorizer.createRole(admins);
  authorizer.createRole(engineers);
  Set<Role> roles=authorizer.listAllRoles();
  Set<Role> expectedRoles=new HashSet<>();
  expectedRoles.add(admins);
  expectedRoles.add(engineers);
  Assert.assertEquals(expectedRoles,roles);
  try {
    authorizer.createRole(admins);
    Assert.fail(String.format("String_Node_Str",admins.getName()));
  }
 catch (  RoleAlreadyExistsException expected) {
  }
  authorizer.dropRole(admins);
  roles=authorizer.listAllRoles();
  Assert.assertEquals(Collections.singleton(engineers),roles);
  try {
    authorizer.dropRole(admins);
    Assert.fail(String.format("String_Node_Str",admins.getName()));
  }
 catch (  RoleNotFoundException expected) {
  }
  Principal spiderman=new Principal("String_Node_Str",Principal.PrincipalType.USER);
  authorizer.addRoleToPrincipal(engineers,spiderman);
  try {
    authorizer.addRoleToPrincipal(admins,spiderman);
    Assert.fail(String.format("String_Node_Str",admins,spiderman));
  }
 catch (  RoleNotFoundException expected) {
  }
  Assert.assertEquals(Collections.singleton(engineers),authorizer.listRoles(spiderman));
  NamespaceId ns1=new NamespaceId("String_Node_Str");
  verifyAuthFailure(ns1,spiderman,Action.READ);
  authorizer.grant(ns1,engineers,Collections.singleton(Action.READ));
  authorizer.enforce(ns1,spiderman,Action.READ);
  Assert.assertEquals(Collections.singleton(new Privilege(ns1,Action.READ)),authorizer.listPrivileges(spiderman));
  authorizer.revoke(ns1,engineers,Collections.singleton(Action.READ));
  Assert.assertEquals(Collections.EMPTY_SET,authorizer.listPrivileges(spiderman));
  verifyAuthFailure(ns1,spiderman,Action.READ);
  authorizer.removeRoleFromPrincipal(engineers,spiderman);
  Assert.assertEquals(Collections.EMPTY_SET,authorizer.listRoles(spiderman));
  try {
    authorizer.removeRoleFromPrincipal(admins,spiderman);
    Assert.fail(String.format("String_Node_Str",admins,spiderman));
  }
 catch (  RoleNotFoundException expected) {
  }
}