From a4d8a3a22dd60518d852b39fbf46782db01c764a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 2 May 2016 10:28:50 +0200 Subject: [PATCH] SONAR-7150 directories count doesn't include empty directories --- .../computation/step/SizeMeasuresStep.java | 2 +- .../step/ReportSizeMeasuresStepTest.java | 14 +++++++------ .../step/ViewsSizeMeasuresStepTest.java | 20 +++++++++---------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SizeMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SizeMeasuresStep.java index fce9685f812..8fd191a5479 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SizeMeasuresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SizeMeasuresStep.java @@ -121,8 +121,8 @@ public class SizeMeasuresStep implements ComputationStep { } private void createMeasures(Component directory, int dirCount, int fileCount) { - measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(dirCount)); if (fileCount > 0) { + measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(dirCount)); measureRepository.add(directory, fileMetric, newMeasureBuilder().create(fileCount)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportSizeMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportSizeMeasuresStepTest.java index d5d0183e0c4..d668f2a99dd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportSizeMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportSizeMeasuresStepTest.java @@ -65,7 +65,7 @@ public class ReportSizeMeasuresStepTest { private static final int FILE_3_REF = 12351; private static final int UNIT_TEST_1_REF = 12352; private static final int UNIT_TEST_2_REF = 12361; - private static final Integer NO_FILE_METRIC = null; + private static final Integer NO_METRIC = null; @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot( @@ -120,7 +120,7 @@ public class ReportSizeMeasuresStepTest { verifyNoMeasure(UNIT_TEST_2_REF); verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 2, 1); verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 1, 1); - verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_FILE_METRIC, 1); + verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC); verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 3, 3); verifyMeasuresOnOtherComponent(MODULE_REF, 3, 3); verifyMeasuresOnOtherComponent(ROOT_REF, 3, 3); @@ -155,7 +155,7 @@ public class ReportSizeMeasuresStepTest { entryOf(metric1Key, newMeasureBuilder().create(7)), entryOf(metric2Key, newMeasureBuilder().create(100)) }; - verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_FILE_METRIC, 1); + verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC); verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 3, 3, subModuleAndAboveEntries); verifyMeasuresOnOtherComponent(MODULE_REF, 3, 3, subModuleAndAboveEntries); verifyMeasuresOnOtherComponent(ROOT_REF, 3, 3, subModuleAndAboveEntries); @@ -180,7 +180,7 @@ public class ReportSizeMeasuresStepTest { verifyNoMeasure(UNIT_TEST_2_REF); verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 2, 1, entryOf(metricKey, newMeasureBuilder().create(16))); verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 1, 1, entryOf(metricKey, newMeasureBuilder().create(3))); - verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_FILE_METRIC, 1); + verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC); verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(19))); verifyMeasuresOnOtherComponent(MODULE_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(19))); verifyMeasuresOnOtherComponent(ROOT_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(19))); @@ -201,10 +201,12 @@ public class ReportSizeMeasuresStepTest { .containsOnly(entryOf(FILES_KEY, newMeasureBuilder().create(fileCount))); } - private void verifyMeasuresOnOtherComponent(int componentRef, @Nullable Integer fileCount, int directoryCount, MeasureRepoEntry... otherMeasures) { + private void verifyMeasuresOnOtherComponent(int componentRef, @Nullable Integer fileCount, @Nullable Integer directoryCount, MeasureRepoEntry... otherMeasures) { MeasureRepoEntry[] measureRepoEntries = concatIntoArray( otherMeasures, - fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)), entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount))); + fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)), + directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount)) + ); assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))) .containsOnly(measureRepoEntries); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsSizeMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsSizeMeasuresStepTest.java index eb7037eb5b3..2e691f4e7b4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsSizeMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsSizeMeasuresStepTest.java @@ -62,7 +62,7 @@ public class ViewsSizeMeasuresStepTest { private static final int PROJECTVIEW_3_REF = 1241; private static final int PROJECTVIEW_4_REF = 1251; private static final int PROJECTVIEW_5_REF = 14; - private static final Integer NO_FILE_METRIC = null; + private static final Integer NO_METRIC = null; @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot( @@ -124,9 +124,9 @@ public class ViewsSizeMeasuresStepTest { verifyNoMeasure(PROJECTVIEW_5_REF); verifyMeasures(SUB_SUBVIEW_1_REF, 3, 3); verifyMeasures(SUB_SUBVIEW_2_REF, 3, 0); - verifyMeasures(SUB_SUBVIEW_3_REF, NO_FILE_METRIC, 4); + verifyMeasures(SUB_SUBVIEW_3_REF, NO_METRIC, NO_METRIC); verifyMeasures(SUBVIEW_1_REF, 6, 7); - verifyMeasures(SUBVIEW_2_REF, NO_FILE_METRIC, 0); + verifyMeasures(SUBVIEW_2_REF, NO_METRIC, NO_METRIC); verifyMeasures(ROOT_REF, 11, 12); } @@ -157,11 +157,11 @@ public class ViewsSizeMeasuresStepTest { verifyMeasures(SUB_SUBVIEW_1_REF, 3, 3, entryOf(metric1Key, newMeasureBuilder().create(7)), entryOf(metric2Key, newMeasureBuilder().create(10))); verifyMeasures(SUB_SUBVIEW_2_REF, 3, 0); - verifyMeasures(SUB_SUBVIEW_3_REF, NO_FILE_METRIC, 4, + verifyMeasures(SUB_SUBVIEW_3_REF, NO_METRIC, NO_METRIC, entryOf(metric2Key, newMeasureBuilder().create(90))); verifyMeasures(SUBVIEW_1_REF, 6, 7, entryOf(metric1Key, newMeasureBuilder().create(7)), entryOf(metric2Key, newMeasureBuilder().create(100))); - verifyMeasures(SUBVIEW_2_REF, NO_FILE_METRIC, 0); + verifyMeasures(SUBVIEW_2_REF, NO_METRIC, NO_METRIC); verifyMeasures(ROOT_REF, 11, 12, entryOf(metric1Key, newMeasureBuilder().create(10)), entryOf(metric2Key, newMeasureBuilder().create(107))); } @@ -186,9 +186,9 @@ public class ViewsSizeMeasuresStepTest { verifyNoMeasure(PROJECTVIEW_5_REF); verifyMeasures(SUB_SUBVIEW_1_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(16))); verifyMeasures(SUB_SUBVIEW_2_REF, 3, 0); - verifyMeasures(SUB_SUBVIEW_3_REF, NO_FILE_METRIC, 4, entryOf(metricKey, newMeasureBuilder().create(3))); + verifyMeasures(SUB_SUBVIEW_3_REF, NO_METRIC, NO_METRIC, entryOf(metricKey, newMeasureBuilder().create(3))); verifyMeasures(SUBVIEW_1_REF, 6, 7, entryOf(metricKey, newMeasureBuilder().create(19))); - verifyMeasures(SUBVIEW_2_REF, NO_FILE_METRIC, 0); + verifyMeasures(SUBVIEW_2_REF, NO_METRIC, NO_METRIC); verifyMeasures(ROOT_REF, 11, 12, entryOf(metricKey, newMeasureBuilder().create(26))); } @@ -202,16 +202,16 @@ public class ViewsSizeMeasuresStepTest { verifyMetricAggregation(CLASSES_KEY); } - private void verifyMeasures(int componentRef, @Nullable Integer fileCount, int directoryCount, MeasureRepoEntry... otherMeasures) { + private void verifyMeasures(int componentRef, @Nullable Integer fileCount, @Nullable Integer directoryCount, MeasureRepoEntry... otherMeasures) { assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))) .containsOnly( concatIntoArray(otherMeasures, createFileAndDirectoryEntries(fileCount, directoryCount))); } - private static MeasureRepoEntry[] createFileAndDirectoryEntries(@Nullable Integer fileCount, int directoryCount) { + private static MeasureRepoEntry[] createFileAndDirectoryEntries(@Nullable Integer fileCount, @Nullable Integer directoryCount) { return new MeasureRepoEntry[] { fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)), - entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount)) + directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount)) }; } -- 2.39.5