WebFragment extends ActionBarFragment { protected void onLoadContent(@Nullable final String content, @ContentType final int type) { if (webView != null) { if (!TextUtils.isEmpty(content)) { if (content.length() > LOG_CONTENT_MAX_LENGTH) { FragmentsLogging.d(TAG, "Loading content('" + content.substring(0, LOG_CONTENT_MAX_LENGTH) + "') into web view."); } else { FragmentsLogging.d(TAG, "Loading content('" + content + "') into web view."); } } switch (type) { case CONTENT_EMPTY: this.webView.loadDataWithBaseURL("", "", DATA_MIME_TYPE, DATA_ENCODING, ""); break; case CONTENT_URL: case CONTENT_FILE: this.webView.loadUrl(content); break; case CONTENT_HTML: default: this.webView.loadDataWithBaseURL("", content, DATA_MIME_TYPE, DATA_ENCODING, ""); break; } } }  static boolean isValidWebUrl(@Nullable final String url); @NonNull static WebFragment newInstance(); @NonNull static WebFragment newInstance(@NonNull final WebOptions options); @Override void onCreate(@Nullable final Bundle savedInstanceState); @NonNull final WebOptions getOptions(); void setOnWebContentLoadingListener(@Nullable final OnWebContentLoadingListener listener); @Override View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState); @Nullable WebView getWebView(); @Override void onActivityCreated(@Nullable final Bundle savedInstanceState); boolean loadContent(@Nullable final String content); @Nullable String getContent(); @ContentType int getContentType(); @Override void onSaveInstanceState(@NonNull final Bundle state); @Override void onDestroyView();  }
@SuppressWarnings("ConstantConditions") @Test public void testOnLoadContent() { final FragmentActivity activity = Robolectric.buildActivity(TestCompatActivity.class).create().start().resume().get(); final FragmentManager fragmentManager = activity.getSupportFragmentManager(); final WebFragment fragment = new WebFragment(); fragmentManager.beginTransaction().add(fragment, null).commit(); fragmentManager.executePendingTransactions(); fragment.onLoadContent("http: assertThat(fragment.getWebView().getUrl(), is("http: }
@Test public void testOnLoadContentWithoutWebView() { final WebFragment fragment = new WebFragment(); fragment.onLoadContent("http: }