]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3257 use max size when pageSize<=0
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 17 May 2013 15:00:15 +0000 (17:00 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 17 May 2013 15:00:15 +0000 (17:00 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java

index 887d57bc0b36eade7f1a597314fdaa96f0eaba7a..869be8aca7e4281609f5bba0cff76487c06294e2 100644 (file)
@@ -332,10 +332,9 @@ public class IssueQuery {
       } else {
         if (pageSize == null) {
           pageSize = DEFAULT_PAGE_SIZE;
-        } else if (pageSize > MAX_PAGE_SIZE) {
+        } else if (pageSize<=0 || pageSize > MAX_PAGE_SIZE) {
           pageSize = MAX_PAGE_SIZE;
         }
-        Preconditions.checkArgument(pageSize > 0, "Page size must be greater than 0 (got " + pageSize + ")");
       }
     }
 
index 2ec08dabf13e6f00c643034f5b6b9549e121c107..fb972c40ceed92a21610c0421a735f1c03f51e7e 100644 (file)
@@ -74,15 +74,12 @@ public class IssueQueryTest {
   }
 
   @Test
-  public void page_size_should_be_positive() throws Exception {
-    try {
-      IssueQuery.builder()
-        .pageSize(0)
-        .build();
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Page size must be greater than 0 (got 0)").isInstanceOf(IllegalArgumentException.class);
-    }
+  public void should_use_max_page_size_if_negative() throws Exception {
+    IssueQuery query = IssueQuery.builder().pageSize(0).build();
+    assertThat(query.pageSize()).isEqualTo(IssueQuery.MAX_PAGE_SIZE);
+
+    query = IssueQuery.builder().pageSize(-1).build();
+    assertThat(query.pageSize()).isEqualTo(IssueQuery.MAX_PAGE_SIZE);
   }
 
   @Test
@@ -93,7 +90,7 @@ public class IssueQueryTest {
   }
 
   @Test
-  public void automatically_resize_page_size() throws Exception {
+  public void should_reset_to_max_page_size() throws Exception {
     IssueQuery query = IssueQuery.builder()
       .pageSize(IssueQuery.MAX_PAGE_SIZE + 100)
       .build();