AirshipWebViewClient extends WebViewClient { protected void onClose(@NonNull WebView webView) { webView.getRootView().dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); webView.getRootView().dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK)); } AirshipWebViewClient();  AirshipWebViewClient(@NonNull ActionRunRequestFactory requestFactory); @VisibleForTesting  AirshipWebViewClient(@NonNull NativeBridge nativeBridge); void setActionCompletionCallback(@Nullable ActionCompletionCallback actionCompletionCallback); @CallSuper @Override boolean shouldOverrideUrlLoading(@NonNull WebView webView, @Nullable String url); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void setFaviconEnabled(boolean enabled); @CallSuper @Override @Nullable WebResourceResponse shouldInterceptRequest(@NonNull WebView webView, @NonNull String url); @CallSuper @Override @SuppressLint("NewApi") @Nullable WebResourceResponse shouldInterceptRequest(@NonNull WebView webView, @NonNull WebResourceRequest request); @CallSuper @Override void onLoadResource(@NonNull WebView webView, @Nullable String url); @Override @CallSuper void onPageFinished(@Nullable final WebView view, final @Nullable String url); @CallSuper @Override void onPageStarted(@NonNull WebView view, @Nullable String url, @Nullable Bitmap favicon); @CallSuper @Override void onReceivedHttpAuthRequest(@NonNull WebView view, @NonNull HttpAuthHandler handler, @Nullable String host,
                                          @Nullable String realm); void addAuthRequestCredentials(@NonNull String expectedAuthHost, @Nullable String username, @Nullable String password); void removeAuthRequestCredentials(@NonNull String expectedAuthHost);  }
@Test public void testOnClose() { String url = "uairship: AirshipWebViewClient spy = spy(client); ArgumentCaptor<NativeBridge.CommandDelegate> argument = ArgumentCaptor.forClass(NativeBridge.CommandDelegate.class); when(nativeBridge.onHandleCommand( eq(url), any(JavaScriptExecutor.class), any(ActionRunRequestExtender.class), argument.capture())) .thenReturn(true); spy.shouldOverrideUrlLoading(webView, url); argument.getValue().onClose(); verify(spy).onClose(webView); verify(rootView).dispatchKeyEvent(argThat(new ArgumentMatcher<KeyEvent>() { @Override public boolean matches(KeyEvent event) { return KeyEvent.ACTION_DOWN == event.getAction() && KeyEvent.KEYCODE_BACK == event.getKeyCode(); } })); verify(rootView).dispatchKeyEvent(argThat(new ArgumentMatcher<KeyEvent>() { @Override public boolean matches(KeyEvent event) { return KeyEvent.ACTION_UP == event.getAction() && KeyEvent.KEYCODE_BACK == event.getKeyCode(); } })); }