]> source.dussan.org Git - sonarqube.git/commitdiff
WS API: accept NewParam#setPossibleValues(Collection) with not-null empty collection...
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 26 Jan 2015 14:24:23 +0000 (15:24 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 26 Jan 2015 14:24:33 +0000 (15:24 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java

index 4d8f8a1dac513e1544246ff33775077b38d98ac0..f8bffedc01977ad4686438942690fc27ed9f285f 100644 (file)
@@ -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();
index d12348d4a8d7c4f0ea64ad159efb972940800f5a..550b959019fa7944486802c9900452d0acadfacc 100644 (file)
@@ -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;
@@ -328,6 +329,24 @@ public class WebServiceTest {
     assertThat(action.param("max").possibleValues()).isNull();
   }
 
+  @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 {