NCMBPushService extends NCMBService { public void updatePushInBackground(final String pushId, final JSONObject params, final ExecuteServiceCallback callback) { try { if (pushId == null) { throw new NCMBException(NCMBException.INVALID_JSON, "pushId must no be null"); } else if (params == null) { throw new NCMBException(NCMBException.INVALID_JSON, "params must no be null"); } else if (params.has("deliveryTime") && params.has("immediateDeliveryFlag")) { throw new NCMBException(NCMBException.INVALID_JSON, "'deliveryTime' and 'immediateDeliveryFlag' can not be set at the same time."); } RequestParams request = createRequestParams(pushId, params, null, NCMBRequest.HTTP_METHOD_PUT); sendRequestAsync(request, new PushServiceCallback(this, callback) { @Override public void handleResponse(NCMBResponse response){ ExecuteServiceCallback callback = (ExecuteServiceCallback) mCallback; if (callback != null) { callback.done(response.responseData, null); } } @Override public void handleError(NCMBException e) { ExecuteServiceCallback callback = (ExecuteServiceCallback) mCallback; if (callback != null) { callback.done(null, e); } } }); } catch (NCMBException error) { if (callback != null) { callback.done(null, error); } } } NCMBPushService(NCMBContext context); JSONObject sendPush(JSONObject params); void sendPushInBackground(final JSONObject params, ExecuteServiceCallback callback); JSONObject updatePush(String pushId, JSONObject params); void updatePushInBackground(final String pushId, final JSONObject params, final ExecuteServiceCallback callback); void deletePush(String pushId); void deletePushInBackground(String pushId, DoneCallback callback); NCMBPush fetchPush(String pushId); void fetchPushInBackground(final String pushId, final FetchCallback callback); List searchPush(JSONObject conditions); void searchPushInBackground(JSONObject conditions, final SearchPushCallback callback); void sendPushReceiptStatusInBackground(String pushId, ExecuteServiceCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_PUSH_CREATED; static final int HTTP_STATUS_PUSH_UPDATED; static final int HTTP_STATUS_PUSH_DELETED; static final int HTTP_STATUS_PUSH_GOTTEN; static final int HTTP_STATUS_PUSH_RECEIPTSTATUS; }
@Test public void updatePushInBackground() throws Exception { Assert.assertFalse(callbackFlag); NCMBPushService pushService = (NCMBPushService) NCMB.factory(NCMB.ServiceType.PUSH); JSONObject params = new JSONObject(); params.put("title", "title_update"); params.put("message", "message_update"); pushService.updatePushInBackground("7FrmPTBKSNtVjajm", params, new ExecuteServiceCallback() { @Override public void done(JSONObject json, NCMBException e) { Assert.assertNull(e); try { Assert.assertEquals("2014-06-04T11:28:30.348Z", json.getString("updateDate")); } catch (JSONException error) { Assert.assertNull(error); } callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); }