return data;
}
@Test
public void testDiff() {
ProjectData one = buildBaseProjectData();
ProjectData two = buildBaseProjectData();
addSomeStuff(two, "foo", 2);
touchAJump(two, "foo", 1, true);
touchAJump(two, "foo", 1, false);
touchASwitch(two, "bar", 2, 2);
touchASwitch(two, "bar", 2, -1);
addSomeStuff(two, "baz", 8);
// sanity check on the raw data.
assertEquals(1, ((JumpData) one.getClassData("foo").getLineCoverage(1)
.getConditionData(0)).getTrueHits());
assertEquals(0, ((JumpData) one.getClassData("foo").getLineCoverage(1)
.getConditionData(0)).getFalseHits());
assertEquals(2, ((JumpData) two.getClassData("foo").getLineCoverage(1)
.getConditionData(0)).getTrueHits());
assertEquals(1, ((JumpData) two.getClassData("foo").getLineCoverage(1)
.getConditionData(0)).getFalseHits());
assertEquals(1, ((SwitchData) one.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getDefaultHits());
assertEquals(0, ((SwitchData) one.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getHits(0));
assertEquals(1, ((SwitchData) one.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getHits(1));
// assertEquals( 0, ((SwitchData)
// one.getClassData("bar").getLineCoverage( 2 ).getConditionData( 0 )
// ).getHits( 2 ));
assertEquals(2, ((SwitchData) two.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getDefaultHits());
assertEquals(0, ((SwitchData) two.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getHits(0));
assertEquals(1, ((SwitchData) two.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getHits(1));
assertEquals(1, ((SwitchData) two.getClassData("bar")
.getLineCoverage(2).getConditionData(0)).getHits(2));
ProjectDataDifferenceCalculator calc = new ProjectDataDifferenceCalculator(
two, one);
ProjectData diff = calc.getDifference();
assertSame(calc.getLarger(), two);
assertSame(calc.getSmaller(), one);
ClassData foo = diff.getClassData("foo");
assertEquals(3, foo.getLines().size());
for (int i = 0; i < 2; i++) {
LineData x = foo.getLineCoverage(i);
assertEquals(x.getHits(), 1);
assertEquals(x.hasBranch(), i == 1);
if (x.hasBranch()) {
JumpData jd = (JumpData) x.getConditionData(0);
assertEquals(jd.getTrueHits(), 1);
assertEquals(jd.getFalseHits(), 1);
}
}
assertEquals(foo.getLineCoverage(2).getHits(), 0);
ClassData bar = diff.getClassData("bar");
assertEquals(3, bar.getLines().size());
for (int i = 0; i < 3; i++) {
LineData x = bar.getLineCoverage(i);
assertEquals(x.getHits(), 0);
assertEquals(x.hasBranch(), i == 2, "Switches for " + i);
if (x.hasBranch()) {
SwitchData sd = (SwitchData) x.getConditionData(0);
assertEquals(1, sd.getDefaultHits());
assertEquals(0, sd.getHits(0));
assertEquals(0, sd.getHits(1));
assertEquals(1, sd.getHits(2));
}
}
ClassData baz = diff.getClassData("baz");
assertEquals(8, baz.getLines().size());
for (int i = 0; i < 8; i++) {
LineData x = baz.getLineCoverage(i);
assertEquals(x.getHits(), 1);
assertFalse(x.hasBranch());