### Question:
Factory implements HandlerListener { @SuppressWarnings("unchecked") public <O extends Featurable> O create(Media media) { if (cache.containsKey(media) && !cache.get(media).isEmpty()) { final Featurable featurable = cache.get(media).poll(); featurable.getFeature(Recycler.class).recycle(); return (O) featurable; } final Setup setup = getSetup(media); final Class<O> type = setup.getConfigClass(classLoader); try { return createFeaturable(type, setup); } catch (final NoSuchMethodException exception) { throw new LionEngineException(exception, ERROR_CONSTRUCTOR_MISSING + media); } } Factory(Services services); @SuppressWarnings("unchecked") O create(Media media); @SuppressWarnings("unchecked") O create(Media media, Class<O> type); void createCache(Media folder, int count); void setClassLoader(ClassLoader classLoader); Setup getSetup(Media media); @Override void notifyHandlableAdded(Featurable featurable); @Override void notifyHandlableRemoved(Featurable featurable); static final String FILE_DATA_EXTENSION; static final String FILE_DATA_DOT_EXTENSION; }### Answer:
@Test void testCreate() { factory.setClassLoader(ClassLoader.getSystemClassLoader()); final Featurable featurable1 = factory.create(Medias.create("Object.xml")); final Featurable featurable2 = factory.create(Medias.create("Object.xml"), FeaturableModel.class); assertNotNull(featurable1); assertNotNull(featurable2); }
@Test void testPrepareWithIdentifiable() { final Featurable featurable1 = factory.create(Medias.create("ObjectIdentifiable.xml")); final Featurable featurable2 = factory.create(Medias.create("ObjectIdentifiable.xml"), ObjectWithIdentifiable.class); assertNotNull(featurable1); assertNotNull(featurable2); }
@Test void testCreateFeatures() { final Featurable featurable = factory.create(Medias.create("ObjectFeatures.xml")); assertTrue(featurable.hasFeature(Mirrorable.class)); }
@Test void testCreateUnknownFeature() { final Media media = Medias.create("ObjectUnknownFeature.xml"); assertThrows(() -> factory.create(media), FeaturableConfig.ERROR_CLASS_PRESENCE + "Unknown"); }
@Test void testCreateNoConstructorClass() { final Media media = Medias.create("ObjectNoConstructor.xml"); assertThrows(() -> factory.create(media, Featurable.class), Factory.ERROR_CONSTRUCTOR_MISSING + media); }
@Test void testCreateNoClass() { assertCause(() -> factory.create(Medias.create("ObjectNoClass.xml")), ClassNotFoundException.class); }
@Test void testCreateNoSetupClass() { assertCause(() -> factory.create(Medias.create("ObjectNoSetup.xml")), ClassNotFoundException.class); }
@Test void testCreateNoSetupConstructor() { assertCause(() -> factory.create(Medias.create("ObjectNoSetupConstructor.xml")), NoSuchMethodException.class); }