Beispiel #1
0
  /**
   * Generate xml for the changed test files
   *
   * @param changedTestsRoot
   */
  public void generateChangedTests(Element changedTestsRoot) {
    List<DiffFile> changedTests = report.getChangedTests();

    for (DiffFile changedTest : changedTests) {
      String fileName = changedTest.getFileName(report);

      Element testFile = doc.createElement("testFile");

      testFile.setAttribute("filename", fileName);
      testFile.setAttribute("sourceState", changedTest.getSourceState().toString());

      generateSourceDifferenceCount(changedTest, testFile);

      changedTestsRoot.appendChild(testFile);
    }
  }
Beispiel #2
0
  /**
   * Generate source different count elements
   *
   * @param sourceDiffFile The source differences
   * @param root Root element where the generated element will be placed
   */
  private void generateSourceDifferenceCount(DiffFile sourceDiffFile, Element root) {

    int removedLinesCount = 0, addedLinesCount = 0;

    for (Delta sourceDiff : sourceDiffFile.getChanges()) {
      if (sourceDiff.getType() == TYPE.CHANGE) {
        removedLinesCount += sourceDiff.getOriginal().size();
        addedLinesCount += sourceDiff.getRevised().size();
      } else if (sourceDiff.getType() == TYPE.DELETE) {
        removedLinesCount += sourceDiff.getOriginal().size();
      } else if (sourceDiff.getType() == TYPE.INSERT) {
        addedLinesCount += sourceDiff.getRevised().size();
      }
    }

    int totalLinesChangedCount =
        sourceDiffFile.getRevisedLineCount() - sourceDiffFile.getOriginalLineCount();
    double totalPercentage = 100.0;
    if (sourceDiffFile.getOriginalLineCount() > 0) {
      totalPercentage =
          Math.round(
                  (double) totalLinesChangedCount
                      / (double) sourceDiffFile.getOriginalLineCount()
                      * (double) 10000)
              / (double) 100;
    }

    root.setAttribute("sizeChange", totalLinesChangedCount + " (" + totalPercentage + "%)");

    if (removedLinesCount > 0) {
      Element removedLines = doc.createElement("removedLineCount");
      double percentage =
          Math.round(
                  (double) removedLinesCount
                      / (double) sourceDiffFile.getOriginalLineCount()
                      * (double) 10000)
              / (double) 100;
      removedLines.appendChild(doc.createTextNode(removedLinesCount + " (" + percentage + "%)"));
      root.appendChild(removedLines);
    }

    if (addedLinesCount > 0) {
      Element addedLines = doc.createElement("addedLineCount");
      double percentage = 100.0;
      if (sourceDiffFile.getOriginalLineCount() > 0) {
        percentage =
            Math.round(
                    (double) addedLinesCount
                        / (double) sourceDiffFile.getOriginalLineCount()
                        * (double) 10000)
                / (double) 100;
      }

      addedLines.appendChild(doc.createTextNode(addedLinesCount + " (" + percentage + "%)"));
      root.appendChild(addedLines);
    }
  }
