JaxbLoader { public static MMOs loadXml(final File xmlFile) throws JAXBException, SAXException, ParserConfigurationException, FileNotFoundException { final JAXBContext jaxbContext = JAXBContext.newInstance(MMOs.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setFeature("http: spf.setFeature("http: final XMLReader xmlReader = spf.newSAXParser().getXMLReader(); final InputSource inputSource = new InputSource(new FileReader(xmlFile)); final SAXSource source = new SAXSource(xmlReader, inputSource); return (MMOs) jaxbUnmarshaller.unmarshal(source); }  static MMOs loadXml(final File xmlFile);  }
@SuppressWarnings("OverlyBroadThrowsClause") @Test public void testLoadXml() throws Exception { final MMOs root = JaxbLoader.loadXml(TEST_XML); assertNotNull(root); final MMO mmo = root.getMMO().get(0); assertNotNull(mmo); final Utterance utterance = mmo.getUtterances().getUtterance().get(0); assertNotNull(utterance); final Phrase phrase = utterance.getPhrases().getPhrase().get(0); assertNotNull(phrase); final Mapping mapping = phrase.getMappings().getMapping().get(0); assertNotNull(mapping); final Candidate candidate = mapping.getMappingCandidates().getCandidate().get(0); assertNotNull(candidate); assertEquals(candidate.getCandidateCUI(), "C0004096"); assertEquals(candidate.getCandidatePreferred(), "Asthma"); final SemType semType = candidate.getSemTypes().getSemType().get(0); assertEquals(semType.getvalue(), "dsyn"); }
@Test public void failToLoad() { try { JaxbLoader.loadXml(new File("noSuchFile")); fail("We should have had an exception before now."); } catch (final FileNotFoundException ignored) { } catch (final Throwable t) { t.printStackTrace(); fail("There should be no other throwables."); } }