InMemoryPermissionsImpl implements PermissionsInterface { @Override public List<Permission> setPermission(User requester, Workflow workflow, Permission permission) { PermissionsInterface.checkUserNotOriginalOwner(permission.getEmail(), workflow); Map<String, Role> entryMap = resourceToUsersAndRolesMap.get(workflow.getWorkflowPath()); checkIfOwner(requester, workflow, entryMap); if (entryMap == null) { entryMap = new ConcurrentHashMap<>(); resourceToUsersAndRolesMap.put(workflow.getWorkflowPath(), entryMap); } entryMap.put(permission.getEmail(), permission.getRole()); return getPermissionsForWorkflow(requester, workflow); }  @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 setPermissionTest() { final Permission permission = new Permission(JANE_DOE_EXAMPLE_COM, Role.WRITER); final List<Permission> permissions = inMemoryPermissions.setPermission(johnDoeUser, fooWorkflow, permission); Assert.assertTrue(permissions.contains(permission)); }
@Test public void setPermissionsUnauthorized() { final Permission permission = new Permission("whatever", Role.READER); thrown.expect(CustomWebApplicationException.class); inMemoryPermissions.setPermission(janeDoeUser, fooWorkflow, permission); }