diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-04-03 13:28:15 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-04-03 13:28:15 +0200 |
commit | e9f0f153b3635b0c8e7f506d7ef7857b12aad753 (patch) | |
tree | 5228f92350c520c999e9e3d0bc31626edff09a02 | |
parent | 7bb307b1ca7d20809b38cd9556b6b34300b9113b (diff) | |
download | sonarqube-e9f0f153b3635b0c8e7f506d7ef7857b12aad753.tar.gz sonarqube-e9f0f153b3635b0c8e7f506d7ef7857b12aad753.zip |
SONAR-5921 Apply feedback from tests
4 files changed, 45 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileProjectsAction.java index d351b0fde1f..9755a806fe7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileProjectsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileProjectsAction.java @@ -78,9 +78,9 @@ public class QProfileProjectsAction implements BaseQProfileWsAction { projects.createParam(PARAM_QUERY) .setDescription("If specified, return only projects whose name match the query."); projects.createParam(PARAM_PAGE_SIZE) - .setDescription("Size for the paging to apply").setDefaultValue(100); + .setDescription("Size for the paging to apply.").setDefaultValue(100); projects.createParam(PARAM_PAGE) - .setDescription("Index of the page to display").setDefaultValue(1); + .setDescription("Index of the page to display.").setDefaultValue(1); } @Override @@ -130,7 +130,8 @@ public class QProfileProjectsAction implements BaseQProfileWsAction { if (pagedAuthorizedProjects.size() <= paging.offset()) { pagedAuthorizedProjects = Lists.newArrayList(); } else if (pagedAuthorizedProjects.size() > paging.pageSize()) { - pagedAuthorizedProjects = pagedAuthorizedProjects.subList(paging.offset(), paging.offset() + pageSize); + int endIndex = Math.min(paging.offset() + pageSize, pagedAuthorizedProjects.size()); + pagedAuthorizedProjects = pagedAuthorizedProjects.subList(paging.offset(), endIndex); } writeProjects(response.newJsonWriter(), pagedAuthorizedProjects, paging); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest.java index 9b73c6a3957..73ede38f285 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest.java @@ -136,6 +136,13 @@ public class QProfileProjectsActionTest { .execute().assertJson(this.getClass(), "empty.json"); newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "2").setParam("page", "4") .execute().assertJson(this.getClass(), "empty.json"); + + newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "3").setParam("page", "1") + .execute().assertJson(this.getClass(), "selected_ps3_page1.json"); + newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "3").setParam("page", "2") + .execute().assertJson(this.getClass(), "selected_ps3_page2.json"); + newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "3").setParam("page", "3") + .execute().assertJson(this.getClass(), "empty.json"); } @Test diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page1.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page1.json new file mode 100644 index 00000000000..978447e76b6 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page1.json @@ -0,0 +1,22 @@ +{ + "results": + [ + { + "key": "DEFA", + "name": "Project Four", + "selected": true + }, + { + "key": "ABCD", + "name": "Project One", + "selected": true + }, + { + "key": "CDEF", + "name": "Project Three", + "selected": true + } + ], + + "more": true +}
\ No newline at end of file diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page2.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page2.json new file mode 100644 index 00000000000..daf6e7e6660 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page2.json @@ -0,0 +1,12 @@ +{ + "results": + [ + { + "key": "BCDE", + "name": "Project Two", + "selected": true + } + ], + + "more": false +}
\ No newline at end of file |