NCMBInstallationService extends NCMBService { public void searchInstallationInBackground(JSONObject conditions, final SearchInstallationCallback callback) { try { final RequestParams request = createRequestParams(null, null, conditions, NCMBRequest.HTTP_METHOD_GET); sendRequestAsync(request, new InstallationServiceCallback(this, callback) { @Override public void handleResponse(NCMBResponse response) { ArrayList<NCMBInstallation> array = null; try { array = createSearchResults(response.responseData); } catch (NCMBException e) { callback.done(null, e); } SearchInstallationCallback callback = (SearchInstallationCallback) mCallback; if (callback != null) { callback.done(array, null); } } @Override public void handleError(NCMBException e) { SearchInstallationCallback callback = (SearchInstallationCallback) mCallback; if (callback != null) { callback.done(null, e); } } }); } catch (NCMBException error) { if (callback != null) { callback.done(null, error); } } } NCMBInstallationService(NCMBContext context); JSONObject createInstallation(String registrationId, JSONObject params); void createInstallationInBackground(String registrationId, JSONObject params, final ExecuteServiceCallback callback); JSONObject updateInstallation(String objectId, JSONObject params); void updateInstallationInBackground(final String objectId, JSONObject params, final ExecuteServiceCallback callback); void deleteInstallation(String objectId); void deleteInstallationInBackground(final String objectId, DoneCallback callback); NCMBInstallation fetchInstallation(String objectId); void fetchInstallationInBackground(String objectId, final FetchCallback callback); List searchInstallation(JSONObject conditions); void searchInstallationInBackground(JSONObject conditions, final SearchInstallationCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_INSTALLATION_CREATED; static final int HTTP_STATUS_INSTALLATION_UPDATED; static final int HTTP_STATUS_INSTALLATION_DELETED; static final int HTTP_STATUS_INSTALLATION_GOTTEN; }
@Test public void searchInstallationInBackground() throws Exception { Assert.assertFalse(callbackFlag); JSONObject query = new JSONObject(); query.put("where", new JSONObject("{deviceType:android}")); query.put("limit", 2); NCMBInstallationService installationService = (NCMBInstallationService) NCMB.factory(NCMB.ServiceType.INSTALLATION); installationService.searchInstallationInBackground(query, new SearchInstallationCallback() { public void done(ArrayList<NCMBInstallation> results, NCMBException e) { Assert.assertNull(e); for (int i = 0; i < results.size(); i++) { Assert.assertEquals("android", results.get(i).getDeviceType()); } callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); }