diff options
author | David Gageot <david@gageot.net> | 2012-05-25 16:00:12 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-25 16:29:25 +0200 |
commit | a92d064fc3083a83f0f26fdf58b6cece98360129 (patch) | |
tree | 190f28836d0494b9eac896d24d0bef4de1a485bb /sonar-plugin-api/src/test/java/org | |
parent | 28ad4901ffc85a84d1b0a7458ae48e54a7b0a2b4 (diff) | |
download | sonarqube-a92d064fc3083a83f0f26fdf58b6cece98360129.tar.gz sonarqube-a92d064fc3083a83f0f26fdf58b6cece98360129.zip |
Improve test coverage
Diffstat (limited to 'sonar-plugin-api/src/test/java/org')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/web/FilterTest.java | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/FilterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/FilterTest.java index e29f4d23393..602e5c99b54 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/web/FilterTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/FilterTest.java @@ -19,17 +19,51 @@ */ package org.sonar.api.web; -import org.junit.rules.ExpectedException; - import org.junit.Rule; - import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.fest.assertions.Assertions.assertThat; public class FilterTest { @Rule public ExpectedException exception = ExpectedException.none(); @Test + public void should_create_filter() { + Filter filter = Filter.create() + .setDisplayAs("list") + .setFavouritesOnly(true) + .setPageSize(100); + + assertThat(filter.getDisplayAs()).isEqualTo("list"); + assertThat(filter.isFavouritesOnly()).isTrue(); + assertThat(filter.getPageSize()).isEqualTo(100); + } + + @Test + public void should_add_criteria() { + Criterion criterion1 = Criterion.createForQualifier("A"); + Criterion criterion2 = Criterion.createForQualifier("A"); + Filter filter = Filter.create() + .add(criterion1) + .add(criterion2); + + assertThat(filter.getCriteria()).containsExactly(criterion1, criterion2); + } + + @Test + public void should_add_columns() { + FilterColumn column1 = FilterColumn.create("", "", "ASC", false); + FilterColumn column2 = FilterColumn.create("", "", "DESC", false); + Filter filter = Filter.create() + .add(column1) + .add(column2); + + assertThat(filter.getColumns()).containsExactly(column1, column2); + } + + @Test public void should_accept_valid_periods() { Filter.create().setDisplayAs("list"); Filter.create().setDisplayAs("treemap"); @@ -42,4 +76,26 @@ public class FilterTest { Filter.create().setDisplayAs("<invalid>"); } + + @Test + public void should_accept_valid_pageSize() { + Filter.create().setPageSize(20); + Filter.create().setPageSize(200); + } + + @Test + public void should_fail_on_pageSize_too_small() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("page size should be between 20 and 200"); + + Filter.create().setPageSize(19); + } + + @Test + public void should_fail_on_pageSize_too_high() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("page size should be between 20 and 200"); + + Filter.create().setPageSize(201); + } } |