Created
March 22, 2016 16:18
-
-
Save romainpiel/e4f64da5b74c23cc27cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
... | |
} |
What's the implementation of buildIntent ?
activityTestRule.launchActivity(LoginSignupActivity.buildIntent(context));
@tasomaniac @romainpiel
what is LoginSignupActivity.buildIntent(context)?
I am getting error "com.facebook.login.LoginClient.Request is not a public class in com.facebook.login can not be accessed from outside package"
@RozinaDarediya look at the package name used for class it is 'package com.facebook.login', so use the same
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
Worked great for me. Thanks for figuring this out.
I just inlined
AccessTokenCreator
class because it only has a dependency toAccessToken
which is public. I thought 1 less class would be better.