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 | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have added a Kotlin version with some updates here: https://gist.github.com/kenilt/df29ff41943ed1ca0ba8ae4f85e5ed0a