Search in sources :

Example 6 with ParseUser

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

the class ParseTwitterUtilsTest method testIsLinked.

// endregion
@Test
public void testIsLinked() {
    ParseUser user = mock(ParseUser.class);
    when(user.isLinked(anyString())).thenReturn(true);
    assertTrue(ParseTwitterUtils.isLinked(user));
    verify(user).isLinked("twitter");
}
Also used : ParseUser(com.parse.ParseUser) Test(org.junit.Test)

Example 7 with ParseUser

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

the class ParseTwitterUtilsTest method testLogInWithContext.

@Test
@SuppressWarnings("unchecked")
public void testLogInWithContext() {
    ParseTwitterUtils.isInitialized = true;
    ParseUser user = mock(ParseUser.class);
    Map<String, String> authData = new HashMap<>();
    when(controller.authenticateAsync(any(Context.class))).thenReturn(Task.forResult(authData));
    when(userDelegate.logInWithInBackground(anyString(), anyMap())).thenReturn(Task.forResult(user));
    Context context = mock(Context.class);
    Task<ParseUser> task = ParseTwitterUtils.logInInBackground(context);
    verify(controller).authenticateAsync(context);
    verify(userDelegate).logInWithInBackground("twitter", authData);
    assertTrue(task.isCompleted());
}
Also used : Context(android.content.Context) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ParseUser(com.parse.ParseUser) Test(org.junit.Test)

Example 8 with ParseUser

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

the class ParseTwitterUtilsTest method testLogInWithToken.

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

Example 9 with ParseUser

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

the class ParseFacebookUtilsTest method doLogInWith.

private void doLogInWith(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(userDelegate.logInWithInBackground(anyString(), anyMap())).thenReturn(Task.forResult(user));
    Task<ParseUser> task;
    if (FacebookController.LoginAuthorizationType.PUBLISH.equals(type)) {
        if (activity != null) {
            task = ParseFacebookUtils.logInWithPublishPermissionsInBackground(activity, permissions);
        } else {
            task = ParseFacebookUtils.logInWithPublishPermissionsInBackground(fragment, permissions);
        }
    } else {
        if (activity != null) {
            task = ParseFacebookUtils.logInWithReadPermissionsInBackground(activity, permissions);
        } else {
            task = ParseFacebookUtils.logInWithReadPermissionsInBackground(fragment, permissions);
        }
    }
    verify(controller).authenticateAsync(activity, fragment, type, permissions);
    verify(userDelegate).logInWithInBackground("facebook", authData);
    assertTrue(task.isCompleted());
    assertEquals(user, task.getResult());
}
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 10 with ParseUser

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

the class ParseFacebookUtilsTest method testIsLinked.

// endregion
@Test
public void testIsLinked() {
    ParseUser user = mock(ParseUser.class);
    when(user.isLinked(anyString())).thenReturn(true);
    assertTrue(ParseFacebookUtils.isLinked(user));
    verify(user).isLinked("facebook");
}
Also used : 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