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;
}
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() {