@Test public void findOrCreateSupportFragment_WhenFragmentFound_ReturnsIt() { given(mFragmentManager.findFragmentByTag(TEST_TAG)).willReturn(mFragment); final Fragment retrievedFragment = SupportActivityUtils.findOrCreateSupportFragment(mFragmentManager, TEST_TAG); assertThat(retrievedFragment, notNullValue()); assertThat(retrievedFragment, is(mFragment)); }
@NonNull public static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag) { checkNotNull(fragmentManager, "fragmentManager must not be null!"); checkNotNull(tag, "tag must not be null!"); checkArgument(!tag.isEmpty(), "tag string must not be empty!"); Fragment fragment = fragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = SupportDiffRequestManagerHolderFragment.newInstance(DiffRequestManagerHolder.create()); addSupportFragmentToActivity(fragmentManager, fragment, tag); } return fragment; }
SupportActivityUtils { @NonNull public static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag) { checkNotNull(fragmentManager, "fragmentManager must not be null!"); checkNotNull(tag, "tag must not be null!"); checkArgument(!tag.isEmpty(), "tag string must not be empty!"); Fragment fragment = fragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = SupportDiffRequestManagerHolderFragment.newInstance(DiffRequestManagerHolder.create()); addSupportFragmentToActivity(fragmentManager, fragment, tag); } return fragment; } }
SupportActivityUtils { @NonNull public static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag) { checkNotNull(fragmentManager, "fragmentManager must not be null!"); checkNotNull(tag, "tag must not be null!"); checkArgument(!tag.isEmpty(), "tag string must not be empty!"); Fragment fragment = fragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = SupportDiffRequestManagerHolderFragment.newInstance(DiffRequestManagerHolder.create()); addSupportFragmentToActivity(fragmentManager, fragment, tag); } return fragment; } private  SupportActivityUtils(); }
SupportActivityUtils { @NonNull public static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag) { checkNotNull(fragmentManager, "fragmentManager must not be null!"); checkNotNull(tag, "tag must not be null!"); checkArgument(!tag.isEmpty(), "tag string must not be empty!"); Fragment fragment = fragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = SupportDiffRequestManagerHolderFragment.newInstance(DiffRequestManagerHolder.create()); addSupportFragmentToActivity(fragmentManager, fragment, tag); } return fragment; } private  SupportActivityUtils(); @SuppressWarnings("WeakerAccess") static void addSupportFragmentToActivity(@NonNull final FragmentManager fragmentManager,
                                                    @NonNull final Fragment fragment,
                                                    @NonNull final String tag); @NonNull static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag); @SuppressWarnings("WeakerAccess") static void removeSupportFragment(@NonNull final FragmentManager fragmentManager,
                                             @NonNull final String tag); }
SupportActivityUtils { @NonNull public static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag) { checkNotNull(fragmentManager, "fragmentManager must not be null!"); checkNotNull(tag, "tag must not be null!"); checkArgument(!tag.isEmpty(), "tag string must not be empty!"); Fragment fragment = fragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = SupportDiffRequestManagerHolderFragment.newInstance(DiffRequestManagerHolder.create()); addSupportFragmentToActivity(fragmentManager, fragment, tag); } return fragment; } private  SupportActivityUtils(); @SuppressWarnings("WeakerAccess") static void addSupportFragmentToActivity(@NonNull final FragmentManager fragmentManager,
                                                    @NonNull final Fragment fragment,
                                                    @NonNull final String tag); @NonNull static Fragment findOrCreateSupportFragment(@NonNull final FragmentManager fragmentManager, @NonNull final String tag); @SuppressWarnings("WeakerAccess") static void removeSupportFragment(@NonNull final FragmentManager fragmentManager,
                                             @NonNull final String tag);  }