XingOAuth { @Nullable public OAuthResponse onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != Shared.REQUEST_CODE) return null; if (resultCode == Activity.RESULT_OK) { Bundle extras = data.getExtras(); String token = extras.getString(Shared.TOKEN, ""); String tokenSecret = extras.getString(Shared.TOKEN_SECRET, ""); if (callback != null) { callback.onSuccess(extras.getString(Shared.TOKEN, ""), extras.getString(Shared.TOKEN_SECRET, "")); } return OAuthResponse.success(token, tokenSecret); } if (callback != null) { callback.onError(); } return OAuthResponse.error("Aborted"); } XingOAuth(String consumerKey, String consumerSecret, String callbackUrl, XingOAuthCallback callback); void loginWithXing(Activity activity); void loginWithXing(Fragment fragment); void loginWithXing(androidx.fragment.app.Fragment fragment); @Nullable OAuthResponse onActivityResult(int requestCode, int resultCode, Intent data);  }
@Test public void onActivityResultHandlesSuccess() throws Exception { XingOAuth xingOAuth = buildTestXingOauth(); Intent data = new Intent(); data.putExtra(Shared.TOKEN, "test"); data.putExtra(Shared.TOKEN_SECRET, "test_test"); OAuthResponse response = xingOAuth.onActivityResult(Shared.REQUEST_CODE, Activity.RESULT_OK, data); assertThat(response).isNotNull(); assertThat(response.isSuccessful()).isTrue(); assertThat(response.token()).isEqualTo("test"); assertThat(response.tokenSecret()).isEqualTo("test_test"); }
@Test public void onActivityResultHandlesError() throws Exception { XingOAuth xingOAuth = buildTestXingOauth(); Intent data = new Intent(); OAuthResponse response = xingOAuth.onActivityResult(Shared.REQUEST_CODE, Activity.RESULT_CANCELED, data); assertThat(response).isNotNull(); assertThat(response.isSuccessful()).isFalse(); assertThat(response.token()).isNullOrEmpty(); assertThat(response.tokenSecret()).isNullOrEmpty(); }
@Test public void onActivityResultIgnoresOtherResults() throws Exception { XingOAuth xingOAuth = buildTestXingOauth(); Intent data = new Intent(); OAuthResponse response = xingOAuth.onActivityResult(345, Activity.RESULT_CANCELED, data); assertThat(response).isNull(); }