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