aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins CI <ci@sonarsource.com>2016-02-18 16:47:35 +0100
committerJenkins CI <ci@sonarsource.com>2016-02-18 16:47:35 +0100
commitc096255c9f57d03a70e02fd99ba06e9e0d737fc3 (patch)
treee0a5922f5524329749eca70b853308ae7fdc6b67
parent86ab67c6f779e2cc92fb8ad6ac9904da6607eea5 (diff)
parent1226733455cc9e8082bd48f152cf5e4e64cf51dc (diff)
downloadsonarqube-5.5-M3.tar.gz
sonarqube-5.5-M3.zip
Automatic merge from branch-5.45.5-M3
* origin/branch-5.4: 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.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java32
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