diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-08-19 14:05:45 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-08-19 14:17:59 +0200 |
commit | 974319a47a9a2578292159d59654584698785547 (patch) | |
tree | 657c27d28ee292c73331d3aceab63327ffac8c2c /sonar-plugin-api | |
parent | 64ac081cdf2b21b6619471dcd3e588e90f30b5a9 (diff) | |
download | sonarqube-974319a47a9a2578292159d59654584698785547.tar.gz sonarqube-974319a47a9a2578292159d59654584698785547.zip |
Use the new Paging builder
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java index 2a2619ee3e7..618b5f6ce4c 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java @@ -20,16 +20,20 @@ package org.sonar.api.utils; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; +import static org.sonar.api.utils.Paging.forPageIndex; public class PagingTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); @Test public void test_pagination() { - Paging paging = Paging.create(5, 1, 20); + Paging paging = forPageIndex(1).withPageSize(5).andTotal(20); assertThat(paging.pageSize()).isEqualTo(5); assertThat(paging.pageIndex()).isEqualTo(1); @@ -41,45 +45,39 @@ public class PagingTest { @Test public void test_offset() { - assertThat(Paging.create(5, 1, 20).offset()).isEqualTo(0); - assertThat(Paging.create(5, 2, 20).offset()).isEqualTo(5); + assertThat(forPageIndex(1).withPageSize(5).andTotal(20).offset()).isEqualTo(0); + assertThat(forPageIndex(2).withPageSize(5).andTotal(20).offset()).isEqualTo(5); } @Test public void test_number_of_pages() { - assertThat(Paging.create(5, 2, 20).pages()).isEqualTo(4); - assertThat(Paging.create(5, 2, 21).pages()).isEqualTo(5); - assertThat(Paging.create(5, 2, 25).pages()).isEqualTo(5); - assertThat(Paging.create(5, 2, 26).pages()).isEqualTo(6); + assertThat(forPageIndex(2).withPageSize(5).andTotal(20).pages()).isEqualTo(4); + assertThat(forPageIndex(2).withPageSize(5).andTotal(21).pages()).isEqualTo(5); + assertThat(forPageIndex(2).withPageSize(5).andTotal(25).pages()).isEqualTo(5); + assertThat(forPageIndex(2).withPageSize(5).andTotal(26).pages()).isEqualTo(6); } @Test public void page_size_should_be_strictly_positive() { - try { - Paging.create(0, 5, 5); - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Page size must be strictly positive. Got 0"); - } + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Page size must be strictly positive. Got 0"); + + forPageIndex(5).withPageSize(0).andTotal(5); } @Test public void page_index_should_be_strictly_positive() { - try { - Paging.create(5, 0, 5); - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Page index must be strictly positive. Got 0"); - } + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Page index must be strictly positive. Got 0"); + + forPageIndex(0).withPageSize(5).andTotal(5); } @Test public void total_items_should_be_positive() { - try { - Paging.create(5, 5, -1); - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Total items must be positive. Got -1"); - } + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Total items must be positive. Got -1"); + + forPageIndex(5).withPageSize(5).andTotal(-1); } } |