ModuleParser extends NonParameterizedTypeParser<Module> { @Override public Module doParse(String raw) throws IllegalArgumentException { String fullyQualifiedName = NAME_ALIASES.containsKey(raw) ? NAME_ALIASES.get(raw) : raw; Class<?> rawClass; try { rawClass = Class.forName(fullyQualifiedName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } if (!Module.class.isAssignableFrom(rawClass)) { throw new IllegalArgumentException( "Class " + fullyQualifiedName + " must implement " + Module.class.getName()); } @SuppressWarnings("unchecked") Class<? extends Module> moduleClass = (Class<? extends Module>) rawClass; return MoreModules.lazilyInstantiated(moduleClass); }  @Override Module doParse(String raw);  }
@Test public void testDoParseSuccess() { new ModuleParser().doParse(NoOpModule.class.getName()); }
@Test(expected = IllegalArgumentException.class) public void testDoParseClassNotFound() { new ModuleParser().doParse("invalid.class.name"); }
@Test(expected = IllegalArgumentException.class) public void testDoParseNotModule() { new ModuleParser().doParse(String.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testDoParseNoNullaryConstructor() { new ModuleParser().doParse(NoNullaryConstructorModule.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testDoParseThrowingConstructorModule() { new ModuleParser().doParse(ThrowingConstructorModule.class.getCanonicalName()); }