RxLogin { public Flowable<LoginResult> loginFacebook(Activity activity, boolean publish, List<String> permissions) { if (mFbManager == null) { mFbManager = com.facebook.login.LoginManager.getInstance(); } return Flowable.create(new FacebookSubscriber(this), BackpressureStrategy.DROP) .doOnSubscribe(subscription -> { mFbManager.logOut(); if (publish) { mFbManager.logInWithPublishPermissions(activity, permissions); } else { mFbManager.logInWithReadPermissions(activity, permissions); } }) .doOnTerminate(() -> { mFbManager = null; mFacebookCallback = null; mCallbackManager = null; }); }  Flowable<LoginResult> loginFacebook(Activity activity, boolean publish,
        List<String> permissions); Flowable<GoogleSignInResult> loginGoogle(Activity activity, @NonNull Scope scope,
        Scope... scopes); Flowable<GoogleSignInResult> loginGoogle(Activity activity, @NonNull String
        webClientId, @NonNull Scope scope, Scope... scopes); Flowable<Result<TwitterSession>> loginTwitter(Activity activity); void registerCallback(final FacebookCallback<LoginResult> callback); void registerCallback(GoogleCallback callback); void registerCallback(Callback<TwitterSession> callback); boolean onActivityResult(int requestCode, int resultCode, Intent data);  }
@Test public void testLoginFacebookSuccess() { com.facebook.login.LoginManager mockLoginManager = mock(com.facebook.login.LoginManager.class); InOrder inOrder = inOrder(mockLoginManager); mRxLogin.mFbManager = mockLoginManager; mRxLogin.loginFacebook(mActivity, mPublish, Arrays.asList( "public_profile", "email", "user_friends")) .subscribe(mFacebookSubscriber); mRxLogin.mFacebookCallback.onSuccess(mLoginResult); mFacebookSubscriber.awaitTerminalEvent(); inOrder.verify(mockLoginManager).logOut(); if (mPublish) { inOrder.verify(mockLoginManager).logInWithPublishPermissions(eq(mActivity), eq(Arrays.asList( "public_profile", "email", "user_friends"))); } else { inOrder.verify(mockLoginManager).logInWithReadPermissions(eq(mActivity), eq(Arrays.asList( "public_profile", "email", "user_friends"))); } mFacebookSubscriber.assertNoErrors(); mFacebookSubscriber.assertValueCount(1); mFacebookSubscriber.assertTerminated(); assertThat(mRxLogin.mFbManager).isNull(); assertThat(mRxLogin.mFacebookCallback).isNull(); assertThat(mRxLogin.mCallbackManager).isNull(); }
@Test public void testLoginFacebookCancel() { com.facebook.login.LoginManager mockLoginManager = mock(com.facebook.login.LoginManager.class); InOrder inOrder = inOrder(mockLoginManager); mRxLogin.mFbManager = mockLoginManager; mRxLogin.loginFacebook(mActivity, mPublish, Arrays.asList( "public_profile", "email", "user_friends")) .subscribe(mFacebookSubscriber); mRxLogin.mFacebookCallback.onCancel(); mFacebookSubscriber.awaitTerminalEvent(); inOrder.verify(mockLoginManager).logOut(); if (mPublish) { inOrder.verify(mockLoginManager).logInWithPublishPermissions(eq(mActivity), eq(Arrays.asList( "public_profile", "email", "user_friends"))); } else { inOrder.verify(mockLoginManager).logInWithReadPermissions(eq(mActivity), eq(Arrays.asList( "public_profile", "email", "user_friends"))); } mFacebookSubscriber.assertError(LoginException.class); mFacebookSubscriber.assertTerminated(); assertThat(mRxLogin.mFbManager).isNull(); assertThat(mRxLogin.mFacebookCallback).isNull(); assertThat(mRxLogin.mCallbackManager).isNull(); }
@Test public void testLoginFacebookError() { com.facebook.login.LoginManager mockLoginManager = mock(com.facebook.login.LoginManager.class); InOrder inOrder = inOrder(mockLoginManager); mRxLogin.mFbManager = mockLoginManager; mRxLogin.loginFacebook(mActivity, mPublish, Arrays.asList( "public_profile", "email", "user_friends")) .subscribe(mFacebookSubscriber); mRxLogin.mFacebookCallback.onError(new FacebookException()); mFacebookSubscriber.awaitTerminalEvent(); inOrder.verify(mockLoginManager).logOut(); if (mPublish) { inOrder.verify(mockLoginManager).logInWithPublishPermissions(eq(mActivity), eq(Arrays.asList( "public_profile", "email", "user_friends"))); } else { inOrder.verify(mockLoginManager).logInWithReadPermissions(eq(mActivity), eq(Arrays.asList( "public_profile", "email", "user_friends"))); } mFacebookSubscriber.assertError(LoginException.class); mFacebookSubscriber.assertTerminated(); assertThat(mRxLogin.mFbManager).isNull(); assertThat(mRxLogin.mFacebookCallback).isNull(); assertThat(mRxLogin.mCallbackManager).isNull(); }