Skip to content

Instantly share code, notes, and snippets.

@romainpiel
Created March 22, 2016 16:18
Show Gist options
  • Save romainpiel/e4f64da5b74c23cc27cf to your computer and use it in GitHub Desktop.
Save romainpiel/e4f64da5b74c23cc27cf to your computer and use it in GitHub Desktop.
package com.facebook;
import java.util.ArrayList;
import java.util.Collection;
public class AccessTokenCreator {
public static AccessToken createToken(Collection<String> grantedPermissions) {
return new AccessToken("token", "appId", "userId", grantedPermissions,
new ArrayList<String>(), AccessTokenSource.WEB_VIEW, null, null);
}
}
package com.facebook.login;
import android.support.test.espresso.core.deps.guava.collect.Sets;
import com.facebook.AccessTokenCreator;
import com.facebook.login.LoginClient.Request;
import com.facebook.login.LoginClient.Result;
import java.util.HashSet;
public class LoginClientCreator {
public static Request createRequest() {
final HashSet<String> permissions = Sets.newHashSet("user_actions.music", "user_friends", "user_likes", "email");
return new Request(LoginBehavior.NATIVE_WITH_FALLBACK, permissions, DefaultAudience.EVERYONE, "appId", "authId");
}
public static Result createResult() {
final Request request = createRequest();
return new Result(request, Result.Code.SUCCESS, AccessTokenCreator.createToken(request.getPermissions()), null, null);
}
}
@Test
public void signupWithFacebook() {
Context context = InstrumentationRegistry.getInstrumentation().getContext();
final Intent resultData = new Intent();
resultData.putExtra("com.facebook.LoginFragment:Result", LoginClientCreator.createResult());
intending(hasComponent(FacebookActivity.class.getName()))
.respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData));
activityTestRule.launchActivity(LoginSignupActivity.buildIntent(context));
// click signup fb button
onView(withId(R.id.signup_with_facebook_button))
.perform(click());
// check facebook intent was hit
intended(hasComponent(FacebookActivity.class.getName()), times(1));
// check UI is showing the user as logged in
...
}
@hafs-r
Copy link

hafs-r commented Jul 2, 2019

@RozinaDarediya look at the package name used for class it is 'package com.facebook.login', so use the same

@kenilt
Copy link

kenilt commented Feb 19, 2020

I have added a Kotlin version with some updates here: https://gist.github.com/kenilt/df29ff41943ed1ca0ba8ae4f85e5ed0a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment