OAuthController implements OAuthWebViewClient.Listener { Callback<OAuthResponse> newRequestAccessTokenCallback() { return new Callback<OAuthResponse>() { @Override public void success(Result<OAuthResponse> result) { final Intent data = new Intent(); final OAuthResponse response = result.data; data.putExtra(AuthHandler.EXTRA_SCREEN_NAME, response.userName); data.putExtra(AuthHandler.EXTRA_USER_ID, response.userId); data.putExtra(AuthHandler.EXTRA_TOKEN, response.authToken.token); data.putExtra(AuthHandler.EXTRA_TOKEN_SECRET, response.authToken.secret); listener.onComplete(Activity.RESULT_OK, data); } @Override public void failure(TwitterException error) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to get access token", error); handleAuthError(AuthHandler.RESULT_CODE_ERROR, new TwitterAuthException("Failed to get access token")); } }; } OAuthController(ProgressBar spinner, WebView webView, TwitterAuthConfig authConfig,
            OAuth1aService oAuth1aService, Listener listener); @Override void onPageFinished(WebView webView, String url); @Override void onSuccess(Bundle bundle); @Override void onError(WebViewException exception);  }
@Test public void testNewAccessTokenCallback_success() { final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback(); final OAuthResponse oAuthResponse = new OAuthResponse( new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET), TestFixtures.SCREEN_NAME, TestFixtures.USER_ID); callback.success(new Result<>(oAuthResponse, null)); final ArgumentCaptor<Intent> intentArgCaptor = ArgumentCaptor.forClass(Intent.class); verify(mockListener).onComplete(eq(Activity.RESULT_OK), intentArgCaptor.capture()); final Intent data = intentArgCaptor.getValue(); assertEquals(TestFixtures.SCREEN_NAME, data.getStringExtra(AuthHandler.EXTRA_SCREEN_NAME)); assertEquals(TestFixtures.USER_ID, data.getLongExtra(AuthHandler.EXTRA_USER_ID, 0L)); assertEquals(TestFixtures.TOKEN, data.getStringExtra(AuthHandler.EXTRA_TOKEN)); assertEquals(TestFixtures.SECRET, data.getStringExtra(AuthHandler.EXTRA_TOKEN_SECRET)); }
@Test public void testNewAccessTokenCallback_failure() { final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback(); final TwitterException mockException = mock(TwitterException.class); callback.failure(mockException); verifyOnCompleteWithError("Failed to get access token"); }