Search in sources :

Example 1 with ParseUser

use of com.parse.ParseUser in project Parse-SDK-Android by ParsePlatform.

the class ParseFacebookUtilsTest method testLinkWithAccessToken.

// endregion
// region testLink
@Test
public void testLinkWithAccessToken() {
    Map<String, String> authData = new HashMap<>();
    when(controller.getAuthData(any(AccessToken.class))).thenReturn(authData);
    ParseFacebookUtils.isInitialized = true;
    ParseUser user = mock(ParseUser.class);
    when(user.linkWithInBackground(anyString(), anyMap())).thenReturn(Task.forResult(null));
    AccessToken token = TestUtils.newAccessToken();
    Task<Void> task = ParseFacebookUtils.linkInBackground(user, token);
    verify(controller).getAuthData(token);
    verify(user).linkWithInBackground("facebook", authData);
    assertTrue(task.isCompleted());
}
Also used : HashMap(java.util.HashMap) AccessToken(com.facebook.AccessToken) Matchers.anyString(org.mockito.Matchers.anyString) ParseUser(com.parse.ParseUser) Test(org.junit.Test)

Example 2 with ParseUser

use of com.parse.ParseUser in project Parse-SDK-Android by ParsePlatform.

the class ParseFacebookUtilsTest method doLinkWith.

private void doLinkWith(Activity activity, Fragment fragment, Collection<String> permissions, FacebookController.LoginAuthorizationType type) {
    assertFalse("Cannot run test with both Activity and Fragment", activity != null && fragment != null);
    Map<String, String> authData = new HashMap<>();
    when(controller.authenticateAsync(nullable(Activity.class), nullable(Fragment.class), any(FacebookController.LoginAuthorizationType.class), anyList())).thenReturn(Task.forResult(authData));
    ParseFacebookUtils.isInitialized = true;
    ParseUser user = mock(ParseUser.class);
    when(user.linkWithInBackground(anyString(), anyMap())).thenReturn(Task.forResult(null));
    Task<Void> task;
    if (FacebookController.LoginAuthorizationType.PUBLISH.equals(type)) {
        if (activity != null) {
            task = ParseFacebookUtils.linkWithPublishPermissionsInBackground(user, activity, permissions);
        } else {
            task = ParseFacebookUtils.linkWithPublishPermissionsInBackground(user, fragment, permissions);
        }
    } else {
        if (activity != null) {
            task = ParseFacebookUtils.linkWithReadPermissionsInBackground(user, activity, permissions);
        } else {
            task = ParseFacebookUtils.linkWithReadPermissionsInBackground(user, fragment, permissions);
        }
    }
    verify(controller).authenticateAsync(activity, fragment, type, permissions);
    verify(user).linkWithInBackground("facebook", authData);
    assertTrue(task.isCompleted());
}
Also used : HashMap(java.util.HashMap) Activity(android.app.Activity) Matchers.anyString(org.mockito.Matchers.anyString) Fragment(androidx.fragment.app.Fragment) ParseUser(com.parse.ParseUser)

Example 3 with ParseUser

use of com.parse.ParseUser in project Parse-SDK-Android by ParsePlatform.

the class ParseFacebookUtilsTest method testLogInWithAccessToken.

// region testLogIn
@Test
public void testLogInWithAccessToken() {
    Map<String, String> authData = new HashMap<>();
    when(controller.getAuthData(any(AccessToken.class))).thenReturn(authData);
    ParseFacebookUtils.isInitialized = true;
    ParseUser user = mock(ParseUser.class);
    when(userDelegate.logInWithInBackground(anyString(), anyMap())).thenReturn(Task.forResult(user));
    AccessToken token = TestUtils.newAccessToken();
    Task<ParseUser> task = ParseFacebookUtils.logInInBackground(token);
    verify(controller).getAuthData(token);
    verify(userDelegate).logInWithInBackground("facebook", authData);
    assertTrue(task.isCompleted());
    assertEquals(user, task.getResult());
}
Also used : HashMap(java.util.HashMap) AccessToken(com.facebook.AccessToken) Matchers.anyString(org.mockito.Matchers.anyString) ParseUser(com.parse.ParseUser) Test(org.junit.Test)

Example 4 with ParseUser

use of com.parse.ParseUser in project Parse-SDK-Android by ParsePlatform.

the class ParseFacebookUtilsTest method testUnlinkInBackground.

// endregion
@Test
public void testUnlinkInBackground() {
    ParseUser user = mock(ParseUser.class);
    when(user.unlinkFromInBackground(anyString())).thenReturn(Task.forResult(null));
    ParseFacebookUtils.isInitialized = true;
    ParseFacebookUtils.unlinkInBackground(user);
    verify(user).unlinkFromInBackground("facebook");
}
Also used : ParseUser(com.parse.ParseUser) Test(org.junit.Test)

Example 5 with ParseUser

use of com.parse.ParseUser in project Parse-SDK-Android by ParsePlatform.

the class ParseTwitterUtilsTest method testLinkWithToken.

// endregion
// region testLink
@Test
@SuppressWarnings("unchecked")
public void testLinkWithToken() {
    ParseTwitterUtils.isInitialized = true;
    ParseUser user = mock(ParseUser.class);
    when(user.linkWithInBackground(anyString(), anyMap())).thenReturn(Task.forResult(null));
    String twitterId = "test_id";
    String screenName = "test_screen_name";
    String authToken = "test_token";
    String authSecret = "test_secret";
    Task<Void> task = ParseTwitterUtils.linkInBackground(user, twitterId, screenName, authToken, authSecret);
    verify(controller).getAuthData(twitterId, screenName, authToken, authSecret);
    verify(user).linkWithInBackground(eq("twitter"), anyMap());
    assertTrue(task.isCompleted());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) ParseUser(com.parse.ParseUser) Test(org.junit.Test)

Aggregations

ParseUser (com.parse.ParseUser)12 Test (org.junit.Test)10 Matchers.anyString (org.mockito.Matchers.anyString)8 HashMap (java.util.HashMap)6 Activity (android.app.Activity)2 Context (android.content.Context)2 Fragment (androidx.fragment.app.Fragment)2 AccessToken (com.facebook.AccessToken)2