@Test public void testSignUpAsyncWithNoUserName() throws Exception { ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.<ParseUser>forResult(null)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); ParseUser user = new ParseUser(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Username cannot be missing or blank"); ParseTaskUtils.wait(user.signUpAsync(Task.<Void>forResult(null))); }
Task<Void> signUpAsync(Task<Void> toAwait) { final ParseUser user = getCurrentUser(); synchronized (mutex) { final String sessionToken = user != null ? user.getSessionToken() : null; if (ParseTextUtils.isEmpty(getUsername())) { return Task.forError(new IllegalArgumentException("Username cannot be missing or blank")); } if (ParseTextUtils.isEmpty(getPassword())) { return Task.forError(new IllegalArgumentException("Password cannot be missing or blank")); } if (getObjectId() != null) { Map<String, Map<String, String>> authData = getAuthData(); if (authData.containsKey(ParseAnonymousUtils.AUTH_TYPE) && authData.get(ParseAnonymousUtils.AUTH_TYPE) == null) { return saveAsync(sessionToken, toAwait); } return Task.forError( new IllegalArgumentException("Cannot sign up a user that has already signed up.")); } if (operationSetQueue.size() > 1) { return Task.forError( new IllegalArgumentException("Cannot sign up a user that is already signing up.")); } if (user != null && ParseAnonymousUtils.isLinked(user)) { if (this == user) { return Task.forError( new IllegalArgumentException("Attempt to merge currentUser with itself.")); } boolean isLazy = user.isLazy(); final String oldUsername = user.getUsername(); final String oldPassword = user.getPassword(); final Map<String, String> anonymousData = user.getAuthData(ParseAnonymousUtils.AUTH_TYPE); user.copyChangesFrom(this); user.setUsername(getUsername()); user.setPassword(getPassword()); revert(); return user.saveAsync(sessionToken, isLazy, toAwait).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (task.isCancelled() || task.isFaulted()) { synchronized (user.mutex) { if (oldUsername != null) { user.setUsername(oldUsername); } else { user.revert(KEY_USERNAME); } if (oldPassword != null) { user.setPassword(oldPassword); } else { user.revert(KEY_PASSWORD); } user.restoreAnonymity(anonymousData); } return task; } else { user.revert(KEY_PASSWORD); revert(KEY_PASSWORD); } mergeFromObject(user); return saveCurrentUserAsync(ParseUser.this); } }); } final ParseOperationSet operations = startSave(); return toAwait.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return getUserController().signUpAsync( getState(), operations, sessionToken ).continueWithTask(new Continuation<ParseUser.State, Task<Void>>() { @Override public Task<Void> then(final Task<ParseUser.State> signUpTask) { ParseUser.State result = signUpTask.getResult(); return handleSaveResultAsync(result, operations).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (!signUpTask.isCancelled() && !signUpTask.isFaulted()) { return saveCurrentUserAsync(ParseUser.this); } return signUpTask.makeVoid(); } }); } }); } }); } }
ParseUser extends ParseObject { Task<Void> signUpAsync(Task<Void> toAwait) { final ParseUser user = getCurrentUser(); synchronized (mutex) { final String sessionToken = user != null ? user.getSessionToken() : null; if (ParseTextUtils.isEmpty(getUsername())) { return Task.forError(new IllegalArgumentException("Username cannot be missing or blank")); } if (ParseTextUtils.isEmpty(getPassword())) { return Task.forError(new IllegalArgumentException("Password cannot be missing or blank")); } if (getObjectId() != null) { Map<String, Map<String, String>> authData = getAuthData(); if (authData.containsKey(ParseAnonymousUtils.AUTH_TYPE) && authData.get(ParseAnonymousUtils.AUTH_TYPE) == null) { return saveAsync(sessionToken, toAwait); } return Task.forError( new IllegalArgumentException("Cannot sign up a user that has already signed up.")); } if (operationSetQueue.size() > 1) { return Task.forError( new IllegalArgumentException("Cannot sign up a user that is already signing up.")); } if (user != null && ParseAnonymousUtils.isLinked(user)) { if (this == user) { return Task.forError( new IllegalArgumentException("Attempt to merge currentUser with itself.")); } boolean isLazy = user.isLazy(); final String oldUsername = user.getUsername(); final String oldPassword = user.getPassword(); final Map<String, String> anonymousData = user.getAuthData(ParseAnonymousUtils.AUTH_TYPE); user.copyChangesFrom(this); user.setUsername(getUsername()); user.setPassword(getPassword()); revert(); return user.saveAsync(sessionToken, isLazy, toAwait).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (task.isCancelled() || task.isFaulted()) { synchronized (user.mutex) { if (oldUsername != null) { user.setUsername(oldUsername); } else { user.revert(KEY_USERNAME); } if (oldPassword != null) { user.setPassword(oldPassword); } else { user.revert(KEY_PASSWORD); } user.restoreAnonymity(anonymousData); } return task; } else { user.revert(KEY_PASSWORD); revert(KEY_PASSWORD); } mergeFromObject(user); return saveCurrentUserAsync(ParseUser.this); } }); } final ParseOperationSet operations = startSave(); return toAwait.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return getUserController().signUpAsync( getState(), operations, sessionToken ).continueWithTask(new Continuation<ParseUser.State, Task<Void>>() { @Override public Task<Void> then(final Task<ParseUser.State> signUpTask) { ParseUser.State result = signUpTask.getResult(); return handleSaveResultAsync(result, operations).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (!signUpTask.isCancelled() && !signUpTask.isFaulted()) { return saveCurrentUserAsync(ParseUser.this); } return signUpTask.makeVoid(); } }); } }); } }); } } }
ParseUser extends ParseObject { Task<Void> signUpAsync(Task<Void> toAwait) { final ParseUser user = getCurrentUser(); synchronized (mutex) { final String sessionToken = user != null ? user.getSessionToken() : null; if (ParseTextUtils.isEmpty(getUsername())) { return Task.forError(new IllegalArgumentException("Username cannot be missing or blank")); } if (ParseTextUtils.isEmpty(getPassword())) { return Task.forError(new IllegalArgumentException("Password cannot be missing or blank")); } if (getObjectId() != null) { Map<String, Map<String, String>> authData = getAuthData(); if (authData.containsKey(ParseAnonymousUtils.AUTH_TYPE) && authData.get(ParseAnonymousUtils.AUTH_TYPE) == null) { return saveAsync(sessionToken, toAwait); } return Task.forError( new IllegalArgumentException("Cannot sign up a user that has already signed up.")); } if (operationSetQueue.size() > 1) { return Task.forError( new IllegalArgumentException("Cannot sign up a user that is already signing up.")); } if (user != null && ParseAnonymousUtils.isLinked(user)) { if (this == user) { return Task.forError( new IllegalArgumentException("Attempt to merge currentUser with itself.")); } boolean isLazy = user.isLazy(); final String oldUsername = user.getUsername(); final String oldPassword = user.getPassword(); final Map<String, String> anonymousData = user.getAuthData(ParseAnonymousUtils.AUTH_TYPE); user.copyChangesFrom(this); user.setUsername(getUsername()); user.setPassword(getPassword()); revert(); return user.saveAsync(sessionToken, isLazy, toAwait).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (task.isCancelled() || task.isFaulted()) { synchronized (user.mutex) { if (oldUsername != null) { user.setUsername(oldUsername); } else { user.revert(KEY_USERNAME); } if (oldPassword != null) { user.setPassword(oldPassword); } else { user.revert(KEY_PASSWORD); } user.restoreAnonymity(anonymousData); } return task; } else { user.revert(KEY_PASSWORD); revert(KEY_PASSWORD); } mergeFromObject(user); return saveCurrentUserAsync(ParseUser.this); } }); } final ParseOperationSet operations = startSave(); return toAwait.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return getUserController().signUpAsync( getState(), operations, sessionToken ).continueWithTask(new Continuation<ParseUser.State, Task<Void>>() { @Override public Task<Void> then(final Task<ParseUser.State> signUpTask) { ParseUser.State result = signUpTask.getResult(); return handleSaveResultAsync(result, operations).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (!signUpTask.isCancelled() && !signUpTask.isFaulted()) { return saveCurrentUserAsync(ParseUser.this); } return signUpTask.makeVoid(); } }); } }); } }); } } ParseUser(); }
ParseUser extends ParseObject { Task<Void> signUpAsync(Task<Void> toAwait) { final ParseUser user = getCurrentUser(); synchronized (mutex) { final String sessionToken = user != null ? user.getSessionToken() : null; if (ParseTextUtils.isEmpty(getUsername())) { return Task.forError(new IllegalArgumentException("Username cannot be missing or blank")); } if (ParseTextUtils.isEmpty(getPassword())) { return Task.forError(new IllegalArgumentException("Password cannot be missing or blank")); } if (getObjectId() != null) { Map<String, Map<String, String>> authData = getAuthData(); if (authData.containsKey(ParseAnonymousUtils.AUTH_TYPE) && authData.get(ParseAnonymousUtils.AUTH_TYPE) == null) { return saveAsync(sessionToken, toAwait); } return Task.forError( new IllegalArgumentException("Cannot sign up a user that has already signed up.")); } if (operationSetQueue.size() > 1) { return Task.forError( new IllegalArgumentException("Cannot sign up a user that is already signing up.")); } if (user != null && ParseAnonymousUtils.isLinked(user)) { if (this == user) { return Task.forError( new IllegalArgumentException("Attempt to merge currentUser with itself.")); } boolean isLazy = user.isLazy(); final String oldUsername = user.getUsername(); final String oldPassword = user.getPassword(); final Map<String, String> anonymousData = user.getAuthData(ParseAnonymousUtils.AUTH_TYPE); user.copyChangesFrom(this); user.setUsername(getUsername()); user.setPassword(getPassword()); revert(); return user.saveAsync(sessionToken, isLazy, toAwait).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (task.isCancelled() || task.isFaulted()) { synchronized (user.mutex) { if (oldUsername != null) { user.setUsername(oldUsername); } else { user.revert(KEY_USERNAME); } if (oldPassword != null) { user.setPassword(oldPassword); } else { user.revert(KEY_PASSWORD); } user.restoreAnonymity(anonymousData); } return task; } else { user.revert(KEY_PASSWORD); revert(KEY_PASSWORD); } mergeFromObject(user); return saveCurrentUserAsync(ParseUser.this); } }); } final ParseOperationSet operations = startSave(); return toAwait.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return getUserController().signUpAsync( getState(), operations, sessionToken ).continueWithTask(new Continuation<ParseUser.State, Task<Void>>() { @Override public Task<Void> then(final Task<ParseUser.State> signUpTask) { ParseUser.State result = signUpTask.getResult(); return handleSaveResultAsync(result, operations).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (!signUpTask.isCancelled() && !signUpTask.isFaulted()) { return saveCurrentUserAsync(ParseUser.this); } return signUpTask.makeVoid(); } }); } }); } }); } } ParseUser(); static ParseQuery<ParseUser> getQuery(); static Task<ParseUser> logInInBackground(String username, String password); static ParseUser logIn(String username, String password); static void logInInBackground(final String username, final String password,
                                         LogInCallback callback); static Task<ParseUser> becomeInBackground(String sessionToken); static ParseUser become(String sessionToken); static void becomeInBackground(final String sessionToken, LogInCallback callback); static ParseUser getCurrentUser(); static String getCurrentSessionToken(); static Task<String> getCurrentSessionTokenAsync(); static Task<Void> logOutInBackground(); static void logOutInBackground(LogOutCallback callback); static void logOut(); static Task<Void> requestPasswordResetInBackground(String email); static void requestPasswordReset(String email); static void requestPasswordResetInBackground(final String email,
                                                        RequestPasswordResetCallback callback); static void registerAuthenticationCallback(
            String authType, AuthenticationCallback callback); static Task<ParseUser> logInWithInBackground(
            final String authType, final Map<String, String> authData); static void enableAutomaticUser(); static Task<Void> enableRevocableSessionInBackground(); boolean isAuthenticated(); @Override void remove(@NonNull String key); String getSessionToken(); String getUsername(); void setUsername(String username); void setPassword(String password); String getEmail(); void setEmail(String email); boolean isNew(); @Override void put(@NonNull String key, @NonNull Object value); @SuppressWarnings("unchecked") @Override ParseUser fetch(); Task<Void> signUpInBackground(); void signUp(); void signUpInBackground(SignUpCallback callback); @SuppressWarnings("unchecked") @Override ParseUser fetchIfNeeded(); boolean isLinked(String authType); Task<Void> linkWithInBackground(
            String authType, Map<String, String> authData); Task<Void> unlinkFromInBackground(final String authType); }
