Commit 5bf5edc4 authored by Alexander's avatar Alexander
Browse files

Add the Terminal.java from the last commit

parent ba58ea7e
......@@ -23,7 +23,7 @@ public final class Terminal {
* If enabled Terminal creates a file with TestPairs of the current run
*/
public static boolean isTestCreation = false;
private static boolean useErrorMessagesInTestCreation = true;
private static boolean useMyErrorMessagesInTestCreation = true;
private static StringBuilder testPairFile = new StringBuilder();
/**
......@@ -42,11 +42,6 @@ public final class Terminal {
*/
private static final BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
/**
* this boolean determines whether the user already outputted something for that readLine call
*/
public static boolean concatOutput = true;
/**
* Private constructor to avoid object generation.
*
......@@ -71,19 +66,19 @@ public final class Terminal {
String out = "Error, " + message;
if (isTest) {
if (concatOutput) {
OUT_TEST.add(OUT_TEST.pollLast() + "\n" + out);
} else {
String current = OUT_TEST.pollLast();
if (current == null || current.isEmpty()) {
OUT_TEST.add(out);
concatOutput = true;
} else {
OUT_TEST.add(current + "\n" + out);
}
} else if (isTestCreation) {
System.err.println(out);
if (useErrorMessagesInTestCreation) {
if (useMyErrorMessagesInTestCreation) {
testPairFile.append(out);
testPairFile.append("\n");
} else {
testPairFile.append("Error, ...\n");
testPairFile.append("Error, ...");
}
} else {
System.err.println(out);
......@@ -101,12 +96,8 @@ public final class Terminal {
*/
public static void printLine(final Object object) {
if (isTest) {
if (concatOutput) {
OUT_TEST.add(OUT_TEST.pollLast() + "\n" + object);
} else {
OUT_TEST.add(object.toString());
concatOutput = true;
}
String current = OUT_TEST.pollLast();
OUT_TEST.add((current.isEmpty() ? "" : current + "\n") + object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -157,12 +148,9 @@ public final class Terminal {
throw new RuntimeException(e);
}
else {
if (!concatOutput) {
//The program outputted nothing. To support this in tests, we append an empty line
OUT_TEST.add("");
} else {
concatOutput = false;
}
//If the program outputted nothing we still have at least an empty line
OUT_TEST.add("");
assert !IN_TEST.isEmpty()
: "Either the executed test doesn't has quit as last input\n"
+ "or your quitting mechanism doesn't work properly.\n"
......@@ -248,7 +236,7 @@ public final class Terminal {
* @param doNotUseMyErrorMessages tells the program to use 'Error, ...' instead of the error-msges for io-files
*/
public static void startTestCreation(String[] args, boolean doNotUseMyErrorMessages) {
useErrorMessagesInTestCreation = !doNotUseMyErrorMessages;
useMyErrorMessagesInTestCreation = !doNotUseMyErrorMessages;
startTestCreation(args);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment