}
@Test
- public void no_new_debt_ratio_when_file_is_unit_test() {
+ public void new_debt_ratio_when_file_is_unit_test() {
setTwoPeriods();
when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
- setupOneFileAloneInAProject(50, 12, Flag.UT_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET);
- measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12));
-
- underTest.visit(treeRootHolder.getRoot());
-
- assertNoNewDebtRatioMeasure(LANGUAGE_1_FILE_REF);
- assertNewDebtRatioValues(ROOT_REF, 0, 0);
- }
-
- @Test
- public void new_debt_ratio_is_0_on_non_file_level_when_all_files_are_unit_test() {
- setTwoPeriods();
- when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
- setupOneFileAloneInAProject(50, 12, Flag.UT_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET);
- measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200, 162));
+ setupOneFileAloneInAProject(500, 120, Flag.UT_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET);
+ measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(1200, 820));
underTest.visit(treeRootHolder.getRoot());
- assertNoNewDebtRatioMeasure(LANGUAGE_1_FILE_REF);
- assertNewDebtRatioValues(ROOT_REF, 0, 0);
+ assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33, 0);
+ assertNewDebtRatioValues(ROOT_REF, 833.33, 0);
}
@Test
.addChildren(
createFileComponent(LANGUAGE_KEY_1, 1111),
createFileComponent(LANGUAGE_KEY_2, 1112),
+ // Unit test should not be ignored
builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1)).build())
.build(),
builder(DIRECTORY, 112)
int ncloc1111 = 10;
addRawMeasure(NCLOC_KEY, 1111, ncloc1111);
- int ncloc1112 = 10;
+ int ncloc1112 = 12;
addRawMeasure(NCLOC_KEY, 1112, ncloc1112);
+ int ncloc1113 = 15;
+ addRawMeasure(NCLOC_KEY, 1113, ncloc1113);
+
int nclocValue1121 = 30;
addRawMeasure(NCLOC_KEY, 1121, nclocValue1121);
// verify measures on files
verifyAddedRawMeasure(1111, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1));
- verifyAddedRawMeasure(1112, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_2));
- verifyNoAddedRawMeasure(1113);
+ verifyAddedRawMeasure(1112, DEVELOPMENT_COST_KEY, Long.toString(ncloc1112 * DEV_COST_LANGUAGE_2));
+ verifyAddedRawMeasure(1113, DEVELOPMENT_COST_KEY, Long.toString(ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1121, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(1211, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
// directory has children => dev cost is aggregated
verifyAddedRawMeasure(111, DEVELOPMENT_COST_KEY, Long.toString(
ncloc1111 * DEV_COST_LANGUAGE_1 +
- ncloc1112 * DEV_COST_LANGUAGE_2));
+ ncloc1112 * DEV_COST_LANGUAGE_2 +
+ ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(112, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(121, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(11, DEVELOPMENT_COST_KEY, Long.toString(
ncloc1111 * DEV_COST_LANGUAGE_1 +
ncloc1112 * DEV_COST_LANGUAGE_2 +
+ ncloc1113 * DEV_COST_LANGUAGE_1 +
nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(12, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(13, DEVELOPMENT_COST_KEY, "0");
verifyAddedRawMeasure(1, DEVELOPMENT_COST_KEY, Long.toString(
ncloc1111 * DEV_COST_LANGUAGE_1 +
ncloc1112 * DEV_COST_LANGUAGE_2 +
+ ncloc1113 * DEV_COST_LANGUAGE_1 +
nclocValue1121 * DEV_COST_LANGUAGE_2 +
ncloc1211 * DEV_COST_LANGUAGE_1));
}
assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).contains(entryOf(metricKey, newMeasureBuilder().create(value)));
}
- private void verifyNoAddedRawMeasure(int componentRef) {
- assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).isEmpty();
- }
-
private static ReportComponent createFileComponent(String languageKey1, int fileRef) {
return builder(FILE, fileRef).setFileAttributes(new FileAttributes(false, languageKey1)).build();
}