RxLogin { public Flowable<GoogleSignInResult> loginGoogle(Activity activity, @NonNull Scope scope, Scope... scopes) { if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(activity.getApplicationContext()) .addApi(Auth.GOOGLE_SIGN_IN_API, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestScopes(scope, scopes) .build()) .build(); } return googleObservable(activity); }  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 testLoginGoogleSuccess() throws Exception { InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); Thread.sleep(20); mRxLogin.mGoogleCallback.onSuccess(mGoogleSignInResult); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertNoErrors(); mGoogleSubscriber.assertValueCount(1); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Test public void testLoginGoogleCancel() throws Exception { InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); Thread.sleep(20); mRxLogin.mGoogleCallback.onCancel(); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertError(LoginException.class); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Test public void testLoginGoogleError() throws Exception { InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); Thread.sleep(20); mRxLogin.mGoogleCallback.onError(mGoogleSignInResult); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertError(LoginException.class); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Test public void testLoginGoogleConnectionError() throws Exception { when(mMockGoogleApiClient.blockingConnect(eq(10L), eq(TimeUnit.SECONDS))) .thenReturn(new ConnectionResult(ConnectionResult.API_UNAVAILABLE)); InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertError(LoginException.class); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }