SamPermissionsImpl implements PermissionsInterface { List<Permission> removeDuplicateEmails(List<Permission> permissionList) { final Map<String, Permission> map = new HashMap<>(); permissionList.stream().forEach(permission -> { final Permission existing = map.get(permission.getEmail()); if (existing == null || existing.getRole().ordinal() > permission.getRole().ordinal()) { map.put(permission.getEmail(), permission); } }); return new ArrayList<>(map.values()); } SamPermissionsImpl(TokenDAO tokenDAO, DockstoreWebserviceConfiguration config); @Override List<Permission> setPermission(User requester, Workflow workflow, Permission permission); @Override Map<Role, List<String>> workflowsSharedWithUser(User user); @Override List<Permission> getPermissionsForWorkflow(User user, Workflow workflow); @Override List<Role.Action> getActionsForWorkflow(User user, Workflow workflow); @Override void removePermission(User user, Workflow workflow, String email, Role role); @Override boolean canDoAction(User user, Workflow workflow, Role.Action action); @Override void selfDestruct(User user); @Override boolean isSharing(User user);  }
@Test public void testRemoveDuplicateEmails() { final List<Permission> permissions = samPermissionsImpl .removeDuplicateEmails(Arrays.asList(ownerPermission, writerPermission, readerPermission)); Assert.assertEquals( permissions.size(), 2); Assert.assertTrue(permissions.contains(ownerPermission)); Assert.assertTrue(permissions.contains(writerPermission)); Assert.assertFalse(permissions.contains(readerPermission)); }