/** * Removes 'channel' from the 'channels' list in the current {@link ParseInstallation} and saves * it in a background thread. * * @param channel The channel to unsubscribe from. * @param callback The SaveCallback that is called after the Installation is saved. */ public static void unsubscribeInBackground(String channel, SaveCallback callback) { ParseTaskUtils.callbackOnMainThreadAsync(unsubscribeInBackground(channel), callback); }
@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 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 testUnsubscribeInBackgroundFail() throws Exception { ParsePushChannelsController controller = mock(ParsePushChannelsController.class); ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error"); when(controller.unsubscribeInBackground(anyString())) .thenReturn(Task.<Void>forError(exception)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); Task<Void> pushTask = ParsePush.unsubscribeInBackground("test"); pushTask.waitForCompletion(); verify(controller, times(1)).unsubscribeInBackground("test"); assertTrue(pushTask.isFaulted()); assertSame(exception, pushTask.getError()); }
@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"); }
@NonNull public static Completable unsubscribe(@NonNull final String channel) { return RxTask.completable(() -> ParsePush.unsubscribeInBackground(channel)); }