}
}
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");
+ }
}
}
verifyJavaTinyFile(rows.get(1));
}
+ @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