aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-20 11:30:15 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-20 11:30:20 +0100
commitdd2e1401e5c74ab50a7432964995de87e100d95f (patch)
tree720b5ec17dfeb5a54811878db4ebc8cdd46f8495 /sonar-ws-client
parent5666d41460c1784d210d32cd9ec8de7b7c039035 (diff)
downloadsonarqube-dd2e1401e5c74ab50a7432964995de87e100d95f.tar.gz
sonarqube-dd2e1401e5c74ab50a7432964995de87e100d95f.zip
Fix quality flaws
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGates.java11
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java18
2 files changed, 25 insertions, 4 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGates.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGates.java
index b1897fed813..e29c5123a37 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGates.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGates.java
@@ -19,6 +19,8 @@
*/
package org.sonar.wsclient.qualitygate.internal;
+import org.json.simple.JSONArray;
+
import org.sonar.wsclient.unmarshallers.JsonUtils;
import org.sonar.wsclient.qualitygate.QualityGate;
@@ -37,9 +39,12 @@ public class DefaultQualityGates implements QualityGates {
@SuppressWarnings("unchecked")
public DefaultQualityGates(Map<String, Object> json) {
qualityGates = new LinkedHashMap<Long, QualityGate>();
- for (Object entry: JsonUtils.getArray(json, "qualitygates")) {
- QualityGate qGate = new DefaultQualityGate((Map<String, String>) entry);
- qualityGates.put(qGate.id(), qGate);
+ JSONArray gatesJson = JsonUtils.getArray(json, "qualitygates");
+ if (gatesJson != null) {
+ for (Object entry: gatesJson) {
+ QualityGate qGate = new DefaultQualityGate((Map<String, String>) entry);
+ qualityGates.put(qGate.id(), qGate);
+ }
}
defaultId = JsonUtils.getLong(json, "default");
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java
index ddf9c29e9d4..f6cb803a6a9 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java
@@ -60,7 +60,7 @@ public class DefaultQualityGateClientTest {
HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
httpServer.stubResponseBody(
- "{\"qualitygates\":[{\"id\":666,\"name\":\"Ninth\"},{\"id\":42,\"name\":\"Golden\"},{\"id\":43,\"name\":\"Star\"}]}");
+ "{\"qualitygates\":[{\"id\":666,\"name\":\"Ninth\"},{\"id\":42,\"name\":\"Golden\"},{\"id\":43,\"name\":\"Star\"}],\"default\":42}");
QualityGateClient client = new DefaultQualityGateClient(requestFactory);
QualityGates qGates = client.list();
@@ -68,6 +68,22 @@ public class DefaultQualityGateClientTest {
assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/list");
assertThat(httpServer.requestParams()).isEmpty();
assertThat(qGates.qualityGates()).hasSize(3);
+ assertThat(qGates.defaultGate().id()).isEqualTo(42L);
+ }
+
+ @Test
+ public void should_list_qualitygates_empty() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+
+ httpServer.stubResponseBody(
+ "{}");
+
+ QualityGateClient client = new DefaultQualityGateClient(requestFactory);
+ QualityGates qGates = client.list();
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/list");
+ assertThat(httpServer.requestParams()).isEmpty();
+ assertThat(qGates.qualityGates()).isEmpty();
assertThat(qGates.defaultGate()).isNull();
}