InMemoryPermissionsImpl implements PermissionsInterface { @Override public Map<Role, List<String>> workflowsSharedWithUser(User user) { final String userKey = userKey(user); final Map<Role, List<String>> map = new HashMap<>(); resourceToUsersAndRolesMap.entrySet().stream().forEach(e -> { final Role role = e.getValue().get(userKey); if (role != null) { List<String> workflows = map.get(role); if (workflows == null) { workflows = new ArrayList<>(); map.put(role, workflows); } workflows.add(e.getKey()); } }); return map; }  @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 workflowsSharedWithUser() { Assert.assertEquals(inMemoryPermissions.workflowsSharedWithUser(johnDoeUser).size(), 0); final Permission permission = new Permission(); permission.setRole(Role.WRITER); permission.setEmail(janeDoeUser.getUsername()); inMemoryPermissions.setPermission(johnDoeUser, fooWorkflow, permission); inMemoryPermissions.setPermission(johnDoeUser, gooWorkflow, permission); Assert.assertEquals(1, inMemoryPermissions.workflowsSharedWithUser(janeDoeUser).size()); permission.setRole(Role.READER); inMemoryPermissions.setPermission(johnDoeUser, dockstoreOrgWorkflow, permission); final Map<Role, List<String>> roleListMap = inMemoryPermissions.workflowsSharedWithUser(janeDoeUser); Assert.assertEquals(2, roleListMap.size()); Assert.assertEquals(DOCKSTORE_ORG_JOHN_MYWORKFLOW, roleListMap.get(Role.READER).get(0)); }