ParsePush { public static Task<Void> subscribeInBackground(String channel) { return getPushChannelsController().subscribeInBackground(channel); } ParsePush();  ParsePush(ParsePush push); private  ParsePush(State.Builder builder); static Task<Void> subscribeInBackground(String channel); static void subscribeInBackground(String channel, SaveCallback callback); static Task<Void> unsubscribeInBackground(String channel); static void unsubscribeInBackground(String channel, SaveCallback callback); static Task<Void> sendMessageInBackground(String message,
                                                     ParseQuery<ParseInstallation> query); static void sendMessageInBackground(String message, ParseQuery<ParseInstallation> query,
                                               SendCallback callback); static Task<Void> sendDataInBackground(JSONObject data,
                                                  ParseQuery<ParseInstallation> query); static void sendDataInBackground(JSONObject data, ParseQuery<ParseInstallation> query,
                                            SendCallback callback); void setChannel(String channel); void setChannels(Collection<String> channels); void setQuery(ParseQuery<ParseInstallation> query); void setExpirationTime(long time); void setExpirationTimeInterval(long timeInterval); void clearExpiration(); void setPushTime(long time); void setData(JSONObject data); void setMessage(String message); Task<Void> sendInBackground(); void send(); void sendInBackground(SendCallback callback);  }
@Test public void testSubscribeInBackgroundSuccess() throws Exception { ParsePushChannelsController controller = mock(ParsePushChannelsController.class); when(controller.subscribeInBackground(anyString())).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); ParseTaskUtils.wait(ParsePush.subscribeInBackground("test")); verify(controller, times(1)).subscribeInBackground("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"); }
@Test public void testSubscribeInBackgroundFail() throws Exception { ParsePushChannelsController controller = mock(ParsePushChannelsController.class); ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error"); when(controller.subscribeInBackground(anyString())).thenReturn(Task.<Void>forError(exception)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); Task<Void> pushTask = ParsePush.subscribeInBackground("test"); pushTask.waitForCompletion(); verify(controller, times(1)).subscribeInBackground("test"); assertTrue(pushTask.isFaulted()); assertSame(exception, pushTask.getError()); }
@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"); }