OAuthWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith(completeUrl)) { final TreeMap<String, String> params = UrlUtils.getQueryParams(URI.create(url), false); final Bundle bundle = new Bundle(params.size()); for (Map.Entry<String, String> entry : params.entrySet()) { bundle.putString(entry.getKey(), entry.getValue()); } listener.onSuccess(bundle); return true; } return super.shouldOverrideUrlLoading(view, url); } OAuthWebViewClient(String completeUrl, Listener listener); @Override void onPageFinished(WebView view, String url); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl); @Override void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error);  }
@Test public void testShouldOverrideUrlLoading_urlStartsWithCompleteUrl() { webViewClient.shouldOverrideUrlLoading(mock(WebView.class), RETURNED_URL); final ArgumentCaptor<Bundle> bundleArgCaptor = ArgumentCaptor.forClass(Bundle.class); verify(mockListener).onSuccess(bundleArgCaptor.capture()); final Bundle bundle = bundleArgCaptor.getValue(); assertEquals(EXPECTED_VERSION_VALUE, bundle.getString(EXPECTED_VERSION_KEY)); assertEquals(EXPECTED_APP_VALUE, bundle.getString(EXPECTED_APP_KEY)); assertEquals(EXPECTED_OAUTH_TOKEN_VALUE, bundle.getString(EXPECTED_OAUTH_TOKEN_KEY)); assertEquals(EXPECTED_OAUTH_VERIFIER_VALUE, bundle.getString(EXPECTED_OAUTH_VERIFIER_KEY)); }
@Test public void testShouldOverrideUrlLoading_urlDoesNotStartWithCompleteUrl() { webViewClient.shouldOverrideUrlLoading(mock(WebView.class), TEST_URL); verifyZeroInteractions(mockListener); }