@Test public void testRightCallbackExecuted() { final Capture<Boolean> capture = new Capture(false); final CallbackManagerImpl callbackManagerImpl = new CallbackManagerImpl(); callbackManagerImpl.registerCallback( 123, new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { capture.set(true); return true; } }); callbackManagerImpl.registerCallback( 456, new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return false; } }); callbackManagerImpl.onActivityResult( 123, 1, new Intent()); assertTrue(capture.get()); }
@Test public void testCallbackExecuted() { final Capture<Boolean> capture = new Capture(false); final CallbackManagerImpl callbackManagerImpl = new CallbackManagerImpl(); callbackManagerImpl.registerCallback( CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(), new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { capture.set(true); return true; } }); callbackManagerImpl.onActivityResult( FacebookSdk.getCallbackRequestCodeOffset(), 1, new Intent()); assertTrue(capture.get()); }
@Test public void testStaticCallbackExecuted() { final Capture<Boolean> capture = new Capture(false); final CallbackManagerImpl callbackManagerImpl = new CallbackManagerImpl(); callbackManagerImpl.registerStaticCallback( CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(), new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { capture.set(true); return true; } }); callbackManagerImpl.onActivityResult( FacebookSdk.getCallbackRequestCodeOffset(), 1, new Intent()); assertTrue(capture.get()); }
/** * This is kind of like ParseTaskUtils.wait(), except that it gives up the CommandCache's lock * while the task is running, and reclaims it before returning. */ private <T> T waitForTaskWithoutLock(Task<T> task) throws ParseException { synchronized (lock) { final Capture<Boolean> finished = new Capture<>(false); task.continueWith(new Continuation<T, Void>() { @Override public Void then(Task<T> task) { finished.set(true); synchronized (lock) { lock.notifyAll(); } return null; } }, Task.BACKGROUND_EXECUTOR); while (!finished.get()) { try { lock.wait(); } catch (InterruptedException ie) { shouldStop = true; } } return ParseTaskUtils.wait(task); // Just to get the return value and maybe rethrow. } }
/** * Tracks this application being launched (and if this happened as the result of the user opening * a push notification, this method sends along information to correlate this open with that * push). * * @param intent The {@code Intent} that started an {@code Activity}, if any. Can be null. * @return A Task that is resolved when the event has been tracked by Parse. */ public static Task<Void> trackAppOpenedInBackground(Intent intent) { String pushHashStr = getPushHashFromIntent(intent); final Capture<String> pushHash = new Capture<>(); if (pushHashStr != null && pushHashStr.length() > 0) { synchronized (lruSeenPushes) { if (lruSeenPushes.containsKey(pushHashStr)) { return Task.forResult(null); } else { lruSeenPushes.put(pushHashStr, true); pushHash.set(pushHashStr); } } } return ParseUser.getCurrentSessionTokenAsync().onSuccessTask(new Continuation<String, Task<Void>>() { @Override public Task<Void> then(Task<String> task) { String sessionToken = task.getResult(); return getAnalyticsController().trackAppOpenedInBackground(pushHash.get(), sessionToken); } }); }
final Capture<Set<ParseObject>> remaining = new Capture<>(objects); Task<Void> objectsTask = Task.forResult(null).continueWhile(new Callable<Boolean>() { @Override
final Capture<Boolean> result = new Capture<>(true);
long timeout, Criteria criteria) { final TaskCompletionSource<Location> tcs = new TaskCompletionSource<>(); final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<>(); final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
@Test public void testUnsubscribeInBackgroundWithCallbackSuccess() throws Exception { final ParsePushChannelsController controller = mock(ParsePushChannelsController.class); when(controller.unsubscribeInBackground(anyString())).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.unsubscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); done.release(); } }); assertNull(exceptionCapture.get()); assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS)); verify(controller, times(1)).unsubscribeInBackground("test"); }
@Test public void testSubscribeInBackgroundWithCallbackSuccess() throws Exception { final ParsePushChannelsController controller = mock(ParsePushChannelsController.class); when(controller.subscribeInBackground(anyString())).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.subscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); done.release(); } }); assertNull(exceptionCapture.get()); assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS)); verify(controller, times(1)).subscribeInBackground("test"); }
final Capture<String> uuidCapture = new Capture<>();
@Test public void testUnsubscribeInBackgroundWithCallbackFail() throws Exception { ParsePushChannelsController controller = mock(ParsePushChannelsController.class); final ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error"); when(controller.unsubscribeInBackground(anyString())) .thenReturn(Task.<Void>forError(exception)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.unsubscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); done.release(); } }); assertSame(exception, exceptionCapture.get()); assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS)); verify(controller, times(1)).unsubscribeInBackground("test"); }
@Test public void testSubscribeInBackgroundWithCallbackFail() throws Exception { ParsePushChannelsController controller = mock(ParsePushChannelsController.class); final ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error"); when(controller.subscribeInBackground(anyString())).thenReturn(Task.<Void>forError(exception)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.subscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); done.release(); } }); assertSame(exception, exceptionCapture.get()); assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS)); verify(controller, times(1)).subscribeInBackground("test"); }
.whereEqualTo("foo", "bar"); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.sendDataInBackground(data, query, new SendCallback() { @Override
.channelSet(channels); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); push.sendInBackground(new SendCallback() { @Override
private Task<Void> deleteDataForObjectAsync(final ParseObject object, final ParseSQLiteDatabase db) { final Capture<String> uuid = new Capture<>();
.whereEqualTo("foo", "bar"); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.sendMessageInBackground("test", query, new SendCallback() { @Override
.channelSet(channels); final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); push.sendInBackground(new SendCallback() { @Override
final Capture<Exception> exceptionCapture = new Capture<>(); user.saveInBackground().continueWith(new Continuation<Void, Void>() { @Override