ParseUser extends ParseObject { Task<Void> signUpAsync(Task<Void> toAwait) { final ParseUser user = getCurrentUser(); synchronized (mutex) { final String sessionToken = user != null ? user.getSessionToken() : null; if (ParseTextUtils.isEmpty(getUsername())) { return Task.forError(new IllegalArgumentException("Username cannot be missing or blank")); } if (ParseTextUtils.isEmpty(getPassword())) { return Task.forError(new IllegalArgumentException("Password cannot be missing or blank")); } if (getObjectId() != null) { Map<String, Map<String, String>> authData = getAuthData(); if (authData.containsKey(ParseAnonymousUtils.AUTH_TYPE) && authData.get(ParseAnonymousUtils.AUTH_TYPE) == null) { return saveAsync(sessionToken, toAwait); } return Task.forError( new IllegalArgumentException("Cannot sign up a user that has already signed up.")); } if (operationSetQueue.size() > 1) { return Task.forError( new IllegalArgumentException("Cannot sign up a user that is already signing up.")); } if (user != null && ParseAnonymousUtils.isLinked(user)) { if (this == user) { return Task.forError( new IllegalArgumentException("Attempt to merge currentUser with itself.")); } boolean isLazy = user.isLazy(); final String oldUsername = user.getUsername(); final String oldPassword = user.getPassword(); final Map<String, String> anonymousData = user.getAuthData(ParseAnonymousUtils.AUTH_TYPE); user.copyChangesFrom(this); user.setUsername(getUsername()); user.setPassword(getPassword()); revert(); return user.saveAsync(sessionToken, isLazy, toAwait).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (task.isCancelled() || task.isFaulted()) { synchronized (user.mutex) { if (oldUsername != null) { user.setUsername(oldUsername); } else { user.revert(KEY_USERNAME); } if (oldPassword != null) { user.setPassword(oldPassword); } else { user.revert(KEY_PASSWORD); } user.restoreAnonymity(anonymousData); } return task; } else { user.revert(KEY_PASSWORD); revert(KEY_PASSWORD); } mergeFromObject(user); return saveCurrentUserAsync(ParseUser.this); } }); } final ParseOperationSet operations = startSave(); return toAwait.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return getUserController().signUpAsync( getState(), operations, sessionToken ).continueWithTask(new Continuation<ParseUser.State, Task<Void>>() { @Override public Task<Void> then(final Task<ParseUser.State> signUpTask) { ParseUser.State result = signUpTask.getResult(); return handleSaveResultAsync(result, operations).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (!signUpTask.isCancelled() && !signUpTask.isFaulted()) { return saveCurrentUserAsync(ParseUser.this); } return signUpTask.makeVoid(); } }); } }); } }); } } ParseUser(); static ParseQuery<ParseUser> getQuery(); static Task<ParseUser> logInInBackground(String username, String password); static ParseUser logIn(String username, String password); static void logInInBackground(final String username, final String password,
                                         LogInCallback callback); static Task<ParseUser> becomeInBackground(String sessionToken); static ParseUser become(String sessionToken); static void becomeInBackground(final String sessionToken, LogInCallback callback); static ParseUser getCurrentUser(); static String getCurrentSessionToken(); static Task<String> getCurrentSessionTokenAsync(); static Task<Void> logOutInBackground(); static void logOutInBackground(LogOutCallback callback); static void logOut(); static Task<Void> requestPasswordResetInBackground(String email); static void requestPasswordReset(String email); static void requestPasswordResetInBackground(final String email,
                                                        RequestPasswordResetCallback callback); static void registerAuthenticationCallback(
            String authType, AuthenticationCallback callback); static Task<ParseUser> logInWithInBackground(
            final String authType, final Map<String, String> authData); static void enableAutomaticUser(); static Task<Void> enableRevocableSessionInBackground(); boolean isAuthenticated(); @Override void remove(@NonNull String key); String getSessionToken(); String getUsername(); void setUsername(String username); void setPassword(String password); String getEmail(); void setEmail(String email); boolean isNew(); @Override void put(@NonNull String key, @NonNull Object value); @SuppressWarnings("unchecked") @Override ParseUser fetch(); Task<Void> signUpInBackground(); void signUp(); void signUpInBackground(SignUpCallback callback); @SuppressWarnings("unchecked") @Override ParseUser fetchIfNeeded(); boolean isLinked(String authType); Task<Void> linkWithInBackground(
            String authType, Map<String, String> authData); Task<Void> unlinkFromInBackground(final String authType);  }