@Test public void testConvertFindResponse() throws Exception { JSONObject mockResponse = generateBasicMockResponse(); ParseQuery.State mockState = mock(ParseQuery.State.class); when(mockState.className()).thenReturn("Test"); when(mockState.selectedKeys()).thenReturn(null); when(mockState.constraints()).thenReturn(new ParseQuery.QueryConstraints()); NetworkQueryController controller = new NetworkQueryController(mock(ParseHttpClient.class)); List<ParseObject> objects = controller.convertFindResponse(mockState, mockResponse); verifyBasicParseObjects(mockResponse, objects, "Test"); }
<T extends ParseObject> List<T> convertFindResponse(ParseQuery.State<T> state, JSONObject response) throws JSONException { ArrayList<T> answer = new ArrayList<>(); JSONArray results = response.getJSONArray("results"); if (results == null) { PLog.d(TAG, "null results in find response"); } else { String resultClassName = response.optString("className", null); if (resultClassName == null) { resultClassName = state.className(); } for (int i = 0; i < results.length(); ++i) { JSONObject data = results.getJSONObject(i); T object = ParseObject.fromJSON(data, resultClassName, ParseDecoder.get(), state.selectedKeys()); answer.add(object); ParseQuery.RelationConstraint relation = (ParseQuery.RelationConstraint) state.constraints().get("$relatedTo"); if (relation != null) { relation.getRelation().addKnownObject(object); } } } return answer; }
NetworkQueryController extends AbstractQueryController { <T extends ParseObject> List<T> convertFindResponse(ParseQuery.State<T> state, JSONObject response) throws JSONException { ArrayList<T> answer = new ArrayList<>(); JSONArray results = response.getJSONArray("results"); if (results == null) { PLog.d(TAG, "null results in find response"); } else { String resultClassName = response.optString("className", null); if (resultClassName == null) { resultClassName = state.className(); } for (int i = 0; i < results.length(); ++i) { JSONObject data = results.getJSONObject(i); T object = ParseObject.fromJSON(data, resultClassName, ParseDecoder.get(), state.selectedKeys()); answer.add(object); ParseQuery.RelationConstraint relation = (ParseQuery.RelationConstraint) state.constraints().get("$relatedTo"); if (relation != null) { relation.getRelation().addKnownObject(object); } } } return answer; } }
NetworkQueryController extends AbstractQueryController { <T extends ParseObject> List<T> convertFindResponse(ParseQuery.State<T> state, JSONObject response) throws JSONException { ArrayList<T> answer = new ArrayList<>(); JSONArray results = response.getJSONArray("results"); if (results == null) { PLog.d(TAG, "null results in find response"); } else { String resultClassName = response.optString("className", null); if (resultClassName == null) { resultClassName = state.className(); } for (int i = 0; i < results.length(); ++i) { JSONObject data = results.getJSONObject(i); T object = ParseObject.fromJSON(data, resultClassName, ParseDecoder.get(), state.selectedKeys()); answer.add(object); ParseQuery.RelationConstraint relation = (ParseQuery.RelationConstraint) state.constraints().get("$relatedTo"); if (relation != null) { relation.getRelation().addKnownObject(object); } } } return answer; } NetworkQueryController(ParseHttpClient restClient); }
NetworkQueryController extends AbstractQueryController { <T extends ParseObject> List<T> convertFindResponse(ParseQuery.State<T> state, JSONObject response) throws JSONException { ArrayList<T> answer = new ArrayList<>(); JSONArray results = response.getJSONArray("results"); if (results == null) { PLog.d(TAG, "null results in find response"); } else { String resultClassName = response.optString("className", null); if (resultClassName == null) { resultClassName = state.className(); } for (int i = 0; i < results.length(); ++i) { JSONObject data = results.getJSONObject(i); T object = ParseObject.fromJSON(data, resultClassName, ParseDecoder.get(), state.selectedKeys()); answer.add(object); ParseQuery.RelationConstraint relation = (ParseQuery.RelationConstraint) state.constraints().get("$relatedTo"); if (relation != null) { relation.getRelation().addKnownObject(object); } } } return answer; } NetworkQueryController(ParseHttpClient restClient); @Override Task<List<T>> findAsync(
            ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken); @Override Task<Integer> countAsync(
            ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken); }
NetworkQueryController extends AbstractQueryController { <T extends ParseObject> List<T> convertFindResponse(ParseQuery.State<T> state, JSONObject response) throws JSONException { ArrayList<T> answer = new ArrayList<>(); JSONArray results = response.getJSONArray("results"); if (results == null) { PLog.d(TAG, "null results in find response"); } else { String resultClassName = response.optString("className", null); if (resultClassName == null) { resultClassName = state.className(); } for (int i = 0; i < results.length(); ++i) { JSONObject data = results.getJSONObject(i); T object = ParseObject.fromJSON(data, resultClassName, ParseDecoder.get(), state.selectedKeys()); answer.add(object); ParseQuery.RelationConstraint relation = (ParseQuery.RelationConstraint) state.constraints().get("$relatedTo"); if (relation != null) { relation.getRelation().addKnownObject(object); } } } return answer; } NetworkQueryController(ParseHttpClient restClient); @Override Task<List<T>> findAsync(
            ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken); @Override Task<Integer> countAsync(
            ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken);  }