Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parse/src/main/java/com/parse/ParseCloudCodeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public T then(Task<JSONObject> task) {
/* package for test */ Object convertCloudResponse(Object result) {
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
// We want to make sure we pass back a null result as null, and not a JSONObject
if (jsonResult.isNull("result")) {
return null;
}
result = jsonResult.opt("result");
}

Expand Down
22 changes: 22 additions & 0 deletions parse/src/test/java/com/parse/ParseCloudCodeControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ public void testCallFunctionInBackgroundFailure() throws Exception {

//endregion

@Test
public void testCallFunctionWithNullResult() throws Exception {
String content = "{ result: null }";

ParseHttpResponse mockResponse = new ParseHttpResponse.Builder()
.setStatusCode(200)
.setTotalSize((long) content.length())
.setContent(new ByteArrayInputStream(content.getBytes()))
.build();

ParseHttpClient restClient = mockParseHttpClientWithReponse(mockResponse);
ParseCloudCodeController controller = new ParseCloudCodeController(restClient);

Task<String> cloudCodeTask = controller.callFunctionInBackground(
"test", new HashMap<String, Object>(), "sessionToken");
ParseTaskUtils.wait(cloudCodeTask);

verify(restClient, times(1)).execute(any(ParseHttpRequest.class));
String result = cloudCodeTask.getResult();
assertEquals(null, result);
}

private ParseHttpClient mockParseHttpClientWithReponse(ParseHttpResponse response)
throws IOException {
ParseHttpClient client = mock(ParseHttpClient.class);
Expand Down