@Override public Task<Void> then(Task<Void> task) { return signUpAsync(task); } });
if (getAuthData().size() == 0) { // TODO(grantland): Could we just check isDirty(KEY_AUTH_DATA)? return signUpAsync(toAwait);
@Test public void testSignUpAsyncWithObjectIdSetAndAuthDataSet() throws Exception { // Register a mock currentUserController to make getCurrentUser work ParseUser currentUser = mock(ParseUser.class); when(currentUser.getSessionToken()).thenReturn("sessionToken"); ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(currentUser)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); ParseUser.State userState = new ParseUser.State.Builder() .objectId("test") .putAuthData(ParseAnonymousUtils.AUTH_TYPE, null) .build(); ParseUser user = ParseObject.from(userState); user.setUsername("userName"); user.setPassword("password"); //TODO (mengyan): Avoid using partial mock after we have ParseObjectInstanceController ParseUser partialMockUser = spy(user); doReturn(Task.<Void>forResult(null)) .when(partialMockUser) .saveAsync(anyString(), Matchers.<Task<Void>>any()); ParseTaskUtils.wait(partialMockUser.signUpAsync(Task.<Void>forResult(null))); // Verify user is saved verify(partialMockUser, times(1)).saveAsync(eq("sessionToken"), Matchers.<Task<Void>>any()); }
user.putAuthData(ParseAnonymousUtils.AUTH_TYPE, anonymousAuthData); Task<Void> signUpTask = user.signUpAsync(Task.<Void>forResult(null)); signUpTask.waitForCompletion();
user.putAuthData(ParseAnonymousUtils.AUTH_TYPE, anonymousAuthData); Task<Void> signUpTask = user.signUpAsync(Task.<Void>forResult(null)); signUpTask.waitForCompletion();
@Test public void testSignUpAsyncWithNoUserName() throws Exception { // Register a mock currentUserController to make getCurrentUser work 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))); }
@Test public void testSignUpAsyncWithNoCurrentUserAndSignUpFailure() { // Register a mock currentUserController to make getCurrentUser work ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())) .thenReturn(Task.<ParseUser>forResult(null)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); // Register a mock userController to make logIn work ParseUserController userController = mock(ParseUserController.class); ParseException signUpException = new ParseException(ParseException.OTHER_CAUSE, "test"); when(userController.signUpAsync( any(ParseUser.State.class), any(ParseOperationSet.class), anyString())) .thenReturn(Task.<ParseUser.State>forError(signUpException)); ParseCorePlugins.getInstance().registerUserController(userController); ParseUser user = new ParseUser(); user.put("key", "value"); user.setUsername("userName"); user.setPassword("password"); Task<Void> signUpTask = user.signUpAsync(Task.<Void>forResult(null)); // Make sure we sign up the user verify(userController, times(1)).signUpAsync( any(ParseUser.State.class), any(ParseOperationSet.class), anyString()); // Make sure user's data is correct assertEquals("value", user.getString("key")); // Make sure we never set the current user verify(currentUserController, never()).setAsync(user); // Make sure task is failed assertTrue(signUpTask.isFaulted()); assertSame(signUpException, signUpTask.getError()); }
@Test public void testSignUpAsyncWithNoPassword() throws Exception { // Register a mock currentUserController to make getCurrentUser work ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.<ParseUser>forResult(null)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); ParseUser user = new ParseUser(); user.setUsername("userName"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Password cannot be missing or blank"); ParseTaskUtils.wait(user.signUpAsync(Task.<Void>forResult(null))); }
@Test public void testSignUpAsyncWithSignUpSameAnonymousUser() throws Exception { ParseUser user = new ParseUser(); user.setUsername("userName"); user.setPassword("password"); Map<String, String> anonymousAuthData = new HashMap<>(); anonymousAuthData.put("key", "token"); user.putAuthData(ParseAnonymousUtils.AUTH_TYPE, anonymousAuthData); // Register a mock currentUserController to make getCurrentUser work ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(user)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Attempt to merge currentUser with itself."); ParseTaskUtils.wait(user.signUpAsync(Task.<Void>forResult(null))); }
user.setPassword("password"); ParseTaskUtils.wait(user.signUpAsync(Task.<Void>forResult(null)));
@Test public void testSignUpAsyncWithAnotherSignUpAlreadyRunning() throws Exception { // Register a mock currentUserController to make getCurrentUser work ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.<ParseUser>forResult(null)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); ParseUser user = new ParseUser(); user.setUsername("userName"); user.setPassword("password"); user.startSave(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Cannot sign up a user that is already signing up."); ParseTaskUtils.wait(user.signUpAsync(Task.<Void>forResult(null))); }
@Test public void testSignUpAsyncWithObjectIdSetAndAuthDataNotSet() throws Exception { // Register a mock currentUserController to make getCurrentUser work ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.<ParseUser>forResult(null)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); ParseUser.State userState = new ParseUser.State.Builder() .objectId("test") .build(); ParseUser user = ParseObject.from(userState); user.setUsername("userName"); user.setPassword("password"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Cannot sign up a user that has already signed up."); ParseTaskUtils.wait(user.signUpAsync(Task.<Void>forResult(null))); }