public void putJumpTouchPoint(int classLine, int trueCounterId, int falseCounterId) { updateLine(classLine); LineData ld = getOrCreateLine(classLine); int branchId = jumpsInLine++; classData.addLineJump(classLine, branchId); ld.touchJump(branchId, true, res[trueCounterId]); ld.touchJump(branchId, false, res[falseCounterId]); }
public void putSwitchTouchPoint(int classLine, int maxBranches, int... counterIds) { updateLine(classLine); LineData ld = getOrCreateLine(classLine); int switchId = switchesInLine++; classData.addLineSwitch(classLine, switchId, 0, counterIds.length - 2, maxBranches); for (int i = 0; i < counterIds.length; i++) { ld.touchSwitch(switchId, i - 1, res[counterIds[i]]); } }
private void dumpConditions(LineData lineData) { increaseIndentation(); println("<conditions>"); for (int i = 0; i < lineData.getConditionSize(); i++) { Object conditionData = lineData.getConditionData(i); String coverage = lineData.getConditionCoverage(i); dumpCondition(conditionData, coverage); } println("</conditions>"); decreaseIndentation(); }
@Test public void testMergeDifferentLineNumbers() { firstClass.addLine(2, "helloWorld", "()V"); firstClass.addLine(3, "helloWorld", "()V"); greenProject.addClassData(firstClass); firstClassB.addLine(1, "helloWorld", "()V"); firstClassB.addLine(5, "helloWorld", "()V"); redProject.addClassData(firstClassB); greenProject.merge(redProject); ClassData cd = greenProject.getClassData("test.First"); assertNotNull(cd); assertEquals(4, cd.getNumberOfValidLines()); assertEquals(2, redProject.getClassData("test.First").getNumberOfValidLines()); Iterator lines = cd.getLines().iterator(); LineData line1 = (LineData) lines.next(); assertEquals(1, line1.getLineNumber()); LineData line2 = (LineData) lines.next(); assertEquals(2, line2.getLineNumber()); LineData line3 = (LineData) lines.next(); assertEquals(3, line3.getLineNumber()); LineData line5 = (LineData) lines.next(); assertEquals(5, line5.getLineNumber()); assertFalse(lines.hasNext()); }
private static void _assertClassDataCoverage( List<AssertionError> assertionErrors, Class<?> clazz, ClassData classData) { if (clazz.isInterface() || clazz.isSynthetic()) { return; } if (classData == null) { assertionErrors.add(new AssertionError("Class " + clazz.getName() + " has no coverage data")); return; } if ((classData.getBranchCoverageRate() != 1.0) || (classData.getLineCoverageRate() != 1.0)) { System.out.printf( "%n[Cobertura] %s is not fully covered.%n[Cobertura]Branch " + "coverage rate : %.2f, line coverage rate : %.2f.%n" + "[Cobertura]Please rerun test with -Djunit.code." + "coverage=true to see coverage report.%n", classData.getName(), classData.getBranchCoverageRate(), classData.getLineCoverageRate()); Set<CoverageData> coverageDatas = classData.getLines(); for (CoverageData coverageData : coverageDatas) { if (!(coverageData instanceof LineData)) { continue; } LineData lineData = (LineData) coverageData; if (lineData.isCovered()) { continue; } System.out.printf( "[Cobertura] %s line %d is not covered %n", classData.getName(), lineData.getLineNumber()); } assertionErrors.add(new AssertionError(classData.getName() + " is not fully covered")); return; } System.out.printf("[Cobertura] %s is fully covered.%n", classData.getName()); }
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 + "/>"); } }
@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()); }
public void putLineTouchPoint( int classLine, int counterId, String methodName, String methodDescription) { updateLine(classLine); LineData ld = classData.addLine(classLine, methodName, methodDescription); ld.touch(res[counterId]); }
@Test public void testMergeBranches() { firstClass.addLine(1, "helloWorld", "()V"); firstClass.addLineJump(1, 0); firstClass.addLine(2, "helloWorld", "()V"); firstClass.addLineJump(2, 0); firstClass.addLineJump(2, 1); firstClass.addLine(3, "helloWorld", "()V"); firstClass.addLine(4, "helloWorld", "()V"); firstClass.addLineSwitch(4, 0, 0, 2); firstClass.addLine(5, "helloWorld", "()V"); firstClass.addLine(8, "helloWorld", "()V"); greenProject.addClassData(firstClass); firstClassB.addLine(1, "helloWorld", "()V"); firstClassB.addLineJump(1, 0); firstClassB.addLine(2, "helloWorld", "()V"); firstClassB.addLine(3, "helloWorld", "()V"); firstClassB.addLineSwitch(3, 0, 2, 4); firstClassB.addLine(6, "helloWorld", "()V"); firstClassB.addLineJump(6, 0); firstClassB.addLine(7, "helloWorld", "()V"); firstClassB.addLine(8, "helloWorld", "()V"); redProject.addClassData(firstClassB); greenProject.merge(redProject); ClassData cd = greenProject.getClassData("test.First"); Iterator lines = cd.getLines().iterator(); LineData line1 = (LineData) lines.next(); assertTrue(line1.hasBranch()); LineData line2 = (LineData) lines.next(); assertTrue(line2.hasBranch()); LineData line3 = (LineData) lines.next(); assertTrue(line3.hasBranch()); LineData line4 = (LineData) lines.next(); assertTrue(line4.hasBranch()); LineData line5 = (LineData) lines.next(); assertFalse(line5.hasBranch()); LineData line6 = (LineData) lines.next(); assertTrue(line6.hasBranch()); LineData line7 = (LineData) lines.next(); assertFalse(line7.hasBranch()); LineData line8 = (LineData) lines.next(); assertFalse(line8.hasBranch()); assertFalse(lines.hasNext()); }