@Test
public void testFilterAclEntriesByAclSpec() throws AclException {

  List<AclEntry> existing = new ImmutableList.Builder<AclEntry>()
    .add(aclEntry(ACCESS, USER, ALL))
    .add(aclEntry(ACCESS, USER, "bruce", READ_WRITE))
    .add(aclEntry(ACCESS, USER, "diana", READ_EXECUTE))
    .add(aclEntry(ACCESS, GROUP, READ))
    .add(aclEntry(ACCESS, GROUP, "sales", READ_EXECUTE))
    .add(aclEntry(ACCESS, GROUP, "execs", READ_WRITE))
    .add(aclEntry(ACCESS, MASK, ALL))
    .add(aclEntry(ACCESS, OTHER, READ))
    .build();
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "diana"),
    aclEntry(ACCESS, GROUP, "sales"));
  List<AclEntry> expected = new ImmutableList.Builder<AclEntry>()
    .add(aclEntry(ACCESS, USER, ALL))
    .add(aclEntry(ACCESS, USER, "bruce", READ_WRITE))
    .add(aclEntry(ACCESS, GROUP, READ))
    .add(aclEntry(ACCESS, GROUP, "execs", READ_WRITE))
    .add(aclEntry(ACCESS, MASK, READ_WRITE))
    .add(aclEntry(ACCESS, OTHER, READ))
    .build();
  assertEquals(expected, filterAclEntriesByAclSpec(existing, aclSpec));
}