]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4366 Fix NPE when quality gate is empty (no condition)
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Mar 2014 15:38:53 +0000 (16:38 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 10 Mar 2014 09:14:39 +0000 (10:14 +0100)
sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java

index 601acbaf2eb05ed5196b8a909cd8cbee4555488e..ff24c155604eb295f72fd93a90ff62ebccb5da3c 100644 (file)
@@ -113,8 +113,10 @@ public class DefaultQualityGateClient implements QualityGateClient {
     Map jsonRoot = (Map) JSONValue.parse(json);
     Collection<Map> conditionArray = (Collection<Map>) jsonRoot.get("conditions");
     Collection<QualityGateCondition> conditions = new ArrayList<QualityGateCondition>();
-    for (Map conditionJson: conditionArray) {
-      conditions.add(new DefaultQualityGateCondition(conditionJson));
+    if (conditionArray != null) {
+      for (Map conditionJson: conditionArray) {
+        conditions.add(new DefaultQualityGateCondition(conditionJson));
+      }
     }
     return conditions;
   }
index a2628931f74d62a64dcf9d297b77da72c558dd06..7bb2f309a26abeda7ce284b5d18ec3e715877e9d 100644 (file)
@@ -168,6 +168,22 @@ public class DefaultQualityGateClientTest {
     assertThat(sixth.warningThreshold()).isEqualTo("0");
   }
 
+  @Test
+  public void should_show_empty_qualitygate_by_id() {
+    HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+
+    httpServer.stubResponseBody("{\"id\":5,\"name\":\"Sonar way\"}");
+
+    QualityGateClient client = new DefaultQualityGateClient(requestFactory);
+
+    QualityGateDetails qGate = client.show(5L);
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/show?id=5");
+    assertThat(qGate.id()).isEqualTo(5L);
+    assertThat(qGate.name()).isEqualTo("Sonar way");
+
+    Collection<QualityGateCondition> conditions = qGate.conditions();
+    assertThat(conditions).isEmpty();
+  }
 
   @Test
   public void should_destroy_qualitygate() {