ParseACL implements Parcelable { static ParseACL createACLFromJSONObject(JSONObject object, ParseDecoder decoder) { ParseACL acl = new ParseACL(); for (String key : ParseJSONUtils.keys(object)) { if (key.equals(UNRESOLVED_USER_JSON_KEY)) { JSONObject unresolvedUser; try { unresolvedUser = object.getJSONObject(key); } catch (JSONException e) { throw new RuntimeException(e); } acl.unresolvedUser = (ParseUser) decoder.decode(unresolvedUser); } else { try { Permissions permissions = Permissions.createPermissionsFromJSONObject(object.getJSONObject(key)); acl.permissionsById.put(key, permissions); } catch (JSONException e) { throw new RuntimeException("could not decode ACL: " + e.getMessage()); } } } return acl; } ParseACL();  ParseACL(ParseACL acl);  ParseACL(ParseUser owner);   ParseACL(Parcel source, ParseParcelDecoder decoder); static void setDefaultACL(ParseACL acl, boolean withAccessForCurrentUser); boolean getPublicReadAccess(); void setPublicReadAccess(boolean allowed); boolean getPublicWriteAccess(); void setPublicWriteAccess(boolean allowed); void setReadAccess(String userId, boolean allowed); boolean getReadAccess(String userId); void setWriteAccess(String userId, boolean allowed); boolean getWriteAccess(String userId); void setReadAccess(ParseUser user, boolean allowed); boolean getReadAccess(ParseUser user); void setWriteAccess(ParseUser user, boolean allowed); boolean getWriteAccess(ParseUser user); boolean getRoleReadAccess(String roleName); void setRoleReadAccess(String roleName, boolean allowed); boolean getRoleWriteAccess(String roleName); void setRoleWriteAccess(String roleName, boolean allowed); boolean getRoleReadAccess(ParseRole role); void setRoleReadAccess(ParseRole role, boolean allowed); boolean getRoleWriteAccess(ParseRole role); void setRoleWriteAccess(ParseRole role, boolean allowed); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); final static Creator<ParseACL> CREATOR; }
@Test public void testCreateACLFromJSONObject() throws Exception { JSONObject aclJson = new JSONObject(); JSONObject permission = new JSONObject(); permission.put(READ_PERMISSION, true); permission.put(WRITE_PERMISSION, true); aclJson.put("userId", permission); ParseUser unresolvedUser = new ParseUser(); JSONObject unresolvedUserJson = new JSONObject(); aclJson.put("unresolvedUser", unresolvedUserJson); ParseDecoder mockDecoder = mock(ParseDecoder.class); when(mockDecoder.decode(eq(unresolvedUserJson))).thenReturn(unresolvedUser); ParseACL acl = ParseACL.createACLFromJSONObject(aclJson, mockDecoder); assertSame(unresolvedUser, acl.getUnresolvedUser()); assertTrue(acl.getReadAccess("userId")); assertTrue(acl.getWriteAccess("userId")); assertEquals(1, acl.getPermissionsById().size()); }