BaseFragmentFactory implements FragmentFactory { @Override public boolean isFragmentProvided(final int fragmentId) { if (fragmentId == lastCheckedFragmentId) { return fragmentProvided; } this.lastCheckedFragmentId = fragmentId; return fragmentProvided = providesFragment(fragmentId); } BaseFragmentFactory(); @Nullable static String createFragmentTag(@NonNull final Class<?> classOfFactory, @NonNull final String fragmentName); @Override boolean isFragmentProvided(final int fragmentId); @Override @Nullable Fragment createFragment(final int fragmentId); @Override @Nullable String createFragmentTag(final int fragmentId);  }
@Test public void testIsFragmentProvided() { final BaseFragmentFactory factory = new TestFactory(); assertThat(factory.isFragmentProvided(TestFactory.FRAGMENT_NOT_PROVIDED), is(false)); for (final int providedFragmentId : TestFactory.providedFragmentIds) { assertThat(factory.isFragmentProvided(providedFragmentId), is(true)); } }
@Test public void testIsFragmentProvidedLastChecked() { final BaseFragmentFactory factory = new TestFactory(); assertThat(factory.isFragmentProvided(TestFactory.FRAGMENT_NOT_PROVIDED), is(false)); assertThat(factory.isFragmentProvided(TestFactory.FRAGMENT_NOT_PROVIDED), is(false)); for (final int providedFragmentId : TestFactory.providedFragmentIds) { assertThat(factory.isFragmentProvided(providedFragmentId), is(true)); assertThat(factory.isFragmentProvided(providedFragmentId), is(true)); } }