@Override public Task<Void> then(Task<Boolean> task) { boolean success = !task.isFaulted() && task.getResult(); if (!success) { return unlinkFromInBackground(authType); } return task.makeVoid(); } });
@Test public void testUnlinkFromAsyncWithAuthType() throws Exception { // Register a mock currentUserController to make getAsync work ParseUser mockUser = mock(ParseUser.class); when(mockUser.getSessionToken()).thenReturn("sessionToken"); ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync()).thenReturn(Task.forResult(mockUser)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); // Set user initial state String authType = "facebook"; Map<String, String> authData = new HashMap<>(); authData.put("facebookToken", "facebookTest"); ParseUser.State userState = new ParseUser.State.Builder() .objectId("test") .putAuthData(authType, authData) .build(); ParseUser user = ParseObject.from(userState); ParseUser partialMockUser = spy(user); doReturn(Task.<Void>forResult(null)) .when(partialMockUser) .saveAsync(anyString(), Matchers.<Task<Void>>any()); ParseTaskUtils.wait(partialMockUser.unlinkFromInBackground(authType)); // Verify we delete authData assertNull(user.getAuthData().get("facebook")); // Verify we save the user verify(partialMockUser, times(1)).saveAsync(eq("sessionToken"), Matchers.<Task<Void>>any()); }
/** * Unlink a user from a Facebook account. This will save the user's data. * * @param user The user to unlink. * @return A task that will be resolved when unlinking has completed. */ public static Task<Void> unlinkInBackground(ParseUser user) { checkInitialization(); return user.unlinkFromInBackground(AUTH_TYPE); }
/** * Unlinks a user from a Facebook account in the background. Unlinking a user will save the user's * data. * * @param user * The user to unlink from Facebook. * @return A Task that will be resolved when unlinking has completed. */ public static Task<Void> unlinkInBackground(ParseUser user) { checkInitialization(); return user.unlinkFromInBackground(provider.getAuthType()); }
@Test public void testUnlinkInBackground() { ParseUser user = mock(ParseUser.class); when(user.unlinkFromInBackground(anyString())).thenReturn(Task.<Void>forResult(null)); ParseFacebookUtils.isInitialized = true; ParseFacebookUtils.unlinkInBackground(user); verify(user).unlinkFromInBackground("facebook"); } }