UserPrincipal extends Principal { public List<String> getOwnerIds() { List<String> ownerIds = new LinkedList<>(); for (Owner owner : getOwners()) { ownerIds.add(owner.getId()); } return ownerIds; } UserPrincipal(String username, Collection<Permission> permissions, boolean admin); String getUsername(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String getType(); @Override String getName(); @Override boolean hasFullAccess(); List<String> getOwnerIds(); List<String> getOwnerKeys(); List<Owner> getOwners(); @Override boolean canAccess(Object target, SubResource subResource, Access access);  }
@Test public void accessOwnerIdsGivenPermission() { when(owner.getId()).thenReturn("1"); when(owner.getKey()).thenReturn("owner1"); when(ownerPerm.getOwner()).thenReturn(owner); List<Permission> ops = new ArrayList<>(); ops.add(ownerPerm); UserPrincipal up = new UserPrincipal("admin", ops, false); List<String> ids = up.getOwnerIds(); assertNotNull(ids); assertEquals("1", ids.get(0)); }