Created
January 10, 2014 03:55
-
-
Save tarynsauer/8346753 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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