InMemoryPermissionsImpl implements PermissionsInterface { @Override public boolean canDoAction(User user, Workflow workflow, Role.Action action) { final Optional<Role> role = getRole(user, workflow); return role.map(p -> { switch (p) { case OWNER: return true; case WRITER: return action != Role.Action.DELETE && action != Role.Action.SHARE; case READER: return action == Role.Action.READ; default: return false; } }).orElse(false); }  @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 canDoAction() { Assert.assertEquals(inMemoryPermissions.workflowsSharedWithUser(johnDoeUser).size(), 0); final Permission permission = new Permission(janeDoeUser.getUsername(), Role.READER); inMemoryPermissions.setPermission(johnDoeUser, fooWorkflow, permission); Assert.assertTrue(inMemoryPermissions.canDoAction(janeDoeUser, fooWorkflow, Role.Action.READ)); Assert.assertFalse(inMemoryPermissions.canDoAction(janeDoeUser, fooWorkflow, Role.Action.WRITE)); }