aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-12-10 23:06:29 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-12-10 23:06:29 +0100
commitaa4a3dc35721fd6fdaaa819c17fb0ec2a506a6fe (patch)
treeee6a9f279023427937016bfa8ba924ecc0db6b36 /sonar-core/src
parent5de4c53c916ff31b63f74339abd1b852d1524834 (diff)
downloadsonarqube-aa4a3dc35721fd6fdaaa819c17fb0ec2a506a6fe.tar.gz
sonarqube-aa4a3dc35721fd6fdaaa819c17fb0ec2a506a6fe.zip
SONAR-3825 display null values at the end of results, whatever the asc/desc sorting
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java7
-rw-r--r--sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java24
2 files changed, 29 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java
index e1ec30a4291..54b0d00a007 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java
@@ -99,8 +99,11 @@ class MeasureFilterSql {
}
}
if (filter.sort().isSortedByDatabase()) {
- sql.append(" ORDER BY sortval");
- sql.append(filter.sort().isAsc() ? " ASC " : " DESC ");
+ if (filter.sort().isAsc()) {
+ sql.append(" ORDER BY sortval");
+ } else {
+ sql.append(" ORDER BY CASE WHEN max(sortval) IS NULL THEN 1 ELSE 0 END, sortval DESC");
+ }
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
index 3bc247897a2..3416b62fa8e 100644
--- a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
@@ -219,6 +219,30 @@ public class MeasureFilterExecutorTest extends AbstractDaoTestCase {
}
@Test
+ public void null_measures_are_ordered_after_descending_numeric_measures() throws SQLException {
+ MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK"))
+ .setSortOnMetric(METRIC_COVERAGE).setSortAsc(false);
+ List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+ // Java has coverage but not PHP
+ assertThat(rows).hasSize(2);
+ verifyJavaProject(rows.get(0));
+ verifyPhpProject(rows.get(1));
+ }
+
+ @Test
+ public void null_measures_are_ordered_after_ascending_numeric_measures() throws SQLException {
+ MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK"))
+ .setSortOnMetric(METRIC_COVERAGE).setSortAsc(true);
+ List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+ // Java has coverage but not PHP
+ assertThat(rows).hasSize(2);
+ verifyJavaProject(rows.get(0));
+ verifyPhpProject(rows.get(1));
+ }
+
+ @Test
public void sort_by_missing_numeric_measure() throws SQLException {
// coverage measures are not computed
MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("CLA")).setSortOnMetric(METRIC_COVERAGE);