BaseFragment extends Fragment implements BackPressWatcher, ViewClickWatcher { @SuppressWarnings("TryWithIdenticalCatches") @Nullable public static <F extends Fragment> F newInstanceWithArguments(@NonNull final Class<F> classOfFragment, @Nullable final Bundle args) { try { final F fragment = classOfFragment.newInstance(); fragment.setArguments(args); return fragment; } catch (java.lang.InstantiationException e) { Log.e(TAG, "Failed to instantiate instance of " + classOfFragment + " with arguments!", e); } catch (IllegalAccessException e) { Log.e(TAG, "Failed to instantiate instance of " + classOfFragment + " with arguments!", e); } return null; } BaseFragment(); @SuppressWarnings("TryWithIdenticalCatches") @Nullable static F newInstanceWithArguments(@NonNull final Class<F> classOfFragment, @Nullable final Bundle args); @SuppressWarnings("deprecation") @Override void onAttach(@NonNull final Activity activity); final boolean isAttached(); final boolean runOnUiThread(@NonNull final Runnable action); @Override void onCreate(@Nullable final Bundle savedInstanceState); final boolean isCreated(); @Override void onStart(); final boolean isStarted(); @Override View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState); @Override void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState); final boolean isViewCreated(); @Override void onResume(); boolean invalidateOptionsMenu(); @Override boolean dispatchViewClick(@NonNull final View view); @Override void onPause(); final boolean isPaused(); @Override void onStop(); final boolean isStopped(); @Override @CheckResult boolean dispatchBackPress(); @Override void onDestroy(); final boolean isDestroyed(); @Override void onDetach();  }
@SuppressWarnings("ConstantConditions") @Test public void testNewInstanceWithArguments() { final Bundle args = new Bundle(); final TestFragment fragment = BaseFragment.newInstanceWithArguments(TestFragment.class, args); assertThat(fragment, is(notNullValue())); assertThat(fragment.getArguments(), is(args)); }
@SuppressWarnings("ConstantConditions") @Test public void testNewInstanceWithNullArguments() { final BaseFragment fragment = BaseFragment.newInstanceWithArguments(TestFragment.class, null); assertThat(fragment, is(notNullValue())); assertThat(fragment.getArguments(), is(nullValue())); }
@Test public void testNewInstanceWithArgumentsForAbstractFragment() { assertThat(BaseFragment.newInstanceWithArguments(AbstractTestFragment.class, new Bundle()), is(nullValue())); }
@Test public void testNewInstanceWithArgumentsForFragmentWithPrivateConstructor() { assertThat(BaseFragment.newInstanceWithArguments(TestFragmentWithPrivateConstructor.class, new Bundle()), is(nullValue())); }