FeatureFinderMetaboDetector { public List<Double> execute() throws XMLStreamException, IOException, MSDKException { List<Double> mzValuesResult = new ArrayList<Double>(); createTempFeatureXMLFile(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(new FileReader(FEATURE_XML_FILE)); while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = xmlEventReader.nextEvent(); if (xmlEvent.isStartElement()) { StartElement startElement = xmlEvent.asStartElement(); if (startElement.getName().getLocalPart().equals("position") && xmlEventReader.hasNext()) { xmlEvent = xmlEventReader.nextEvent(); Attribute idAttr = startElement.getAttributeByName(new QName("dim")); if (idAttr.getValue().equals("1")) { Characters characters = xmlEvent.asCharacters(); try { mzValuesResult.add(Double.valueOf(characters.getData())); } catch (NumberFormatException e) { throw new MSDKException("The featureXML contains an invalid m/z value.\n" + e.getMessage()); } } } } } return mzValuesResult; } FeatureFinderMetaboDetector(String mzMLFilePath);  FeatureFinderMetaboDetector(File mzMLFile); List<Double> execute();  }
@Test public void testValidmzMLfile() throws Exception { File inputFile = new File(this.getClass().getClassLoader().getResource("msms.mzML").toURI()); Assert.assertNotNull(inputFile); FeatureFinderMetaboDetector mzDetector = new FeatureFinderMetaboDetector(inputFile); Assert.assertEquals(233, mzDetector.execute().size()); FeatureFinderMetaboDetector mzDetector2 = new FeatureFinderMetaboDetector(inputFile); Assert.assertEquals(233, mzDetector2.execute().size()); }
@Test(expected = MSDKException.class) public void testInvalidmzMLFile() throws Exception { File inputFile = new File(this.getClass().getClassLoader().getResource("truncated.mzML").toURI()); Assert.assertNotNull(inputFile); FeatureFinderMetaboDetector mzDetector3 = new FeatureFinderMetaboDetector(inputFile); Assert.assertEquals(0, mzDetector3.execute().size()); FeatureFinderMetaboDetector mzDetector4 = new FeatureFinderMetaboDetector(inputFile); Assert.assertEquals(0, mzDetector4.execute().size()); }