summaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/output/TextTestWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cz/crcs/ectester/reader/output/TextTestWriter.java')
-rw-r--r--src/cz/crcs/ectester/reader/output/TextTestWriter.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/reader/output/TextTestWriter.java b/src/cz/crcs/ectester/reader/output/TextTestWriter.java
new file mode 100644
index 0000000..80c7204
--- /dev/null
+++ b/src/cz/crcs/ectester/reader/output/TextTestWriter.java
@@ -0,0 +1,66 @@
+package cz.crcs.ectester.reader.output;
+
+import cz.crcs.ectester.reader.test.Test;
+import cz.crcs.ectester.reader.test.TestSuite;
+
+import java.io.PrintStream;
+
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public class TextTestWriter implements TestWriter {
+ private PrintStream output;
+ private ResponseWriter respWriter;
+
+ public TextTestWriter(PrintStream output) {
+ this.output = output;
+ this.respWriter = new ResponseWriter(output);
+ }
+
+ @Override
+ public void begin(TestSuite suite) {
+ }
+
+ private String testPrefix(Test t) {
+ return String.format("%-4s", t.getResult() == Test.Result.SUCCESS ? "OK" : "NOK");
+ }
+
+ private String testString(Test t) {
+ if (!t.hasRun())
+ return null;
+
+ StringBuilder out = new StringBuilder();
+ if (t instanceof Test.Simple) {
+ Test.Simple test = (Test.Simple) t;
+ out.append(String.format("%-70s:", testPrefix(t) + " : " + test.getDescription())).append(" : ");
+ out.append(respWriter.responseSuffix(test.getResponse()));
+ } else if (t instanceof Test.Compound) {
+ Test.Compound test = (Test.Compound) t;
+ Test[] tests = test.getTests();
+ for (int i = 0; i < tests.length; ++i) {
+ if (i == 0) {
+ out.append(" /- ");
+ } else if (i == tests.length - 1) {
+ out.append(" \\- ");
+ } else {
+ out.append(" | ");
+ }
+ out.append(testString(tests[i])).append(System.lineSeparator());
+ }
+ out.append(String.format("%-70s:", testPrefix(t) + " : " + test.getDescription()));
+ }
+ return out.toString();
+ }
+
+ @Override
+ public void outputTest(Test t) {
+ if (!t.hasRun())
+ return;
+ output.println(testString(t));
+ output.flush();
+ }
+
+ @Override
+ public void end() {
+ }
+}