WebFragment extends ActionBarFragment { @Override public void onSaveInstanceState(@NonNull final Bundle state) { super.onSaveInstanceState(state); if (webView != null) { this.webView.saveState(state); } state.putParcelable(BUNDLE_OPTIONS, options); state.putString(BUNDLE_CONTENT, content); state.putInt(BUNDLE_PRIVATE_FLAGS, privateFlags); }  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();  }
@Test public void testOnSaveInstanceState() { 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(); final Bundle state = new Bundle(); fragment.onSaveInstanceState(state); assertThat(state.containsKey(WebFragment.BUNDLE_OPTIONS), is(true)); assertThat(state.containsKey(WebFragment.BUNDLE_CONTENT), is(true)); assertThat(state.containsKey(WebFragment.BUNDLE_PRIVATE_FLAGS), is(true)); }
@Test public void testOnSaveInstanceStateWithoutWebView() { final WebFragment fragment = new WebFragment(); final Bundle state = new Bundle(); fragment.onSaveInstanceState(state); assertThat(state.containsKey(WebFragment.BUNDLE_OPTIONS), is(true)); assertThat(state.containsKey(WebFragment.BUNDLE_CONTENT), is(true)); assertThat(state.containsKey(WebFragment.BUNDLE_PRIVATE_FLAGS), is(true)); }