### Question:
ModuleFileParser { public Module parse(InputStream inputStream) { File moduleFile = createTempFile("moduleUpgrade", OPENMRS_MODULE_FILE_EXTENSION); copyInputStreamToFile(inputStream, moduleFile); return parse(moduleFile); } ModuleFileParser(MessageSourceService messageSourceService); @Deprecated  ModuleFileParser(File moduleFile); @Deprecated  ModuleFileParser(InputStream inputStream); @Deprecated  ModuleFileParser(); Module parse(InputStream inputStream); @Deprecated Module parse(); Module parse(File moduleFile);  }### Answer:
@Test public void parse_shouldParseValidXmlConfigCreatedFromInputStream() throws IOException { File moduleFile = new File(getClass().getClassLoader().getResource(LOGIC_MODULE_PATH).getPath()); ModuleFileParser parser = new ModuleFileParser(new FileInputStream(moduleFile)); Module module = parser.parse(); assertThat(module.getModuleId(), is("logic")); assertThat(module.getVersion(), is("0.2")); assertThat(module.getPackageName(), is("org.openmrs.logic")); assertThat(module.getActivatorName(), is("org.openmrs.logic.LogicModuleActivator")); assertThat(module.getMappingFiles().size(), is(1)); assertThat(module.getMappingFiles(), hasItems("LogicRuleToken.hbm.xml")); }
@Test public void parse_shouldFailIfModuleHasConfigInvalidConfigVersion() throws Exception { String invalidConfigVersion = "0.0.1"; String expectedMessage = messageSourceService .getMessage("Module.error.invalidConfigVersion", new Object[] { invalidConfigVersion, "1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6" }, Context.getLocale()); expectModuleExceptionWithMessage(expectedMessage); Document configXml = documentBuilder.newDocument(); Element root = configXml.createElement("module"); configXml.appendChild(root); configXml.getDocumentElement().setAttribute("configVersion", invalidConfigVersion); ModuleFileParser parser = new ModuleFileParser(writeConfigXmlToFile(configXml)); parser.parse(); }
@Test public void parse_shouldParseValidLogicModuleFromFile() { File moduleFile = new File(getClass().getClassLoader().getResource(LOGIC_MODULE_PATH).getPath()); ModuleFileParser parser = new ModuleFileParser(Context.getMessageSourceService()); Module module = parser.parse(moduleFile); assertThat(module.getModuleId(), is("logic")); assertThat(module.getVersion(), is("0.2")); assertThat(module.getPackageName(), is("org.openmrs.logic")); assertThat(module.getActivatorName(), is("org.openmrs.logic.LogicModuleActivator")); assertThat(module.getMappingFiles().size(), is(1)); assertThat(module.getMappingFiles(), hasItems("LogicRuleToken.hbm.xml")); }