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

org.pitest.aggregate.MutationResultDataLoader Maven / Gradle / Ivy

There is a newer version: 1.17.3
Show newest version
package org.pitest.aggregate;

import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.pitest.classinfo.ClassName;
import org.pitest.mutationtest.DetectionStatus;
import org.pitest.mutationtest.MutationResult;
import org.pitest.mutationtest.MutationStatusTestPair;
import org.pitest.mutationtest.engine.Location;
import org.pitest.mutationtest.engine.MutationDetails;
import org.pitest.mutationtest.engine.MutationIdentifier;
import org.pitest.util.Unchecked;

class MutationResultDataLoader extends DataLoader {

  MutationResultDataLoader(final Collection filesToLoad) {
    super(filesToLoad);
  }
  
  @Override
  protected Set mapToData(XMLStreamReader xr) throws XMLStreamException {
    XmlMapper xm = new XmlMapper();
    final Set data = new HashSet<>();
    while (xr.hasNext()) {
      xr.next();
      if (xr.getEventType() == START_ELEMENT) {
        if ("mutation".equals(xr.getLocalName())) {
          try {
            MutationXml mutation = xm.readValue(xr, MutationXml.class);
            data.add(xmlToResult(mutation));
          } catch (IOException e) {
            throw Unchecked.translateCheckedException(e);
          }
        }
      }
    }
    return data;
  }

  private MutationResult xmlToResult(MutationXml xml) {
    Location location = new Location(ClassName.fromString(xml.mutatedClass),
            xml.mutatedMethod, xml.methodDescription);
    MutationIdentifier id = new MutationIdentifier(location, xml.indexes, xml.mutator);
    return new MutationResult(new MutationDetails(id,
            xml.sourceFile, xml.description,
            xml.lineNumber, xml.blocks),
            new MutationStatusTestPair(xml.numberOfTestsRun, DetectionStatus.valueOf(xml.status), xml.killingTest));
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy