ParserRegistry { public static EDIReader get(String firstChars) { EDIReader result = null; Class parserClass; String name = (String) getMatch(firstChars, registeredClassNames); if (name != null) { try { parserClass = Class.forName(name); result = (EDIReader) parserClass.newInstance(); } catch (Exception ignore) { } } if (result == null) { parserClass = (Class) getMatch(firstChars, builtinClass); if (parserClass != null) { try { result = (EDIReader) parserClass.newInstance(); } catch (Exception ignore) { } } } if (result == null) { name = registeredClassNames.get(""); if (name != null) { try { parserClass = Class.forName(name); result = (EDIReader) parserClass.newInstance(); } catch (Exception ignore) { } } } return result; } private  ParserRegistry(); static EDIReader get(String firstChars); static void register(String firstChars, String className);  }
@Test public void testInitialConditions() { assertNull(ParserRegistry.get("xyz")); assertTrue(ParserRegistry.get("ISA") instanceof AnsiReader); assertNull(ParserRegistry.get("IS")); assertNull(ParserRegistry.get("I")); assertTrue(ParserRegistry.get("UNA") instanceof EdifactReader); assertTrue(ParserRegistry.get("UNB") instanceof EdifactReader); assertNull(ParserRegistry.get("UN")); assertNull(ParserRegistry.get("U")); }
@Test public void testEdifactWithControl() { assertTrue(ParserRegistry.get("UNA") instanceof EdifactReaderWithCONTRL); }