@Override public Task<Boolean> then(Task<Integer> task) { boolean exists = task.getResult() == 1; if (exists) { return Task.forResult(true); } return legacy.existsAsync(); } });
@Test public void testExistAsyncFromStore() throws Exception { //noinspection unchecked ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class); when(store.existsAsync()).thenReturn(Task.forResult(true)); // Create test controller CachedCurrentInstallationController controller = new CachedCurrentInstallationController(store, null); assertTrue(ParseTaskUtils.wait(controller.existsAsync())); verify(store, times(1)).existsAsync(); }
@Test public void testExistsAsyncWithNoInMemoryAndInDiskCurrentUserSet() throws Exception { ParseObjectStore<ParseUser> store = (ParseObjectStore<ParseUser>) mock(ParseObjectStore.class); when(store.existsAsync()).thenReturn(Task.forResult(false)); CachedCurrentUserController controller = new CachedCurrentUserController(store); assertFalse(ParseTaskUtils.wait(controller.existsAsync())); }
@Test public void testExistsAsyncWithInDiskCurrentUserSet() throws Exception { ParseObjectStore<ParseUser> store = (ParseObjectStore<ParseUser>) mock(ParseObjectStore.class); when(store.existsAsync()).thenReturn(Task.forResult(true)); CachedCurrentUserController controller = new CachedCurrentUserController(store); assertTrue(ParseTaskUtils.wait(controller.existsAsync())); }
@Test public void testExistsAsyncLegacy() throws Exception { Parse.enableLocalDatastore(null); ParseQueryController queryController = mock(ParseQueryController.class); //noinspection unchecked 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())); //noinspection unchecked verify(queryController, times(1)).countAsync( any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)); }