diff --git a/Parse/src/main/java/com/parse/ParseCloud.java b/Parse/src/main/java/com/parse/ParseCloud.java index 5411b714a..f1eba3212 100644 --- a/Parse/src/main/java/com/parse/ParseCloud.java +++ b/Parse/src/main/java/com/parse/ParseCloud.java @@ -11,9 +11,6 @@ import java.util.List; import java.util.Map; -import org.json.JSONException; -import org.json.JSONObject; - import bolts.Continuation; import bolts.Task; diff --git a/Parse/src/main/java/com/parse/ParseCloudCodeController.java b/Parse/src/main/java/com/parse/ParseCloudCodeController.java index eaa2a7ae0..3316b865d 100644 --- a/Parse/src/main/java/com/parse/ParseCloudCodeController.java +++ b/Parse/src/main/java/com/parse/ParseCloudCodeController.java @@ -8,7 +8,6 @@ */ package com.parse; -import org.json.JSONException; import org.json.JSONObject; import java.util.Map; @@ -46,11 +45,7 @@ public T then(Task task) throws Exception { /* package for test */ Object convertCloudResponse(Object result) { if (result instanceof JSONObject) { JSONObject jsonResult = (JSONObject)result; - try { - result = jsonResult.get("result"); - } catch (JSONException e) { - return result; - } + result = jsonResult.opt("result"); } ParseDecoder decoder = ParseDecoder.get(); diff --git a/Parse/src/test/java/com/parse/ParseCloudCodeControllerTest.java b/Parse/src/test/java/com/parse/ParseCloudCodeControllerTest.java index e1e47582b..a86d04c79 100644 --- a/Parse/src/test/java/com/parse/ParseCloudCodeControllerTest.java +++ b/Parse/src/test/java/com/parse/ParseCloudCodeControllerTest.java @@ -11,7 +11,6 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; -import org.skyscreamer.jsonassert.JSONCompareMode; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -31,7 +30,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; public class ParseCloudCodeControllerTest { @@ -59,21 +57,6 @@ public void testConvertCloudResponseNullResponse() throws Exception { assertNull(result); } - @Test - public void testConvertCloudResponseJsonResponseWithoutResultField() throws Exception { - ParseHttpClient restClient = mock(ParseHttpClient.class); - ParseCloudCodeController controller = new ParseCloudCodeController(restClient); - JSONObject response = new JSONObject(); - response.put("foo", "bar"); - response.put("yarr", 1); - - Object result = controller.convertCloudResponse(response); - - assertThat(result, instanceOf(JSONObject.class)); - JSONObject jsonResult = (JSONObject)result; - assertEquals(response, jsonResult, JSONCompareMode.NON_EXTENSIBLE); - } - @Test public void testConvertCloudResponseJsonResponseWithResultField() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); @@ -116,7 +99,7 @@ public void testCallFunctionInBackgroundCommand() throws Exception { } @Test - public void testCallFunctionInBackgroundSuccess() throws Exception { + public void testCallFunctionInBackgroundSuccessWithResult() throws Exception { JSONObject json = new JSONObject(); json.put("result", "test"); String content = json.toString(); @@ -137,6 +120,27 @@ public void testCallFunctionInBackgroundSuccess() throws Exception { assertEquals("test", cloudCodeTask.getResult()); } + @Test + public void testCallFunctionInBackgroundSuccessWithoutResult() throws Exception { + JSONObject json = new JSONObject(); + String content = json.toString(); + + ParseHttpResponse mockResponse = mock(ParseHttpResponse.class); + when(mockResponse.getStatusCode()).thenReturn(200); + when(mockResponse.getContent()).thenReturn(new ByteArrayInputStream(content.getBytes())); + when(mockResponse.getTotalSize()).thenReturn(content.length()); + + ParseHttpClient restClient = mockParseHttpClientWithReponse(mockResponse); + ParseCloudCodeController controller = new ParseCloudCodeController(restClient); + + Task cloudCodeTask = controller.callFunctionInBackground( + "test", new HashMap(), "sessionToken"); + ParseTaskUtils.wait(cloudCodeTask); + + verify(restClient, times(1)).execute(any(ParseHttpRequest.class)); + assertNull(cloudCodeTask.getResult()); + } + @Test public void testCallFunctionInBackgroundFailure() throws Exception { // TODO(mengyan): Remove once we no longer rely on retry logic.