NCMBPushService extends NCMBService { public void searchPushInBackground(JSONObject conditions, final SearchPushCallback callback) { try { final RequestParams request = createRequestParams(null, null, conditions, NCMBRequest.HTTP_METHOD_GET); sendRequestAsync(request, new PushServiceCallback(this, callback) { @Override public void handleResponse(NCMBResponse response){ ArrayList<NCMBPush> results = null; try { results = createSearchResults(response.responseData); } catch (NCMBException e) { callback.done(null, e); } SearchPushCallback callback = (SearchPushCallback) mCallback; if (callback != null) { callback.done(results, null); } } @Override public void handleError(NCMBException e) { SearchPushCallback callback = (SearchPushCallback) 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 searchPushInBackground() throws Exception { Assert.assertFalse(callbackFlag); NCMBPushService pushService = new NCMBPushService(NCMB.getCurrentContext()); JSONObject query = new JSONObject(); query.put("where", new JSONObject("{target:[android]}")); query.put("limit", 2); pushService.searchPushInBackground(query, new SearchPushCallback() { @Override public void done(ArrayList<NCMBPush> results, NCMBException e) { Assert.assertNull(e); Assert.assertEquals(2, results.size()); for (int i = 0; i < results.size(); i++) { try { Assert.assertEquals(new JSONArray("[android]"), results.get(i).getTarget()); } catch (JSONException error) { Assert.fail(error.getMessage()); } } callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); }