BaseFragmentFactory implements FragmentFactory { @NonNull protected Fragment onCreateFragment(final int fragmentId) { if (items.indexOfKey(fragmentId) < 0) { throw new IllegalArgumentException("Factory does not provide fragment instance for id(" + fragmentId + ")!"); } final Fragment fragment = items.get(fragmentId).newFragmentInstance(null); if (fragment == null) { throw new IllegalArgumentException("Failed to instantiate fragment for the requested id(" + fragmentId + ")!"); } return fragment; } 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(expected = IllegalArgumentException.class) public void testOnCreateFragmentThatIsNotProvided() { final TestFactory factory = new TestFactory(); factory.onCreateFragment(TestFactory.FRAGMENT_NOT_PROVIDED); }