aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-06-13 11:32:42 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-06-13 11:33:41 +0200
commit849d0e9ef5ff9bd0049af2f9bcc18f2104579da9 (patch)
tree02c83791a06f9318428520b2a31c956ce582f063 /sonar-plugin-api
parent021a6413c8627d62957de3f85955be3691ceff18 (diff)
downloadsonarqube-849d0e9ef5ff9bd0049af2f9bcc18f2104579da9.tar.gz
sonarqube-849d0e9ef5ff9bd0049af2f9bcc18f2104579da9.zip
Fix null collections in org.sonar.api.issue.IssueQuery
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java53
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java56
2 files changed, 83 insertions, 26 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 5daf278f46a..79e5aace148 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
@@ -27,10 +27,7 @@ import org.sonar.api.web.UserRole;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.Set;
+import java.util.*;
/**
* @since 3.6
@@ -77,16 +74,16 @@ public class IssueQuery {
private final int pageIndex;
private IssueQuery(Builder builder) {
- this.issueKeys = builder.issueKeys;
- this.severities = builder.severities;
- this.statuses = builder.statuses;
- this.resolutions = builder.resolutions;
- this.components = builder.components;
- this.componentRoots = builder.componentRoots;
- this.rules = builder.rules;
- this.actionPlans = builder.actionPlans;
- this.reporters = builder.reporters;
- this.assignees = builder.assignees;
+ this.issueKeys = defaultCollection(builder.issueKeys);
+ this.severities = defaultCollection(builder.severities);
+ this.statuses = defaultCollection(builder.statuses);
+ this.resolutions = defaultCollection(builder.resolutions);
+ this.components = defaultCollection(builder.components);
+ this.componentRoots = defaultCollection(builder.componentRoots);
+ this.rules = defaultCollection(builder.rules);
+ this.actionPlans = defaultCollection(builder.actionPlans);
+ this.reporters = defaultCollection(builder.reporters);
+ this.assignees = defaultCollection(builder.assignees);
this.assigned = builder.assigned;
this.planned = builder.planned;
this.resolved = builder.resolved;
@@ -224,52 +221,52 @@ public class IssueQuery {
private Builder() {
}
- public Builder issueKeys(Collection<String> l) {
+ public Builder issueKeys(@Nullable Collection<String> l) {
this.issueKeys = l;
return this;
}
- public Builder severities(Collection<String> l) {
+ public Builder severities(@Nullable Collection<String> l) {
this.severities = l;
return this;
}
- public Builder statuses(Collection<String> l) {
+ public Builder statuses(@Nullable Collection<String> l) {
this.statuses = l;
return this;
}
- public Builder resolutions(Collection<String> l) {
+ public Builder resolutions(@Nullable Collection<String> l) {
this.resolutions = l;
return this;
}
- public Builder components(Collection<String> l) {
+ public Builder components(@Nullable Collection<String> l) {
this.components = l;
return this;
}
- public Builder componentRoots(Collection<String> l) {
+ public Builder componentRoots(@Nullable Collection<String> l) {
this.componentRoots = l;
return this;
}
- public Builder rules(Collection<RuleKey> rules) {
+ public Builder rules(@Nullable Collection<RuleKey> rules) {
this.rules = rules;
return this;
}
- public Builder actionPlans(Collection<String> l) {
+ public Builder actionPlans(@Nullable Collection<String> l) {
this.actionPlans = l;
return this;
}
- public Builder reporters(Collection<String> l) {
+ public Builder reporters(@Nullable Collection<String> l) {
this.reporters = l;
return this;
}
- public Builder assignees(Collection<String> l) {
+ public Builder assignees(@Nullable Collection<String> l) {
this.assignees = l;
return this;
}
@@ -302,12 +299,12 @@ public class IssueQuery {
}
public Builder createdAfter(@Nullable Date d) {
- this.createdAfter = d;
+ this.createdAfter = (d == null ? null : new Date(d.getTime()));
return this;
}
public Builder createdBefore(@Nullable Date d) {
- this.createdBefore = d;
+ this.createdBefore = (d == null ? null : new Date(d.getTime()));
return this;
}
@@ -367,4 +364,8 @@ public class IssueQuery {
Preconditions.checkArgument(pageIndex > 0, "Page index must be greater than 0 (got " + pageIndex + ")");
}
}
+
+ private static <T> Collection<T> defaultCollection(@Nullable Collection<T> c) {
+ return c == null ? Collections.<T>emptyList() : Collections.unmodifiableCollection(c);
+ }
}
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 3ee45572a6c..27ee1da2ee8 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
@@ -49,6 +49,8 @@ public class IssueQueryTest {
.assigned(true)
.createdAfter(new Date())
.createdBefore(new Date())
+ .planned(true)
+ .resolved(true)
.sort(IssueQuery.SORT_BY_ASSIGNEE)
.pageSize(10)
.pageIndex(2)
@@ -67,6 +69,8 @@ public class IssueQueryTest {
assertThat(query.actionPlans()).containsOnly("AP1", "AP2");
assertThat(query.createdAfter()).isNotNull();
assertThat(query.createdBefore()).isNotNull();
+ assertThat(query.planned()).isTrue();
+ assertThat(query.resolved()).isTrue();
assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_ASSIGNEE);
assertThat(query.pageSize()).isEqualTo(10);
assertThat(query.pageIndex()).isEqualTo(2);
@@ -74,6 +78,58 @@ public class IssueQueryTest {
}
@Test
+ public void collection_params_should_not_be_null_but_empty() throws Exception {
+ IssueQuery query = IssueQuery.builder()
+ .issueKeys(null)
+ .components(null)
+ .componentRoots(null)
+ .statuses(null)
+ .actionPlans(null)
+ .assignees(null)
+ .reporters(null)
+ .resolutions(null)
+ .rules(null)
+ .severities(null)
+ .build();
+ assertThat(query.issueKeys()).isEmpty();
+ assertThat(query.components()).isEmpty();
+ assertThat(query.componentRoots()).isEmpty();
+ assertThat(query.statuses()).isEmpty();
+ assertThat(query.actionPlans()).isEmpty();
+ assertThat(query.assignees()).isEmpty();
+ assertThat(query.reporters()).isEmpty();
+ assertThat(query.resolutions()).isEmpty();
+ assertThat(query.rules()).isEmpty();
+ assertThat(query.severities()).isEmpty();
+ }
+
+ @Test
+ public void test_default_query() throws Exception {
+ IssueQuery query = IssueQuery.builder().build();
+ assertThat(query.issueKeys()).isEmpty();
+ assertThat(query.components()).isEmpty();
+ assertThat(query.componentRoots()).isEmpty();
+ assertThat(query.statuses()).isEmpty();
+ assertThat(query.actionPlans()).isEmpty();
+ assertThat(query.assignees()).isEmpty();
+ assertThat(query.reporters()).isEmpty();
+ assertThat(query.resolutions()).isEmpty();
+ assertThat(query.rules()).isEmpty();
+ assertThat(query.severities()).isEmpty();
+ assertThat(query.assigned()).isNull();
+ assertThat(query.createdAfter()).isNull();
+ assertThat(query.createdBefore()).isNull();
+ assertThat(query.planned()).isNull();
+ assertThat(query.resolved()).isNull();
+ assertThat(query.sort()).isNull();
+ assertThat(query.pageSize()).isEqualTo(100);
+ assertThat(query.pageIndex()).isEqualTo(1);
+ assertThat(query.requiredRole()).isEqualTo(UserRole.USER);
+ assertThat(query.maxResults()).isEqualTo(IssueQuery.MAX_RESULTS);
+
+ }
+
+ @Test
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);