Beispiel #3
0
  /**
   * Generate a summary of the coverage and source differences of the comparison
   *
   * @param summaryRoot
   */
  public void generateSummary(Element summaryRoot) {

    Element classChanges = doc.createElement("classChanges");
    Element testChanges = doc.createElement("testChanges");

    List<OperiasFile> changedClasses = report.getChangedClasses();
    int totalRelevantLineCountRemoved = 0, totalRelevantLineCountAdded = 0;
    int totalRelevantLineCountCoveredAndRemoved = 0, totalRelevantLineCountCoveredAndAdded = 0;

    for (OperiasFile changedClass : changedClasses) {

      List<OperiasChange> changes = changedClass.getChanges();

      // Collect all numbers
      for (OperiasChange change : changes) {
        // Either there is a change, else no source changes were found, which means that only the
        // coverage changed
        if (change.getSourceDiffDelta() != null) {
          if (change.getSourceDiffDelta().getType() == TYPE.DELETE
              || change.getSourceDiffDelta().getType() == TYPE.CHANGE) {
            totalRelevantLineCountRemoved += change.countOriginalRelevantLines();
            totalRelevantLineCountCoveredAndRemoved += change.countOriginalLinesCovered();
          }
          if (change.getSourceDiffDelta().getType() == TYPE.INSERT
              || change.getSourceDiffDelta().getType() == TYPE.CHANGE) {
            totalRelevantLineCountAdded += change.countRevisedRelevantLines();
            totalRelevantLineCountCoveredAndAdded += change.countRevisedLinesCovered();
          }
        }
      }
    }

    Element coverageChanges = doc.createElement("coverageChanges");

    coverageChanges.setAttribute(
        "originalLineRate", report.getOriginalCoverageReport().getLineRate() + "");
    coverageChanges.setAttribute(
        "originalConditionRate", report.getOriginalCoverageReport().getConditionRate() + "");
    coverageChanges.setAttribute(
        "revisedLineRate", report.getRevisedCoverageReport().getLineRate() + "");
    coverageChanges.setAttribute(
        "revisedConditionRate", report.getRevisedCoverageReport().getConditionRate() + "");

    // Element for removed lines
    if (totalRelevantLineCountRemoved > 0) {
      Element coverableLinesRemoved = doc.createElement("totalCoverableLinesRemoved");
      Element coverableLinesRemovedCount = doc.createElement("lineCount");
      Element coverableLinesRemovedPercentage = doc.createElement("lineRate");

      coverableLinesRemovedCount.appendChild(
          doc.createTextNode("" + totalRelevantLineCountRemoved));
      coverableLinesRemovedPercentage.appendChild(
          doc.createTextNode(
              ""
                  + Math.round(
                          (double) totalRelevantLineCountCoveredAndRemoved
                              / (double) totalRelevantLineCountRemoved
                              * 100.0f)
                      / (double) 100));
      coverableLinesRemoved.appendChild(coverableLinesRemovedCount);
      coverableLinesRemoved.appendChild(coverableLinesRemovedPercentage);

      coverageChanges.appendChild(coverableLinesRemoved);
    }

    // Elements for added lines

    if (totalRelevantLineCountAdded > 0) {
      Element coverableLinesAdded = doc.createElement("totalCoverableLinesAdded");
      Element coverableLinesAddedCount = doc.createElement("lineCount");
      Element coverableLinesAddedPercentage = doc.createElement("lineRate");

      coverableLinesAddedCount.appendChild(doc.createTextNode("" + totalRelevantLineCountAdded));
      coverableLinesAddedPercentage.appendChild(
          doc.createTextNode(
              ""
                  + Math.round(
                          (double) totalRelevantLineCountCoveredAndAdded
                              / (double) totalRelevantLineCountAdded
                              * 100.0f)
                      / (double) 100));
      coverableLinesAdded.appendChild(coverableLinesAddedCount);
      coverableLinesAdded.appendChild(coverableLinesAddedPercentage);

      coverageChanges.appendChild(coverableLinesAdded);
    }

    classChanges.appendChild(coverageChanges);

    // Collect a summary of source changes
    int totalClassSourceLinesAdded = 0, totalClassSourceLinesRemoved = 0;
    int totalClassSourceLinesOriginal = 0;

    for (OperiasFile classFile : report.getChangedClasses()) {
      totalClassSourceLinesOriginal += classFile.getSourceDiff().getOriginalLineCount();
      for (Delta sourceDiff : classFile.getSourceDiff().getChanges()) {
        if (sourceDiff.getType() == TYPE.CHANGE) {
          totalClassSourceLinesRemoved += sourceDiff.getOriginal().size();
          totalClassSourceLinesAdded += sourceDiff.getRevised().size();
        } else if (sourceDiff.getType() == TYPE.DELETE) {
          totalClassSourceLinesRemoved += sourceDiff.getOriginal().size();
        } else if (sourceDiff.getType() == TYPE.INSERT) {
          totalClassSourceLinesAdded += sourceDiff.getRevised().size();
        }
      }
    }

    // All counts collected
    Element classSourceChanges = doc.createElement("sourceChanges");
    Element classSourceLinesAdded = doc.createElement("addedLineCount");
    Element classSourceLinesRemoved = doc.createElement("removedLineCount");

    classSourceLinesAdded.appendChild(
        doc.createTextNode(
            totalClassSourceLinesAdded
                + " ("
                + Math.round(
                        (double) totalClassSourceLinesAdded
                            / (double) totalClassSourceLinesOriginal
                            * (double) 10000)
                    / (double) 100
                + "%)"));
    classSourceLinesRemoved.appendChild(
        doc.createTextNode(
            totalClassSourceLinesRemoved
                + " ("
                + Math.round(
                        (double) totalClassSourceLinesRemoved
                            / (double) totalClassSourceLinesOriginal
                            * (double) 10000)
                    / (double) 100
                + "%)"));

    classSourceChanges.appendChild(classSourceLinesAdded);
    classSourceChanges.appendChild(classSourceLinesRemoved);

    classChanges.appendChild(classSourceChanges);

    summaryRoot.appendChild(classChanges);

    // Collect a summary of source changes
    totalClassSourceLinesAdded = 0;
    totalClassSourceLinesRemoved = 0;
    totalClassSourceLinesOriginal = 0;

    for (DiffFile testFile : report.getChangedTests()) {
      totalClassSourceLinesOriginal += testFile.getOriginalLineCount();
      for (Delta sourceDiff : testFile.getChanges()) {
        if (sourceDiff.getType() == TYPE.CHANGE) {
          totalClassSourceLinesRemoved += sourceDiff.getOriginal().size();
          totalClassSourceLinesAdded += sourceDiff.getRevised().size();
        } else if (sourceDiff.getType() == TYPE.DELETE) {
          totalClassSourceLinesRemoved += sourceDiff.getOriginal().size();
        } else if (sourceDiff.getType() == TYPE.INSERT) {
          totalClassSourceLinesAdded += sourceDiff.getRevised().size();
        }
      }
    }

    // All counts collected
    Element testSourceChanges = doc.createElement("sourceChanges");
    Element testSourceLinesAdded = doc.createElement("addedLineCount");
    Element testSourceLinesRemoved = doc.createElement("removedLineCount");

    testSourceLinesAdded.appendChild(
        doc.createTextNode(
            totalClassSourceLinesAdded
                + " ("
                + Math.round(
                        (double) totalClassSourceLinesAdded
                            / (double) totalClassSourceLinesOriginal
                            * (double) 10000)
                    / (double) 100
                + "%)"));
    testSourceLinesRemoved.appendChild(
        doc.createTextNode(
            totalClassSourceLinesRemoved
                + " ("
                + Math.round(
                        (double) totalClassSourceLinesRemoved
                            / (double) totalClassSourceLinesOriginal
                            * (double) 10000)
                    / (double) 100
                + "%)"));

    testSourceChanges.appendChild(testSourceLinesAdded);
    testSourceChanges.appendChild(testSourceLinesRemoved);

    testChanges.appendChild(testSourceChanges);
    summaryRoot.appendChild(testChanges);
  }