From b8bdde5e341b95afad6726f00c76f303f5de25b0 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 17 May 2013 17:00:15 +0200 Subject: [PATCH] SONAR-3257 use max size when pageSize<=0 --- .../java/org/sonar/api/issue/IssueQuery.java | 3 +-- .../org/sonar/api/issue/IssueQueryTest.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java index 887d57bc0b3..869be8aca7e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java @@ -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 + ")"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java index 2ec08dabf13..fb972c40cee 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java @@ -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(); -- 2.39.5