@@ -58,7 +58,8 @@ public void testConstructor() throws Exception {
5858 String contentType = "content_type" ;
5959 File file = temporaryFolder .newFile (name );
6060
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.
6263
6364 ParseFile parseFile = new ParseFile (name , data , contentType );
6465 assertEquals ("name" , parseFile .getName ());
@@ -288,6 +289,22 @@ public void testGetDataAsyncSuccess() throws Exception {
288289 assertEquals (url , stateCaptor .getValue ().url ());
289290 // Verify the data we get is correct
290291 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 );
291308 }
292309
293310 @ Test
@@ -322,6 +339,22 @@ public void testGetDataStreamAsyncSuccess() throws Exception {
322339 assertEquals (url , stateCaptor .getValue ().url ());
323340 // Verify the data we get is correct
324341 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 ));
325358 }
326359
327360 @ Test
@@ -356,6 +389,22 @@ public void testGetFileAsyncSuccess() throws Exception {
356389 assertEquals (url , stateCaptor .getValue ().url ());
357390 // Verify the data we get is correct
358391 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 ));
359408 }
360409
361410 //endregion
0 commit comments