OfflineObjectStore implements ParseObjectStore<T> { @Override public Task<Boolean> existsAsync() { ParseQuery<T> query = ParseQuery.<T>getQuery(className) .fromPin(pinName) .ignoreACLs(); return query.countInBackground().onSuccessTask(new Continuation<Integer, Task<Boolean>>() { @Override public Task<Boolean> then(Task<Integer> task) { boolean exists = task.getResult() == 1; if (exists) { return Task.forResult(true); } return legacy.existsAsync(); } }); } OfflineObjectStore(Class<T> clazz, String pinName, ParseObjectStore<T> legacy);  OfflineObjectStore(String className, String pinName, ParseObjectStore<T> legacy); @Override Task<Void> setAsync(final T object); @Override Task<T> getAsync(); @Override Task<Boolean> existsAsync(); @Override Task<Void> deleteAsync();  }
@Test public void testExistsAsyncLDS() throws Exception { Parse.enableLocalDatastore(null); ParseQueryController queryController = mock(ParseQueryController.class); when(queryController.countAsync( any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)) ).thenReturn(Task.forResult(1)); ParseCorePlugins.getInstance().registerQueryController(queryController); OfflineObjectStore<ParseUser> store = new OfflineObjectStore<>(ParseUser.class, PIN_NAME, null); assertTrue(ParseTaskUtils.wait(store.existsAsync())); verify(queryController, times(1)).countAsync( any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)); }
@Test public void testExistsAsyncLegacy() throws Exception { Parse.enableLocalDatastore(null); ParseQueryController queryController = mock(ParseQueryController.class); when(queryController.countAsync( any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)) ).thenReturn(Task.forResult(0)); ParseCorePlugins.getInstance().registerQueryController(queryController); @SuppressWarnings("unchecked") ParseObjectStore<ParseUser> legacy = mock(ParseObjectStore.class); when(legacy.existsAsync()).thenReturn(Task.forResult(true)); OfflineObjectStore<ParseUser> store = new OfflineObjectStore<>(ParseUser.class, PIN_NAME, legacy); assertTrue(ParseTaskUtils.wait(store.existsAsync())); verify(queryController, times(1)).countAsync( any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)); }