OAuthController implements OAuthWebViewClient.Listener { Callback<OAuthResponse> newRequestTempTokenCallback() { return new Callback<OAuthResponse>() { @Override public void success(Result<OAuthResponse> result) { requestToken = result.data.authToken; final String authorizeUrl = oAuth1aService.getAuthorizeUrl(requestToken); Twitter.getLogger().d(TwitterCore.TAG, "Redirecting user to web view to complete authorization flow"); setUpWebView(webView, new OAuthWebViewClient(oAuth1aService.buildCallbackUrl(authConfig), OAuthController.this), authorizeUrl, new OAuthWebChromeClient()); } @Override public void failure(TwitterException error) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to get request token", error); handleAuthError(AuthHandler.RESULT_CODE_ERROR, new TwitterAuthException("Failed to get request 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 testNewRequestTempTokenCallback_success() { final Callback<OAuthResponse> callback = controller.newRequestTempTokenCallback(); final TwitterAuthToken mockRequestToken = mock(TwitterAuthToken.class); final OAuthResponse oAuthResponse = new OAuthResponse(mockRequestToken, null, 0L); callback.success(new Result<>(oAuthResponse, null)); assertEquals(mockRequestToken, controller.requestToken); verify(mockOAuth1aService).getAuthorizeUrl(eq(mockRequestToken)); }
@Test public void testNewRequestTempTokenCallback_failure() { final Callback<OAuthResponse> callback = controller.newRequestTempTokenCallback(); final TwitterException mockException = mock(TwitterException.class); callback.failure(mockException); verifyOnCompleteWithError("Failed to get request token"); }