]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6137 Do not fail when createdAfter == createdBefore 98/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 17 Feb 2015 15:09:10 +0000 (16:09 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 18 Feb 2015 16:02:27 +0000 (17:02 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java

index 523e0bacba11246b6d4d897799906e6c182ecf8a..5878c7a6f4612bde2b64207ab8e707b5b5fb7537 100644 (file)
@@ -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");
   }
 
index e8073a7791c05cf8ebfd2d371da6db78f9521ab4..e9392b77d72ff594b4b1eb85de6be8a3f41fa238 100644 (file)
@@ -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 {