Exemplo n.º 1
0
  @Test
  public void testMergeSimillarLineNumbers() {
    firstClass.addLine(2, "helloWorld", "()V");
    firstClass.touch(2, 1);
    firstClass.touch(2, 1);
    firstClass.addLine(3, "helloWorld", "()V");
    greenProject.addClassData(firstClass);

    firstClassB.addLine(2, "helloWorld", "()V");
    firstClassB.touch(2, 1);
    firstClassB.touch(2, 1);
    firstClassB.touch(2, 1);
    firstClassB.addLine(3, "helloWorld", "()V");
    firstClassB.touch(3, 1);
    firstClassB.addLine(7, "helloWorld", "()V");
    redProject.addClassData(firstClassB);

    greenProject.merge(redProject);

    ClassData cd = greenProject.getClassData("test.First");
    assertNotNull(cd);
    assertEquals(3, cd.getNumberOfValidLines());
    assertEquals(3, redProject.getClassData("test.First").getNumberOfValidLines());

    Iterator lines = cd.getLines().iterator();
    LineData line2 = (LineData) lines.next();
    assertEquals(2, line2.getLineNumber());
    assertEquals(5, line2.getHits());
    LineData line3 = (LineData) lines.next();
    assertEquals(3, line3.getLineNumber());
    assertEquals(1, line3.getHits());
    LineData line7 = (LineData) lines.next();
    assertEquals(7, line7.getLineNumber());
    assertEquals(0, line7.getHits());
    assertFalse(lines.hasNext());
  }
  private void dumpLine(LineData lineData) {
    int lineNumber = lineData.getLineNumber();
    long hitCount = lineData.getHits();
    boolean hasBranch = lineData.hasBranch();
    String conditionCoverage = lineData.getConditionCoverage();

    String lineInfo =
        "<line number=\""
            + lineNumber
            + "\" hits=\""
            + hitCount
            + "\" branch=\""
            + hasBranch
            + "\"";
    if (hasBranch) {
      println(lineInfo + " condition-coverage=\"" + conditionCoverage + "\">");
      dumpConditions(lineData);
      println("</line>");
    } else {
      println(lineInfo + "/>");
    }
  }