NCMBUserService extends NCMBService { public void searchUserInBackground(JSONObject conditions, final SearchUserCallback callback) { try { RequestParams reqParams = searchUserParams(conditions); sendRequestAsync(reqParams, new UserServiceCallback(this, callback) { @Override public void handleResponse(NCMBResponse response) { ArrayList<NCMBUser> users = null; try { users = getUserService().searchUserPostProcess(response.responseData); } catch (NCMBException e) { callback.done(null, e); } SearchUserCallback callback = (SearchUserCallback) mCallback; callback.done(users, null); } @Override public void handleError(NCMBException e) { SearchUserCallback callback = (SearchUserCallback) mCallback; callback.done(null, e); } }); } catch (NCMBException e) { if (callback != null) { callback.done(null, e); } } } NCMBUserService(NCMBContext context); NCMBUser registerByName(String userName, String password); NCMBUser registerByName(String userName, String password,JSONObject otherFields); void saveByName(String userName, String password); void saveByName(String userName, String password,JSONObject otherFields); void registerByNameInBackground(String userName, String password, LoginCallback callback); void registerByNameInBackground(String userName, String password, JSONObject otherFields, LoginCallback callback); NCMBUser registerByOauth(JSONObject oauthOptions); void registerByOauthInBackground(JSONObject oauthOptions, LoginCallback callback); void inviteByMail(String mailAddress); void inviteByMailInBackground(String mailAddress, DoneCallback callback); void requestPasswordReset(String mailAddress); void requestPasswordResetInBackground(String mailAddress, DoneCallback callback); NCMBUser fetchUser(String userId); void fetchUserInBackground(String userId, final FetchCallback callback); JSONObject updateUser(String userId, JSONObject params); void updateUserInBackground(final String userId, final JSONObject params, final ExecuteServiceCallback callback); NCMBUser loginByName(String userName, String password); void loginByNameInBackground(String userName, String password,
                                        LoginCallback callback); NCMBUser loginByMail(String mailAddress, String password); void loginByMailInBackground(String mailAddress, String password,
                                        LoginCallback callback); void deleteUser(String userId); void deleteUserInBackground(final String userId, ExecuteServiceCallback callback); void logout(); void logoutInBackground(DoneCallback callback); ArrayList<NCMBUser> searchUser(JSONObject conditions); void searchUserInBackground(JSONObject conditions, final SearchUserCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_REGISTERED; static final int HTTP_STATUS_AUTHORIZED; static final int HTTP_STATUS_REQUEST_ACCEPTED; }
@Test public void searchUserAllInBackground() throws Exception { NCMBUserService userService = getUserService(); userService.searchUserInBackground(null, new SearchUserCallback() { @Override public void done(ArrayList<NCMBUser> result, NCMBException e) { Assert.assertEquals(e, null); Assert.assertEquals(result.size(), 2); NCMBUser user1 = result.get(0); Assert.assertEquals(user1.getObjectId(), "dummyObjectId01"); Assert.assertEquals(user1.getUserName(), "Ncmb Tarou"); NCMBUser user2 = result.get(1); Assert.assertEquals(user2.getObjectId(), "dummyObjectId02"); Assert.assertEquals(user2.getUserName(), "Ncmb Jirou"); callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); }
@Test public void searchUserInBackground() throws Exception { NCMBQuery<NCMBUser> query = new NCMBQuery<>("user"); query.whereEqualTo("userName", "Ncmb Tarou"); NCMBUserService userService = getUserService(); userService.searchUserInBackground(query.getConditions(), new SearchUserCallback() { @Override public void done(ArrayList<NCMBUser> result, NCMBException e) { Assert.assertEquals(e, null); Assert.assertEquals(result.size(), 1); NCMBUser user1 = result.get(0); Assert.assertEquals(user1.getObjectId(), "dummyObjectId01"); Assert.assertEquals(user1.getUserName(), "Ncmb Tarou"); callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); }