package com.mumux.androidtesting.runner;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class ScenarioTestCase {
// Mandatory
private final String name;
public final TestStatus status;
// Optional
public String message = null;
//private final String filename = null;
List<ActionTestCase> actionTestCases = new ArrayList<>();
long duration = 0;
ScenarioTestCase(String name, TestStatus status) {
this.name = name;
this.status = status;
}
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
try {
// Mandatory
jsonObject.put("name", name);
jsonObject.put("status", status);
// Optional
if (duration > 0) {
jsonObject.put("duration", duration);
}
if (message != null) {
jsonObject.put("message", message);
}
//if (filename != null) {
// jsonObject.put("filename", filename);
//}
if (!actionTestCases.isEmpty()) {
JSONArray actions = new JSONArray();
for (ActionTestCase action : actionTestCases) {
actions.put(action.toJson());
}
jsonObject.put("actions", actions);
}
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}
}