1111import org .json .JSONArray ;
1212import org .json .JSONObject ;
1313import org .junit .Test ;
14- import org .skyscreamer .jsonassert .JSONCompareMode ;
1514
1615import java .io .ByteArrayInputStream ;
1716import java .io .IOException ;
3130import static org .mockito .Mockito .times ;
3231import static org .mockito .Mockito .verify ;
3332import static org .mockito .Mockito .when ;
34- import static org .skyscreamer .jsonassert .JSONAssert .assertEquals ;
3533
3634public class ParseCloudCodeControllerTest {
3735
@@ -59,21 +57,6 @@ public void testConvertCloudResponseNullResponse() throws Exception {
5957 assertNull (result );
6058 }
6159
62- @ Test
63- public void testConvertCloudResponseJsonResponseWithoutResultField () throws Exception {
64- ParseHttpClient restClient = mock (ParseHttpClient .class );
65- ParseCloudCodeController controller = new ParseCloudCodeController (restClient );
66- JSONObject response = new JSONObject ();
67- response .put ("foo" , "bar" );
68- response .put ("yarr" , 1 );
69-
70- Object result = controller .convertCloudResponse (response );
71-
72- assertThat (result , instanceOf (JSONObject .class ));
73- JSONObject jsonResult = (JSONObject )result ;
74- assertEquals (response , jsonResult , JSONCompareMode .NON_EXTENSIBLE );
75- }
76-
7760 @ Test
7861 public void testConvertCloudResponseJsonResponseWithResultField () throws Exception {
7962 ParseHttpClient restClient = mock (ParseHttpClient .class );
@@ -116,7 +99,7 @@ public void testCallFunctionInBackgroundCommand() throws Exception {
11699 }
117100
118101 @ Test
119- public void testCallFunctionInBackgroundSuccess () throws Exception {
102+ public void testCallFunctionInBackgroundSuccessWithResult () throws Exception {
120103 JSONObject json = new JSONObject ();
121104 json .put ("result" , "test" );
122105 String content = json .toString ();
@@ -137,6 +120,27 @@ public void testCallFunctionInBackgroundSuccess() throws Exception {
137120 assertEquals ("test" , cloudCodeTask .getResult ());
138121 }
139122
123+ @ Test
124+ public void testCallFunctionInBackgroundSuccessWithoutResult () throws Exception {
125+ JSONObject json = new JSONObject ();
126+ String content = json .toString ();
127+
128+ ParseHttpResponse mockResponse = mock (ParseHttpResponse .class );
129+ when (mockResponse .getStatusCode ()).thenReturn (200 );
130+ when (mockResponse .getContent ()).thenReturn (new ByteArrayInputStream (content .getBytes ()));
131+ when (mockResponse .getTotalSize ()).thenReturn (content .length ());
132+
133+ ParseHttpClient restClient = mockParseHttpClientWithReponse (mockResponse );
134+ ParseCloudCodeController controller = new ParseCloudCodeController (restClient );
135+
136+ Task <String > cloudCodeTask = controller .callFunctionInBackground (
137+ "test" , new HashMap <String , Object >(), "sessionToken" );
138+ ParseTaskUtils .wait (cloudCodeTask );
139+
140+ verify (restClient , times (1 )).execute (any (ParseHttpRequest .class ));
141+ assertNull (cloudCodeTask .getResult ());
142+ }
143+
140144 @ Test
141145 public void testCallFunctionInBackgroundFailure () throws Exception {
142146 // TODO(mengyan): Remove once we no longer rely on retry logic.
0 commit comments