@Test public void testFetchIncludesJSONArray() throws ParseException { OfflineStore store = mock(OfflineStore.class); when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.<ParseObject>forResult(null)); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject") .include("foo") .build(); ParseObject object = mock(ParseObject.class); ParseObject unfetchedObject = mock(ParseObject.class); JSONArray objects = new JSONArray(); objects.put(unfetchedObject); when(object.get("foo")).thenReturn(objects); ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); }
static <T extends ParseObject> Task<Void> fetchIncludesAsync( final OfflineStore store, final T object, ParseQuery.State<T> state, final ParseSQLiteDatabase db) { Set<String> includes = state.includes(); Task<Void> task = Task.forResult(null); for (final String include : includes) { task = task.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return fetchIncludeAsync(store, object, include, db); } }); } return task; }
OfflineQueryLogic { static <T extends ParseObject> Task<Void> fetchIncludesAsync( final OfflineStore store, final T object, ParseQuery.State<T> state, final ParseSQLiteDatabase db) { Set<String> includes = state.includes(); Task<Void> task = Task.forResult(null); for (final String include : includes) { task = task.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return fetchIncludeAsync(store, object, include, db); } }); } return task; } }
OfflineQueryLogic { static <T extends ParseObject> Task<Void> fetchIncludesAsync( final OfflineStore store, final T object, ParseQuery.State<T> state, final ParseSQLiteDatabase db) { Set<String> includes = state.includes(); Task<Void> task = Task.forResult(null); for (final String include : includes) { task = task.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return fetchIncludeAsync(store, object, include, db); } }); } return task; } OfflineQueryLogic(OfflineStore store); }
OfflineQueryLogic { static <T extends ParseObject> Task<Void> fetchIncludesAsync( final OfflineStore store, final T object, ParseQuery.State<T> state, final ParseSQLiteDatabase db) { Set<String> includes = state.includes(); Task<Void> task = Task.forResult(null); for (final String include : includes) { task = task.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return fetchIncludeAsync(store, object, include, db); } }); } return task; } OfflineQueryLogic(OfflineStore store);  }
OfflineQueryLogic { static <T extends ParseObject> Task<Void> fetchIncludesAsync( final OfflineStore store, final T object, ParseQuery.State<T> state, final ParseSQLiteDatabase db) { Set<String> includes = state.includes(); Task<Void> task = Task.forResult(null); for (final String include : includes) { task = task.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return fetchIncludeAsync(store, object, include, db); } }); } return task; } OfflineQueryLogic(OfflineStore store);   }