aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-04 10:34:31 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-04 10:34:31 +0200
commitb9e0daf97c2107da6575bb7c4977c35193952248 (patch)
treec2deed41a318950b45f64de46b971615dded79c3 /sonar-plugin-api
parent7fbb12369a4f13802a7636535c34ad23956b7e75 (diff)
downloadsonarqube-b9e0daf97c2107da6575bb7c4977c35193952248.tar.gz
sonarqube-b9e0daf97c2107da6575bb7c4977c35193952248.zip
SONAR-3755 refactor issue sorting
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java26
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java16
3 files changed, 16 insertions, 30 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 d3fedd09ac7..b80ea04b91e 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
@@ -25,8 +25,6 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.sonar.api.rule.RuleKey;
import javax.annotation.Nullable;
-
-import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
@@ -37,6 +35,10 @@ import java.util.Date;
*/
public class IssueQuery {
+ public static enum Sort {
+ CREATION_DATE, UPDATE_DATE, CLOSE_DATE, ASSIGNEE
+ }
+
private final Collection<String> issueKeys;
private final Collection<String> severities;
private final Collection<String> statuses;
@@ -49,7 +51,7 @@ public class IssueQuery {
private final Boolean assigned;
private final Date createdAfter;
private final Date createdBefore;
- private final String sort;
+ private final Sort sort;
private final boolean asc;
// max results per page
@@ -125,7 +127,7 @@ public class IssueQuery {
return createdBefore;
}
- public String sort() {
+ public Sort sort() {
return sort;
}
@@ -156,10 +158,6 @@ public class IssueQuery {
*/
public static class Builder {
- private enum Sort {
- created, updated, closed, assignee
- }
-
private static final int DEFAULT_PAGE_SIZE = 100;
private static final int MAX_PAGE_SIZE = 1000;
private static final int DEFAULT_PAGE_INDEX = 1;
@@ -176,7 +174,7 @@ public class IssueQuery {
private Boolean assigned = null;
private Date createdAfter;
private Date createdBefore;
- private String sort;
+ private Sort sort;
private boolean asc = false;
private int pageSize = DEFAULT_PAGE_SIZE;
private int pageIndex = DEFAULT_PAGE_INDEX;
@@ -248,14 +246,8 @@ public class IssueQuery {
return this;
}
- public Builder sort(@Nullable String sort) {
- if (sort != null) {
- try {
- this.sort = Sort.valueOf(sort).name();
- } catch (IllegalArgumentException e){
- throw new IllegalArgumentException("Sort should contain only : " + Arrays.toString(Sort.values()), e);
- }
- }
+ public Builder sort(@Nullable Sort sort) {
+ this.sort = sort;
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index 3a5cc176be2..7bc4e18671c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -422,8 +422,8 @@ public final class Rule {
/**
* @since 3.6
*/
- public Rule setCreatedAt(Date created_at) {
- this.createdAt = created_at;
+ public Rule setCreatedAt(Date d) {
+ this.createdAt = d;
return this;
}
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 5a9d955bac1..c7646729b99 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
@@ -46,7 +46,7 @@ public class IssueQueryTest {
.assigned(true)
.createdAfter(new Date())
.createdBefore(new Date())
- .sort("assignee")
+ .sort(IssueQuery.Sort.ASSIGNEE)
.pageSize(10)
.pageIndex(2)
.build();
@@ -62,7 +62,7 @@ public class IssueQueryTest {
assertThat(query.rules()).containsOnly(RuleKey.of("squid", "AvoidCycle"));
assertThat(query.createdAfter()).isNotNull();
assertThat(query.createdBefore()).isNotNull();
- assertThat(query.sort()).isEqualTo("assignee");
+ assertThat(query.sort()).isEqualTo(IssueQuery.Sort.ASSIGNEE);
assertThat(query.pageSize()).isEqualTo(10);
assertThat(query.pageIndex()).isEqualTo(2);
}
@@ -104,14 +104,8 @@ public class IssueQueryTest {
}
@Test
- public void should_validate_sort() throws Exception {
- try {
- IssueQuery.builder()
- .sort("INVALID SORT")
- .build();
- fail();
- } catch (Exception e) {
- assertThat(e).hasMessage("Sort should contain only : [created, updated, closed, assignee]").isInstanceOf(IllegalArgumentException.class);
- }
+ public void should_accept_null_sort() throws Exception {
+ IssueQuery query = IssueQuery.builder().sort(null).build();
+ assertThat(query.sort()).isNull();
}
}