@@ -319,6 +319,34 @@ public void testFetchAsyncSuccess() throws Exception {
319319 assertFalse (controller .getTempFile (state ).exists ());
320320 }
321321
322+ @ Test
323+ public void testFetchAsyncSuccessWithCacheDirNotExist () throws Exception {
324+ byte [] data = "hello" .getBytes ();
325+ ParseHttpResponse response = mock (ParseHttpResponse .class );
326+ when (response .getStatusCode ()).thenReturn (200 );
327+ when (response .getContent ()).thenReturn (new ByteArrayInputStream (data ));
328+ when (response .getTotalSize ()).thenReturn ((long ) data .length );
329+
330+ ParseHttpClient awsClient = mock (ParseHttpClient .class );
331+ when (awsClient .execute (any (ParseHttpRequest .class ))).thenReturn (response );
332+ // Make sure cache dir does not exist
333+ File root = new File (temporaryFolder .getRoot (), "cache" );
334+ assertFalse (root .exists ());
335+ ParseFileController controller = new ParseFileController (null , root ).awsClient (awsClient );
336+
337+ ParseFile .State state = new ParseFile .State .Builder ()
338+ .name ("file_name" )
339+ .url ("url" )
340+ .build ();
341+ Task <File > task = controller .fetchAsync (state , null , null , null );
342+ File result = ParseTaskUtils .wait (task );
343+
344+ verify (awsClient , times (1 )).execute (any (ParseHttpRequest .class ));
345+ assertTrue (result .exists ());
346+ assertEquals ("hello" , ParseFileUtils .readFileToString (result , "UTF-8" ));
347+ assertFalse (controller .getTempFile (state ).exists ());
348+ }
349+
322350 @ Test
323351 public void testFetchAsyncFailure () throws Exception {
324352 // TODO(grantland): Remove once we no longer rely on retry logic.
0 commit comments