@@ -58,7 +58,8 @@ public void testConstructor() throws Exception {
58
58
String contentType = "content_type" ;
59
59
File file = temporaryFolder .newFile (name );
60
60
61
- // TODO(mengyan): Test data and file pointer in ParseFile when we have proper stage strategy
61
+ // TODO(mengyan): After we have proper staging strategy, we should verify the staging file's
62
+ // content is the same with the original file.
62
63
63
64
ParseFile parseFile = new ParseFile (name , data , contentType );
64
65
assertEquals ("name" , parseFile .getName ());
@@ -288,6 +289,22 @@ public void testGetDataAsyncSuccess() throws Exception {
288
289
assertEquals (url , stateCaptor .getValue ().url ());
289
290
// Verify the data we get is correct
290
291
assertArrayEquals (content .getBytes (), data );
292
+
293
+ // Make sure we always get the data from network
294
+ byte [] dataAgain = ParseTaskUtils .wait (parseFile .getDataInBackground ());
295
+
296
+ // Verify controller get the correct data
297
+ ArgumentCaptor <ParseFile .State > stateCaptorAgain =
298
+ ArgumentCaptor .forClass (ParseFile .State .class );
299
+ verify (controller , times (2 )).fetchAsync (
300
+ stateCaptorAgain .capture (),
301
+ anyString (),
302
+ any (ProgressCallback .class ),
303
+ Matchers .<Task <Void >>any ()
304
+ );
305
+ assertEquals (url , stateCaptorAgain .getValue ().url ());
306
+ // Verify the data we get is correct
307
+ assertArrayEquals (content .getBytes (), dataAgain );
291
308
}
292
309
293
310
@ Test
@@ -322,6 +339,22 @@ public void testGetDataStreamAsyncSuccess() throws Exception {
322
339
assertEquals (url , stateCaptor .getValue ().url ());
323
340
// Verify the data we get is correct
324
341
assertArrayEquals (content .getBytes (), ParseIOUtils .toByteArray (dataStream ));
342
+
343
+ // Make sure we always get the data from network
344
+ InputStream dataStreamAgain = ParseTaskUtils .wait (parseFile .getDataStreamInBackground ());
345
+
346
+ // Verify controller get the correct data
347
+ ArgumentCaptor <ParseFile .State > stateCaptorAgain =
348
+ ArgumentCaptor .forClass (ParseFile .State .class );
349
+ verify (controller , times (2 )).fetchAsync (
350
+ stateCaptorAgain .capture (),
351
+ anyString (),
352
+ any (ProgressCallback .class ),
353
+ Matchers .<Task <Void >>any ()
354
+ );
355
+ assertEquals (url , stateCaptorAgain .getValue ().url ());
356
+ // Verify the data we get is correct
357
+ assertArrayEquals (content .getBytes (), ParseIOUtils .toByteArray (dataStreamAgain ));
325
358
}
326
359
327
360
@ Test
@@ -356,6 +389,22 @@ public void testGetFileAsyncSuccess() throws Exception {
356
389
assertEquals (url , stateCaptor .getValue ().url ());
357
390
// Verify the data we get is correct
358
391
assertArrayEquals (content .getBytes (), ParseFileUtils .readFileToByteArray (fetchedFile ));
392
+
393
+ // Make sure we always get the data from network
394
+ File fetchedFileAgain = ParseTaskUtils .wait (parseFile .getFileInBackground ());
395
+
396
+ // Verify controller get the correct data
397
+ ArgumentCaptor <ParseFile .State > stateCaptorAgain =
398
+ ArgumentCaptor .forClass (ParseFile .State .class );
399
+ verify (controller , times (2 )).fetchAsync (
400
+ stateCaptorAgain .capture (),
401
+ anyString (),
402
+ any (ProgressCallback .class ),
403
+ Matchers .<Task <Void >>any ()
404
+ );
405
+ assertEquals (url , stateCaptorAgain .getValue ().url ());
406
+ // Verify the data we get is correct
407
+ assertArrayEquals (content .getBytes (), ParseFileUtils .readFileToByteArray (fetchedFileAgain ));
359
408
}
360
409
361
410
//endregion
0 commit comments