DataWriterFactory extends AbstractIOFactory<DataWriter> { @Override public DataWriter get(String mimeType) { DataWriter writer = null; Class<? extends DataWriter> clazz = getTypeClass(mimeType); try { if (clazz != null) { Constructor<? extends DataWriter> constructor = clazz.getDeclaredConstructor(String.class); writer = constructor.newInstance(mimeType); } } catch (SecurityException | InvocationTargetException | IllegalAccessException | InstantiationException | IllegalArgumentException | NoSuchMethodException e) { e.printStackTrace(); } if (writer == null) { throw new IllegalArgumentException(MessageFormat.format( "Unsupported MIME type: {0}", mimeType)); } return writer; } private  DataWriterFactory(); static DataWriterFactory getInstance(); @Override DataWriter get(String mimeType);  }
@Test public void testGet() { DataWriter r = DataWriterFactory.getInstance().get("text/csv"); assertNotNull(r); try { DataWriterFactory.getInstance().get("fail"); fail("Expected IllegalArgumentException exception."); } catch (IllegalArgumentException e) { } }