aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-01-26 15:24:23 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-01-26 15:24:33 +0100
commit88325e4bdd2f914ee8b4c33d1727b711bdeed898 (patch)
treef61ce1d4920095586641464b533e5cb173d1e751 /sonar-plugin-api
parent38eafa1405c79b577143f4376c2fca9b5cd1259e (diff)
downloadsonarqube-88325e4bdd2f914ee8b4c33d1727b711bdeed898.tar.gz
sonarqube-88325e4bdd2f914ee8b4c33d1727b711bdeed898.zip
WS API: accept NewParam#setPossibleValues(Collection) with not-null empty collection parameter
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java19
2 files changed, 20 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
index 4d8f8a1dac5..f8bffedc019 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
@@ -504,7 +504,7 @@ public interface WebService extends ServerExtension {
* @since 4.4
*/
public NewParam setPossibleValues(@Nullable Collection values) {
- if (values == null) {
+ if (values == null || values.isEmpty()) {
this.possibleValues = null;
} else {
this.possibleValues = Sets.newLinkedHashSet();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
index d12348d4a8d..550b959019f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
@@ -26,6 +26,7 @@ import org.sonar.api.rule.RuleStatus;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
+import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@@ -329,6 +330,24 @@ public class WebServiceTest {
}
@Test
+ public void param_with_empty_possible_values() {
+ new WebService() {
+ @Override
+ public void define(Context context) {
+ NewController newController = context.createController("api/rule");
+ NewAction create = newController.createAction("create").setHandler(mock(RequestHandler.class));
+ create.createParam("status")
+ .setPossibleValues(Collections.emptyList());
+ newController.done();
+ }
+ }.define(context);
+
+ WebService.Action action = context.controller("api/rule").action("create");
+ // no possible values -> return null but not empty
+ assertThat(action.param("status").possibleValues()).isNull();
+ }
+
+ @Test
public void fail_if_required_param_has_default_value() {
try {
new WebService() {