### Question:
PrivilegesGrantor { public void grantSelectPrivileges(String dbName, String tableName) { log.info("Granting Public Select Privileges to the table: " + tableName); try { if (isSelectPrivilegeGranted(dbName, tableName)) { log.info("Skipping Granting Public privileges, the privilege is already granted on the table: " + tableName); } else { PrivilegeBag privilegeBag = new PrivilegeBag(); privilegeBag.addToPrivileges(getPublicSelectPrivilege(dbName, tableName)); client.grant_privileges(privilegeBag); log.info("Successfully granted Public Select Privileges to the table: " + tableName); } } catch (TException e) { throw new HiveClientException(("Error Granting Public Select Privileges to the table: " + tableName), e); } } PrivilegesGrantor(IMetaStoreClient client); void grantSelectPrivileges(String dbName, String tableName); boolean isSelectPrivilegeGranted(String dbName, String tableName);  }### Answer:
@Test public void testGrantSelectPrivilegesToPublic() throws TException { List<HiveObjectPrivilege> hiveObjectPrivilegeList = hive .client() .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, getHiveObjectRef()); assertEquals(0, hiveObjectPrivilegeList.size()); privilegesGrantor.grantSelectPrivileges(DB_NAME, TABLE_NAME); hiveObjectPrivilegeList = hive .client() .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, getHiveObjectRef()); assertEquals(1, hiveObjectPrivilegeList.size()); HiveObjectPrivilege hiveObjectPrivilege = hiveObjectPrivilegeList.get(0); assertEquals(Privilege.SELECT.toString(), hiveObjectPrivilege.getGrantInfo().getPrivilege()); assertEquals(Grantor.APIARY_PRIVILEGE_GRANTOR.toString(), hiveObjectPrivilege.getGrantInfo().getGrantor()); assertEquals(false, hiveObjectPrivilege.getGrantInfo().isGrantOption()); assertEquals(PrincipalType.ROLE, hiveObjectPrivilege.getGrantInfo().getGrantorType()); assertEquals(PrincipalType.ROLE, hiveObjectPrivilege.getPrincipalType()); }
@Test(expected = HiveClientException.class) public void testAddingPrivilegesFailure() { privilegesGrantor.grantSelectPrivileges(DB_NAME, null); }