/** * Synchronously gets the data from cache if available or fetches its content from the network. * You probably want to use {@link #getDataInBackground()} instead unless you're already in a * background thread. */ public byte[] getData() throws ParseException { return ParseTaskUtils.wait(getDataInBackground()); }
/** * Fetches a new configuration object from the server. * * @return The {@code ParseConfig} that was fetched. * @throws ParseException Throws an exception if the server is inaccessible. */ public static ParseConfig get() throws ParseException { return ParseTaskUtils.wait(getInBackground()); }
/** * Removes the object and every object it points to in the local datastore, recursively. * * @see #pin(String) */ public void unpin(String name) throws ParseException { ParseTaskUtils.wait(unpinInBackground(name)); }
@Override public void clearFromDisk() { synchronized (mutex) { currentUser = null; currentUserMatchesDisk = false; } try { ParseTaskUtils.wait(store.deleteAsync()); } catch (ParseException e) { // ignored } }
/** * Fetches all the objects that don't have data in the provided list. * * @param objects The list of objects to fetch. * @return The list passed in for convenience. * @throws ParseException Throws an exception if the server returns an error or is inaccessible. */ public static <T extends ParseObject> List<T> fetchAllIfNeeded(List<T> objects) throws ParseException { return ParseTaskUtils.wait(fetchAllIfNeededInBackground(objects)); }
/** * Deletes this object on the server. This does not delete or destroy the object locally. * * @throws ParseException Throws an error if the object does not exist or if the internet fails. */ public final void delete() throws ParseException { ParseTaskUtils.wait(deleteInBackground()); }
/** * Loads data from the local datastore into this object, if it has not been fetched from the * server already. If the object is not stored in the local datastore, this method with throw a * CACHE_MISS exception. * * @throws ParseException exception if fails */ public void fetchFromLocalDatastore() throws ParseException { ParseTaskUtils.wait(fetchFromLocalDatastoreAsync()); }
public static ParseInstallation getCurrentInstallation() { try { return ParseTaskUtils.wait( getCurrentInstallationController().getAsync()); } catch (ParseException e) { // In order to have backward compatibility, we swallow the exception silently. return null; } }
@Test public void testTrackEventInBackgroundNormalParameters() throws Exception { Map<String, String> dimensions = new HashMap<>(); dimensions.put("key", "value"); ParseTaskUtils.wait(ParseAnalytics.trackEventInBackground("test", dimensions)); verify(controller, times(1)).trackEventInBackground( eq("test"), eq(dimensions), isNull(String.class)); }
@Test public void testTrackEventInBackgroundEmptyParameters() throws Exception { Map<String, String> dimensions = new HashMap<>(); ParseTaskUtils.wait(ParseAnalytics.trackEventInBackground("test", dimensions)); verify(controller, times(1)).trackEventInBackground( eq("test"), eq(dimensions), isNull(String.class)); }
@Test public void testTrackEventInBackgroundNormalName() throws Exception { ParseTaskUtils.wait(ParseAnalytics.trackEventInBackground("test")); verify(controller, times(1)).trackEventInBackground( eq("test"), Matchers.<Map<String, String>>eq(null), isNull(String.class)); }
@Test public void testUnsubscribeInBackgroundSuccess() throws Exception { ParsePushChannelsController controller = mock(ParsePushChannelsController.class); when(controller.unsubscribeInBackground(anyString())).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); ParseTaskUtils.wait(ParsePush.unsubscribeInBackground("test")); verify(controller, times(1)).unsubscribeInBackground("test"); }
@Test public void testTrackAppOpenedInBackgroundEmptyIntent() throws Exception { Intent intent = new Intent(); ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(intent)); verify(controller, times(1)).trackAppOpenedInBackground(isNull(String.class), isNull(String.class)); }
@Test public void testTrackAppOpenedInBackgroundNormalIntent() throws Exception { Intent intent = makeIntentWithParseData("test"); ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(intent)); verify(controller, times(1)).trackAppOpenedInBackground(eq("test"), isNull(String.class)); }
@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 testRequestPasswordResetAsync() throws Exception { // Make mock response and client ParseHttpClient restClient = ParseTestUtils.mockParseHttpClientWithResponse(new JSONObject(), 200, "OK"); NetworkUserController controller = new NetworkUserController(restClient, true); // We just need to verify task is finished since sever returns an empty json here ParseTaskUtils.wait(controller.requestPasswordResetAsync("sessionToken")); }
@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 testTrackAppOpenedInBackgroundNullIntent() throws Exception { ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(null)); verify(controller, times(1)).trackAppOpenedInBackground(isNull(String.class), isNull(String.class)); }
@Test public void testExistAsyncFromMemory() throws Exception { // Create test controller CachedCurrentInstallationController controller = new CachedCurrentInstallationController(null, null); controller.currentInstallation = mock(ParseInstallation.class); assertTrue(ParseTaskUtils.wait(controller.existsAsync())); }
@Test public void testExistsAsyncWithInMemoryCurrentUserSet() throws Exception { CachedCurrentUserController controller = new CachedCurrentUserController(null); controller.currentUser = new ParseUser(); assertTrue(ParseTaskUtils.wait(controller.existsAsync())); }