nl.hsac.fitnesse.junit.reportmerge.writer.JsonWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hsac-fitnesse-fixtures Show documentation
Show all versions of hsac-fitnesse-fixtures Show documentation
Fixtures to assist in testing via FitNesse
package nl.hsac.fitnesse.junit.reportmerge.writer;
import nl.hsac.fitnesse.junit.reportmerge.TestReportHtml;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
public class JsonWriter {
protected PrintWriter pw;
public JsonWriter(PrintWriter pw) {
this.pw = pw;
}
public void writeContent(List reports) {
boolean first = true;
pw.write("[");
for (TestReportHtml report : reports) {
if (first) {
first = false;
} else {
pw.write(",");
}
writeReport(report);
}
pw.write("]");
}
protected void writeReport(TestReportHtml report) {
pw.write("{");
write("timestamp", report.getTimestamp());
pw.write(",");
write("runName", report.getRunName());
pw.write(",");
write("index", report.getIndex());
pw.write(",");
write("testName", report.getTestName());
pw.write(",");
write("status", report.getStatus());
pw.write(",");
write("time", report.getTime());
pw.write(",");
write("overviewPage", report.isOverviewPage());
pw.write(",");
write("relativePath", report.getRelativePath());
pw.write("}");
}
protected void write(String key, String value) {
writeKeyValue(key, "\"" + value + "\"");
}
protected void write(String key, boolean value) {
writeKeyValue(key, value ? "true" : "false");
}
protected void write(String key, int value) {
writeKeyValue(key, Integer.toString(value));
}
protected void write(String key, Date value) {
write(key, value.getTime());
}
protected void write(String key, Long value) {
writeKeyValue(key, Long.toString(value));
}
protected void writeKeyValue(String key, String value) {
pw.write("\"");
pw.write(key);
pw.write("\":");
pw.write(value);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy