Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Created January 10, 2014 03:55
Show Gist options
  • Save tarynsauer/8346753 to your computer and use it in GitHub Desktop.
Save tarynsauer/8346753 to your computer and use it in GitHub Desktop.
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
public class MockPrintStream extends PrintStream {
public ArrayList<String> printCallHistory;
public void setPrintCallHistory(ArrayList<String> printCallHistory) {
this.printCallHistory = printCallHistory;
}
public MockPrintStream(OutputStream outputStream) {
super(outputStream);
}
public void println(String printOutput) {
printCallHistory.add(printOutput);
}
public void print(String printOutput) {
printCallHistory.add(printOutput);
}
public String getPrintCallHistory() {
int arrayLength = printCallHistory.size();
StringBuilder result;
result = new StringBuilder();
for (int i = 0; i < arrayLength; i++) {
result.append(printCallHistory.get(i));
}
return result.toString();
}
public String lastPrintCall() {
return printCallHistory.get(printCallHistory.size() - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment