public void sort_by_file_and_line() throws Exception {
db.issueDao().insert(session,
// file Foo.java
- IssueTesting.newDto(rule, file, project).setLine(20).setFilePath("src/Foo.java"),
- IssueTesting.newDto(rule, file, project).setLine(null).setFilePath("src/Foo.java"),
- IssueTesting.newDto(rule, file, project).setLine(25).setFilePath("src/Foo.java"),
+ IssueTesting.newDto(rule, file, project).setLine(20).setFilePath("src/Foo.java").setKee("FOO1"),
+ IssueTesting.newDto(rule, file, project).setLine(null).setFilePath("src/Foo.java").setKee("FOO3"),
+ IssueTesting.newDto(rule, file, project).setLine(25).setFilePath("src/Foo.java").setKee("FOO2"),
// file Bar.java
- IssueTesting.newDto(rule, file, project).setLine(9).setFilePath("src/Bar.java"),
- IssueTesting.newDto(rule, file, project).setLine(109).setFilePath("src/Bar.java")
+ IssueTesting.newDto(rule, file, project).setLine(9).setFilePath("src/Bar.java").setKee("BAR1"),
+ IssueTesting.newDto(rule, file, project).setLine(109).setFilePath("src/Bar.java").setKee("BAR2"),
+ // two issues on the same line -> sort by key
+ IssueTesting.newDto(rule, file, project).setLine(109).setFilePath("src/Bar.java").setKee("BAR3")
);
session.commit();
// ascending sort -> Bar then Foo
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(true);
Result<Issue> result = index.search(query.build(), new QueryContext());
- assertThat(result.getHits()).hasSize(5);
- assertThat(result.getHits().get(0).line()).isEqualTo(9);
- assertThat(result.getHits().get(1).line()).isEqualTo(109);
- assertThat(result.getHits().get(2).line()).isEqualTo(20);
- assertThat(result.getHits().get(3).line()).isEqualTo(25);
- assertThat(result.getHits().get(4).line()).isEqualTo(null);
+ assertThat(result.getHits()).hasSize(6);
+ assertThat(result.getHits().get(0).key()).isEqualTo("BAR1");
+ assertThat(result.getHits().get(1).key()).isEqualTo("BAR2");
+ assertThat(result.getHits().get(2).key()).isEqualTo("BAR3");
+ assertThat(result.getHits().get(3).key()).isEqualTo("FOO1");
+ assertThat(result.getHits().get(4).key()).isEqualTo("FOO2");
+ assertThat(result.getHits().get(5).key()).isEqualTo("FOO3");
// descending sort -> Foo then Bar
query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(false);
result = index.search(query.build(), new QueryContext());
- assertThat(result.getHits()).hasSize(5);
- assertThat(result.getHits().get(0).line()).isEqualTo(25);
- assertThat(result.getHits().get(1).line()).isEqualTo(20);
- assertThat(result.getHits().get(2).line()).isEqualTo(null);
- assertThat(result.getHits().get(3).line()).isEqualTo(109);
- assertThat(result.getHits().get(4).line()).isEqualTo(9);
+ assertThat(result.getHits()).hasSize(6);
+ assertThat(result.getHits().get(0).key()).isEqualTo("FOO2");
+ assertThat(result.getHits().get(1).key()).isEqualTo("FOO1");
+ // nul line is on last. Could be improved.
+ assertThat(result.getHits().get(2).key()).isEqualTo("FOO3");
+ assertThat(result.getHits().get(3).key()).isEqualTo("BAR3");
+ assertThat(result.getHits().get(4).key()).isEqualTo("BAR2");
+ assertThat(result.getHits().get(5).key()).isEqualTo("BAR1");
}
@Test