WriterFactory { public IChemObjectWriter createWriter(IChemFormat format) { if (format != null) { String writerClassName = format.getWriterClassName(); if (writerClassName != null) { try { if (registeredReaders.containsKey(writerClassName)) { Class<IChemObjectWriter> writer = registeredReaders.get(writerClassName); if (writer != null) return writer.newInstance(); } return (IChemObjectWriter) this.getClass().getClassLoader().loadClass(writerClassName) .newInstance(); } catch (ClassNotFoundException exception) { logger.error("Could not find this ChemObjectWriter: ", writerClassName); logger.debug(exception); } catch (InstantiationException | IllegalAccessException exception) { logger.error("Could not create this ChemObjectWriter: ", writerClassName); logger.debug(exception); } } else { logger.warn("ChemFormat is recognized, but no writer is available."); } } else { logger.warn("ChemFormat is not recognized."); } return null; } WriterFactory(); void registerWriter(Class<?> writer); IChemFormat[] findChemFormats(int features); int formatCount(); IChemObjectWriter createWriter(IChemFormat format);  }
@Test public void testCreateWriter_IChemFormat() { IChemFormat format = (IChemFormat) XYZFormat.getInstance(); IChemObjectWriter writer = factory.createWriter(format); Assert.assertNotNull(writer); Assert.assertEquals(format.getFormatName(), writer.getFormat().getFormatName()); }