@Test
public void onPageStarted_whenLoadedUrlStartsWithRedirectAndHasClickthrough_withUserClick_whenMoPubBrowserCannotHandleIntent_shouldOpenInNativeBrowser() throws Exception {

    Context mockContext = mock(Context.class);
    stub(htmlWebView.wasClicked()).toReturn(true);
    stub(htmlWebView.getContext()).toReturn(mockContext);
    String url = "redirectUrlToLoad";
    // We only want startActivity() to throw an exception the first time we call it.
    doThrow(new ActivityNotFoundException())
            .doNothing()
            .when(mockContext).startActivity(any(Intent.class));
    subject = new HtmlWebViewClient(htmlWebViewListener, htmlWebView, "clickthrough", "redirect");
    subject.onPageStarted(htmlWebView, url, null);
    ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(mockContext, times(2)).startActivity(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getAllValues().get(1);
    assertThat(intent.getAction()).isEqualTo("android.intent.action.VIEW");
    assertThat(intent.getData().toString()).isEqualTo("about:blank");
    assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0);
    verify(htmlWebViewListener, times(1)).onClicked();
}