diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-18 16:05:24 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-18 16:05:24 +0100 |
commit | 1226733455cc9e8082bd48f152cf5e4e64cf51dc (patch) | |
tree | b6ada56e5bdee4cc51807da8db83db538d611533 | |
parent | 6955f8a11bcb0d2855012baea10039e2829520ba (diff) | |
download | sonarqube-1226733455cc9e8082bd48f152cf5e4e64cf51dc.tar.gz sonarqube-1226733455cc9e8082bd48f152cf5e4e64cf51dc.zip |
SONAR-7135 WS api/measures/component_tree sort by metric consistent for component measureless
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java | 10 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java | 32 |
2 files changed, 32 insertions, 10 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java index b99ec27a3b3..6c136b2f490 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java @@ -87,13 +87,12 @@ class ComponentTreeSort { } private static Ordering<ComponentDtoWithSnapshotId> stringOrdering(boolean isAscending, Function<ComponentDtoWithSnapshotId, String> function) { - Ordering<String> ordering = Ordering.from(CASE_INSENSITIVE_ORDER) - .nullsLast(); + Ordering<String> ordering = Ordering.from(CASE_INSENSITIVE_ORDER); if (!isAscending) { ordering = ordering.reverse(); } - return ordering.onResultOf(function); + return ordering.nullsLast().onResultOf(function); } /** @@ -129,14 +128,13 @@ class ComponentTreeSort { private static Ordering<ComponentDtoWithSnapshotId> numericalMetricOrdering(boolean isAscending, @Nullable MetricDto metric, Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric) { - Ordering<Double> ordering = Ordering.natural() - .nullsLast(); + Ordering<Double> ordering = Ordering.natural(); if (!isAscending) { ordering = ordering.reverse(); } - return ordering.onResultOf(new ComponentDtoWithSnapshotIdToNumericalMeasureValue(metric, measuresByComponentUuidAndMetric)); + return ordering.nullsLast().onResultOf(new ComponentDtoWithSnapshotIdToNumericalMeasureValue(metric, measuresByComponentUuidAndMetric)); } private static class ComponentDtoWithSnapshotIdToNumericalMeasureValue implements Function<ComponentDtoWithSnapshotId, Double> { diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java index eed4d78fc97..13439ef9655 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java @@ -111,23 +111,47 @@ public class ComponentTreeSortTest { } @Test - public void sort_by_numerical_metric_key() { + public void sort_by_numerical_metric_key_ascending() { + components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure")); ComponentTreeWsRequest wsRequest = newRequest(singletonList(METRIC_SORT), true, NUM_METRIC_KEY); List<ComponentDtoWithSnapshotId> result = sortComponents(wsRequest); assertThat(result).extracting("path") - .containsExactly("path-1", "path-2", "path-3", "path-4", "path-5", "path-6", "path-7", "path-8", "path-9"); + .containsExactly("path-1", "path-2", "path-3", "path-4", "path-5", "path-6", "path-7", "path-8", "path-9", "path-without-measure"); + } + + @Test + public void sort_by_numerical_metric_key_descending() { + components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure")); + ComponentTreeWsRequest wsRequest = newRequest(singletonList(METRIC_SORT), false, NUM_METRIC_KEY); + + List<ComponentDtoWithSnapshotId> result = sortComponents(wsRequest); + + assertThat(result).extracting("path") + .containsExactly("path-9", "path-8", "path-7", "path-6", "path-5", "path-4", "path-3", "path-2", "path-1", "path-without-measure"); } @Test - public void sort_by_textual_metric_key() { + public void sort_by_textual_metric_key_ascending() { + components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure")); ComponentTreeWsRequest wsRequest = newRequest(singletonList(METRIC_SORT), true, TEXT_METRIC_KEY); List<ComponentDtoWithSnapshotId> result = sortComponents(wsRequest); assertThat(result).extracting("path") - .containsExactly("path-1", "path-2", "path-3", "path-4", "path-5", "path-6", "path-7", "path-8", "path-9"); + .containsExactly("path-1", "path-2", "path-3", "path-4", "path-5", "path-6", "path-7", "path-8", "path-9", "path-without-measure"); + } + + @Test + public void sort_by_textual_metric_key_descending() { + components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure")); + ComponentTreeWsRequest wsRequest = newRequest(singletonList(METRIC_SORT), false, TEXT_METRIC_KEY); + + List<ComponentDtoWithSnapshotId> result = sortComponents(wsRequest); + + assertThat(result).extracting("path") + .containsExactly("path-9", "path-8", "path-7", "path-6", "path-5", "path-4", "path-3", "path-2", "path-1", "path-without-measure"); } @Test |