Skip to content

Instantly share code, notes, and snippets.

@kenilt
Forked from romainpiel/AccessTokenCreator.java
Last active February 19, 2020 03:16
Show Gist options
  • Save kenilt/df29ff41943ed1ca0ba8ae4f85e5ed0a to your computer and use it in GitHub Desktop.
Save kenilt/df29ff41943ed1ca0ba8ae4f85e5ed0a to your computer and use it in GitHub Desktop.
package com.facebook
object AccessTokenCreator {
fun createToken(grantedPermissions: Collection<String?>?): AccessToken? {
return AccessToken("token", "appId", "userId", grantedPermissions,
ArrayList<String>(), null, AccessTokenSource.WEB_VIEW, null, null, null)
}
}
package com.facebook.login
import com.facebook.AccessTokenCreator.createToken
import com.facebook.login.LoginClient.Request
import com.facebook.login.LoginClient.Result
internal object LoginClientCreator {
fun createRequest(): Request {
val permissions: HashSet<String> = hashSetOf("user_actions.music", "user_friends", "user_likes", "email")
return Request(LoginBehavior.NATIVE_WITH_FALLBACK, permissions, DefaultAudience.EVERYONE, "authType", "appId", "authId")
}
fun createResult(): Result? {
val request: Request = createRequest()
return Result(request, Result.Code.SUCCESS, createToken(request.permissions), null, null)
}
}
@Test
fun signupWithFacebook() {
val resultData = Intent()
resultData.putExtra("com.facebook.LoginFragment:Result", LoginClientCreator.createResult())
intending(hasComponent(FacebookActivity::class.java.name))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, resultData))
activityTestRule..launchActivity(Intent())
// click signup fb button
onView(withId(R.id.signup_with_facebook_button)).perform(click())
// wait a bit while UI return the mock intent
Thread.sleep(1000)
// 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