11
11
import org .json .JSONArray ;
12
12
import org .json .JSONObject ;
13
13
import org .junit .Test ;
14
- import org .skyscreamer .jsonassert .JSONCompareMode ;
15
14
16
15
import java .io .ByteArrayInputStream ;
17
16
import java .io .IOException ;
31
30
import static org .mockito .Mockito .times ;
32
31
import static org .mockito .Mockito .verify ;
33
32
import static org .mockito .Mockito .when ;
34
- import static org .skyscreamer .jsonassert .JSONAssert .assertEquals ;
35
33
36
34
public class ParseCloudCodeControllerTest {
37
35
@@ -59,21 +57,6 @@ public void testConvertCloudResponseNullResponse() throws Exception {
59
57
assertNull (result );
60
58
}
61
59
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
-
77
60
@ Test
78
61
public void testConvertCloudResponseJsonResponseWithResultField () throws Exception {
79
62
ParseHttpClient restClient = mock (ParseHttpClient .class );
@@ -116,7 +99,7 @@ public void testCallFunctionInBackgroundCommand() throws Exception {
116
99
}
117
100
118
101
@ Test
119
- public void testCallFunctionInBackgroundSuccess () throws Exception {
102
+ public void testCallFunctionInBackgroundSuccessWithResult () throws Exception {
120
103
JSONObject json = new JSONObject ();
121
104
json .put ("result" , "test" );
122
105
String content = json .toString ();
@@ -137,6 +120,27 @@ public void testCallFunctionInBackgroundSuccess() throws Exception {
137
120
assertEquals ("test" , cloudCodeTask .getResult ());
138
121
}
139
122
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
+
140
144
@ Test
141
145
public void testCallFunctionInBackgroundFailure () throws Exception {
142
146
// TODO(mengyan): Remove once we no longer rely on retry logic.
0 commit comments