when(callbacks.onRestore(Matchers.<Map<String, String>>any())) .thenReturn(true); ParseUser.registerAuthenticationCallback("facebook", callbacks);
@Override public void registerAuthenticationCallback(String authType, AuthenticationCallback callback) { ParseUser.registerAuthenticationCallback(authType, callback); }
@Test public void testSynchronizeAuthData() throws Exception { // Register a mock currentUserController to make getCurrentUser work ParseUser currentUser = new ParseUser(); ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(currentUser)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); // Register mock callbacks AuthenticationCallback callbacks = mock(AuthenticationCallback.class); when(callbacks.onRestore(Matchers.<Map<String, String>>any())) .thenReturn(true); ParseUser.registerAuthenticationCallback("facebook", callbacks); // Set user initial state String authType = "facebook"; Map<String, String> authData = new HashMap<>(); authData.put("facebookToken", "facebookTest"); ParseUser.State userState = new ParseUser.State.Builder() .putAuthData(authType, authData) .build(); ParseUser user = ParseObject.from(userState); user.setIsCurrentUser(true); ParseTaskUtils.wait(user.synchronizeAuthDataAsync(authType)); // Make sure we restore authentication verify(callbacks, times(1)).onRestore(authData); }
@Test public void testSynchronizeAllAuthData() throws Exception { // Register a mock currentUserController to make getCurrentUser work ParseUser currentUser = new ParseUser(); ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(currentUser)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); // Register mock callbacks AuthenticationCallback callbacks = mock(AuthenticationCallback.class); when(callbacks.onRestore(Matchers.<Map<String, String>>any())) .thenReturn(true); ParseUser.registerAuthenticationCallback("facebook", callbacks); // Set user initial state String facebookAuthType = "facebook"; Map<String, String> facebookAuthData = new HashMap<>(); facebookAuthData.put("facebookToken", "facebookTest"); ParseUser.State userState = new ParseUser.State.Builder() .putAuthData(facebookAuthType, facebookAuthData) .build(); ParseUser user = ParseObject.from(userState); user.setIsCurrentUser(true); ParseTaskUtils.wait(user.synchronizeAllAuthDataAsync()); // Make sure we restore authentication verify(callbacks, times(1)).onRestore(facebookAuthData); }
/** * Initializes Facebook with a custom {@code appId} for use with Parse. * <p/> * This method is only required if you intend to use a different {@code appId} than is defined by * {@code com.facebook.sdk.ApplicationId} in your {@code AndroidManifest.xml}. You may also invoke * this method more than once if you need to change the appId. * <p /> * <b>IMPORTANT:</b> If you choose to enable single sign-on, you must override the * {@link Activity#onActivityResult(int, int, android.content.Intent)} method to invoke * {@link #finishAuthentication(int, int, Intent)}. * * @param context * The application context. * @param appId * The Facebook appId for your application. * @see #logIn(Collection, Activity, int, LogInCallback) * @see #link(ParseUser, Collection, Activity, int, SaveCallback) */ public static void initialize(Context context, String appId) { provider = new FacebookAuthenticationProvider(context, appId); ParseUser.registerAuthenticationCallback(FacebookAuthenticationProvider.AUTH_TYPE, provider); isInitialized = true; }