@@ -186,11 +186,12 @@ public void testSaveAsyncSuccessWithFile() throws Exception {
186
186
assertEquals ("http://example.com" , result .url ());
187
187
File cachedFile = new File (root , "new_file_name" );
188
188
assertTrue (cachedFile .exists ());
189
+ assertTrue (file .exists ());
189
190
assertEquals ("content" , ParseFileUtils .readFileToString (cachedFile , "UTF-8" ));
190
191
}
191
192
192
193
@ Test
193
- public void testSaveAsyncFailure () throws Exception {
194
+ public void testSaveAsyncFailureWithByteArray () throws Exception {
194
195
// TODO(grantland): Remove once we no longer rely on retry logic.
195
196
ParseRequest .setDefaultInitialRetryDelay (1L );
196
197
@@ -215,6 +216,34 @@ public void testSaveAsyncFailure() throws Exception {
215
216
assertEquals (0 , root .listFiles ().length );
216
217
}
217
218
219
+ @ Test
220
+ public void testSaveAsyncFailureWithFile () throws Exception {
221
+ // TODO(grantland): Remove once we no longer rely on retry logic.
222
+ ParseRequest .setDefaultInitialRetryDelay (1L );
223
+
224
+ ParseHttpClient restClient = mock (ParseHttpClient .class );
225
+ when (restClient .execute (any (ParseHttpRequest .class ))).thenThrow (new IOException ());
226
+
227
+ File root = temporaryFolder .getRoot ();
228
+ ParseFileController controller = new ParseFileController (restClient , root );
229
+
230
+ File file = temporaryFolder .newFile ("test" );
231
+ ParseFile .State state = new ParseFile .State .Builder ()
232
+ .build ();
233
+ Task <ParseFile .State > task = controller .saveAsync (state , file , null , null , null );
234
+ task .waitForCompletion ();
235
+
236
+ // TODO(grantland): Abstract out command runner so we don't have to account for retries.
237
+ verify (restClient , times (5 )).execute (any (ParseHttpRequest .class ));
238
+ assertTrue (task .isFaulted ());
239
+ Exception error = task .getError ();
240
+ assertThat (error , instanceOf (ParseException .class ));
241
+ assertEquals (ParseException .CONNECTION_FAILED , ((ParseException ) error ).getCode ());
242
+ // Make sure the original file is not deleted and there is no cache file in the folder
243
+ assertEquals (1 , root .listFiles ().length );
244
+ assertTrue (file .exists ());
245
+ }
246
+
218
247
//endregion
219
248
220
249
//region testFetchAsync
0 commit comments