@Test
  public void testEquals() throws Exception {
    Permission p1 = Permission.newBuilder(TEST_TABLE).withActions(Permission.Action.READ).build();
    Permission p2 = Permission.newBuilder(TEST_TABLE).withActions(Permission.Action.READ).build();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_TABLE)
      .withActions(TablePermission.Action.READ, TablePermission.Action.WRITE).build();
    p2 = Permission.newBuilder(TEST_TABLE)
      .withActions(TablePermission.Action.WRITE, TablePermission.Action.READ).build();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_TABLE).withFamily(TEST_FAMILY)
      .withActions(TablePermission.Action.READ, TablePermission.Action.WRITE).build();
    p2 = Permission.newBuilder(TEST_TABLE).withFamily(TEST_FAMILY)
      .withActions(TablePermission.Action.WRITE, TablePermission.Action.READ).build();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_TABLE).withFamily(TEST_FAMILY).withQualifier(TEST_QUALIFIER)
      .withActions(TablePermission.Action.READ, TablePermission.Action.WRITE).build();
    p2 = Permission.newBuilder(TEST_TABLE).withFamily(TEST_FAMILY).withQualifier(TEST_QUALIFIER)
      .withActions(TablePermission.Action.WRITE, TablePermission.Action.READ).build();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_TABLE).withActions(TablePermission.Action.READ).build();
    p2 = Permission.newBuilder(TEST_TABLE).withFamily(TEST_FAMILY)
      .withActions(TablePermission.Action.READ).build();
    assertFalse(p1.equals(p2));
    assertFalse(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_TABLE).withActions(TablePermission.Action.READ).build();
    p2 = Permission.newBuilder(TEST_TABLE).withActions(TablePermission.Action.WRITE).build();
    assertFalse(p1.equals(p2));
    assertFalse(p2.equals(p1));
    p2 = Permission.newBuilder(TEST_TABLE)
      .withActions(TablePermission.Action.READ, TablePermission.Action.WRITE).build();
    assertFalse(p1.equals(p2));
    assertFalse(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_TABLE).withActions(TablePermission.Action.READ).build();
    p2 = Permission.newBuilder(TEST_TABLE2).withActions(TablePermission.Action.READ).build();
    assertFalse(p1.equals(p2));
    assertFalse(p2.equals(p1));

    p1 = Permission.newBuilder(TEST_NAMESPACE).withActions(TablePermission.Action.READ).build();
    p2 = Permission.newBuilder(TEST_NAMESPACE).withActions(TablePermission.Action.READ).build();
    assertEquals(p1, p2);

    p1 = Permission.newBuilder(TEST_NAMESPACE).withActions(TablePermission.Action.READ).build();
    p2 = Permission.newBuilder(TEST_NAMESPACE2).withActions(TablePermission.Action.READ).build();
    assertFalse(p1.equals(p2));
    assertFalse(p2.equals(p1));
  }
The PermissionStorage.addUserPermission may throw exception before closing the table.
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java