@Test
public void testRemovePrincipalFromAllRolesDeleteUserException() {

    List<PrincipalRole> roles = new ArrayList<>();
    PrincipalRole role1 = new PrincipalRole();
    role1.setDomainName("dom1");
    role1.setRoleName("role1");
    roles.add(role1);
    PrincipalRole role2 = new PrincipalRole();
    role2.setDomainName("dom1");
    role2.setRoleName("role2");
    roles.add(role2);
    ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(conn.listPrincipalRoles(null, "user.joe")).thenReturn(roles);
    Mockito.when(conn.deleteRoleMember("dom1", "role1", "user.joe", adminUser, "unittest"))
            .thenReturn(true);
    Mockito.when(conn.deleteRoleMember("dom1", "role2", "user.joe", adminUser, "unittest"))
            .thenThrow(new ResourceException(501));
    // we should handle the exception without any errors
    zms.dbService.removePrincipalFromAllRoles(conn, "user.joe", adminUser, "unittest");
}