Skip to content

Commit

Permalink
[JENKINS-38564] Always return an array from toJson
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Oct 5, 2016
1 parent ec39863 commit fcf9a65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Expand Up @@ -162,12 +162,7 @@ public HttpResponse doStepsToJson(StaplerRequest req) {
array.add(step.toJSON());
}
result.accumulate("result", "success");
if (array.size() == 1) {
result.accumulate("json", array.get(0)); //TODO decide if consistently returning an array is better
} else {
result.accumulate("json", array);
}

result.accumulate("json", array);
} catch (MultipleCompilationErrorsException e) {
result.accumulate("result", "failure");
JSONArray errors = new JSONArray();
Expand Down
Expand Up @@ -36,6 +36,7 @@
import java.io.IOException;
import java.util.Collections;

import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.core.AllOf.allOf;
import static org.hamcrest.core.Is.isA;
import static org.hamcrest.core.StringContains.containsString;
Expand Down Expand Up @@ -70,8 +71,8 @@ public void simpleEchoToJson() throws IOException {
assertThat(result, hasKey("data"));
JSONObject data = result.getJSONObject("data");
assertThat(data, hasEntry("result", "success"));
assertThat(data, hasKey("json"));
JSONObject json = data.getJSONObject("json");
assertThat(data, hasEntry("json", allOf(isA(JSONArray.class), hasSize(1))));
JSONObject json = data.getJSONArray("json").getJSONObject(0);
assertThat(json, allOf(
hasEntry("name", "echo"),
hasEntry("arguments", hasEntry("value", "Hello World"))
Expand Down Expand Up @@ -132,8 +133,8 @@ public void simpleScriptToJson() throws IOException {
assertThat(result, hasKey("data"));
JSONObject data = result.getJSONObject("data");
assertThat(data, hasEntry("result", "success"));
assertThat(data, hasEntry("json", isA(JSONObject.class)));
JSONObject json = data.getJSONObject("json");
assertThat(data, hasEntry("json", allOf(isA(JSONArray.class), hasSize(1))));
JSONObject json = data.getJSONArray("json").getJSONObject(0);
assertThat(json,
allOf(
hasEntry("name", "script"),
Expand Down

0 comments on commit fcf9a65

Please sign in to comment.