All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.ericdriggs.reportcard.xml.surefire.SurefireParserUtil Maven / Gradle / Ivy

There is a newer version: 0.1.19
Show newest version
package io.github.ericdriggs.reportcard.xml.surefire;


import io.github.ericdriggs.file.FileUtils;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class SurefireParserUtil {
    private SurefireParserUtil() {
        //call statically
    }

    public static List parseTestSuitesFromPathAndRegex(String absolutePath, String fileNameRegex) {
        List xmlStringList = FileUtils.fileContentsFromPathAndRegex(absolutePath, fileNameRegex);
        return parseTestSuites(xmlStringList);
    }

    public static List parseTestSuites(List xmlStringList) {
        List testsuites = new ArrayList<>();
        for ( String xmlString : xmlStringList) {
            testsuites.add(parseTestSuite(xmlString));
        }
        return testsuites;
    }

    public static Testsuite parseTestSuite(String xmlString) {

        JAXBContext jaxbContext;
        try {
            jaxbContext = JAXBContext.newInstance(Testsuite.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            Testsuite testsuite = (Testsuite) jaxbUnmarshaller.unmarshal(new StringReader(xmlString));
            return testsuite;
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy