From 87d444ab3bf860db5d39843d689ff9d330c18384 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Tue, 17 Feb 2015 16:09:10 +0100 Subject: [PATCH] SONAR-6137 Do not fail when createdAfter == createdBefore --- .../sonar/server/issue/index/IssueIndex.java | 2 +- .../server/issue/index/IssueIndexTest.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 523e0bacba1..5878c7a6f46 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -336,7 +336,7 @@ public class IssueIndex extends BaseIndex { private void validateCreationDateBounds(Date createdBefore, Date createdAfter) { Preconditions.checkArgument(createdAfter == null || createdAfter.before(system.newDate()), "Start bound cannot be in the future"); - Preconditions.checkArgument(createdAfter == null || createdBefore == null || createdAfter.before(createdBefore), + Preconditions.checkArgument(createdAfter == null || createdAfter.equals(createdBefore) || createdBefore == null || createdAfter.before(createdBefore), "Start bound cannot be larger than end bound"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index e8073a7791c..e9392b77d72 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -641,6 +641,51 @@ public class IssueIndexTest { assertThat(index.search(IssueQuery.builder().createdBefore(DateUtils.parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).hasSize(2); } + @Test + public void filter_by_created_after_and_before() throws Exception { + ComponentDto project = ComponentTesting.newProjectDto(); + ComponentDto file = ComponentTesting.newFileDto(project); + + indexIssues( + IssueTesting.newDoc("ISSUE1", file).setFuncCreationDate(DateUtils.parseDate("2014-09-20")), + IssueTesting.newDoc("ISSUE2", file).setFuncCreationDate(DateUtils.parseDate("2014-09-23"))); + + // 19 < createdAt < 25 + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-19")).createdBefore(DateUtils.parseDate("2014-09-25")) + .build(), new SearchOptions()).getDocs()).hasSize(2); + + // 20 < createdAt < 25: excludes first issue + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-20")).createdBefore(DateUtils.parseDate("2014-09-25")) + .build(), new SearchOptions()).getDocs()).hasSize(1); + + // 21 < createdAt < 25 + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-21")).createdBefore(DateUtils.parseDate("2014-09-25")) + .build(), new SearchOptions()).getDocs()).hasSize(1); + + // 21 < createdAt < 24 + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-21")).createdBefore(DateUtils.parseDate("2014-09-24")) + .build(), new SearchOptions()).getDocs()).hasSize(1); + + // 21 < createdAt < 23: excludes second issue + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-21")).createdBefore(DateUtils.parseDate("2014-09-23")) + .build(), new SearchOptions()).getDocs()).isEmpty(); + + // 19 < createdAt < 21: only first issue + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-19")).createdBefore(DateUtils.parseDate("2014-09-21")) + .build(), new SearchOptions()).getDocs()).hasSize(1); + + // 20 < createdAt < 20: nothing + assertThat(index.search(IssueQuery.builder() + .createdAfter(DateUtils.parseDate("2014-09-20")).createdBefore(DateUtils.parseDate("2014-09-20")) + .build(), new SearchOptions()).getDocs()).isEmpty(); + } + @Test public void filter_by_created_before_must_be_lower_than_after() throws Exception { try { -- 2.39.5