]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7870 Do not ignore unit tests when computing measures based on issues 1102/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 13 Jul 2016 15:35:18 +0000 (17:35 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 15 Jul 2016 06:36:59 +0000 (08:36 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/qualitymodel/NewQualityModelMeasuresVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/qualitymodel/QualityModelMeasuresVisitor.java
server/sonar-server/src/test/java/org/sonar/server/computation/qualitymodel/NewQualityModelMeasuresVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/qualitymodel/QualityModelMeasuresVisitorForReportTest.java

index 0a9df567c79e442f110a60e962622a5639b75b08..325c76a4d037fff5ec56368498495ba47756778e 100644 (file)
@@ -104,10 +104,6 @@ public class NewQualityModelMeasuresVisitor extends PathAwareVisitorAdapter<NewQ
 
   @Override
   public void visitFile(Component file, Path<NewTechDebtRatioCounter> path) {
-    if (file.getFileAttributes().isUnitTest()) {
-      return;
-    }
-
     initNewDebtRatioCounter(file, path);
     computeAndSaveNewDebtRatioMeasure(file, path);
     increaseNewDebtAndDevCostOfParent(path);
index a6bd2569c0690128b664bd841765196da70ffb5e..8fb1b81cfd1e602acd57d4eb611efe6db32926b9 100644 (file)
@@ -116,10 +116,8 @@ public class QualityModelMeasuresVisitor extends PathAwareVisitorAdapter<Quality
 
   @Override
   public void visitFile(Component file, Path<QualityModelCounter> path) {
-    if (!file.getFileAttributes().isUnitTest()) {
-      path.current().addDevCosts(computeDevelopmentCost(file));
-      computeAndSaveMeasures(file, path);
-    }
+    path.current().addDevCosts(computeDevelopmentCost(file));
+    computeAndSaveMeasures(file, path);
   }
 
   private long computeDevelopmentCost(Component file) {
index 27f402162b65b94f0ea341ebfb060b534a5e486f..35a273cf5db6bc3eb80a6269000276b53176e778 100644 (file)
@@ -195,29 +195,16 @@ public class NewQualityModelMeasuresVisitorTest {
   }
 
   @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
index 0b2dee0df9614c49c11d644e6b3d3b4df74043e0..caa5d2116f1bb83582b471204d9c53c942a320ef 100644 (file)
@@ -175,6 +175,7 @@ public class QualityModelMeasuresVisitorForReportTest {
               .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)
@@ -198,9 +199,12 @@ public class QualityModelMeasuresVisitorForReportTest {
     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);
 
@@ -211,8 +215,8 @@ public class QualityModelMeasuresVisitorForReportTest {
 
     // 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));
 
@@ -222,7 +226,8 @@ public class QualityModelMeasuresVisitorForReportTest {
     // 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));
 
@@ -230,12 +235,14 @@ public class QualityModelMeasuresVisitorForReportTest {
     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));
   }
@@ -484,10 +491,6 @@ public class QualityModelMeasuresVisitorForReportTest {
     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();
   }