public class StandardOutputStreamLog extends PrintStreamLog
StandardOutputStreamLog records writes to the standard output
stream. The text written is available via PrintStreamLog.getLog().
public void MyTest {
@Rule
public final StandardOutputStreamLog log = new StandardOutputStreamLog();
@Test
public void captureOutputStream() {
System.out.print("hello world");
assertEquals("hello world", log.getLog());
}
}
You can clear the log if you only want to test parts of the text written to
the standard output stream.
@Test
public void captureOutputStream() {
System.out.print("before");
log.clear();
System.out.print("afterwards");
assertEquals("afterwards", log.getLog());
}
The test does not write to the stream if the rule is created with the
LogMode.LOG_ONLY mode.
@Rule public final StandardOutputStreamLog log = new StandardOutputStreamLog(LOG_ONLY);
| Constructor and Description |
|---|
StandardOutputStreamLog()
Creates a rule that records writes while they are still written to the
standard output stream.
|
StandardOutputStreamLog(LogMode mode)
Creates a rule that records writes to the standard output stream
according to the specified
LogMode. |
| Modifier and Type | Method and Description |
|---|---|
protected java.io.PrintStream |
getOriginalStream() |
protected void |
setStream(java.io.PrintStream wrappedLog) |
after, before, clear, getLogpublic StandardOutputStreamLog()
public StandardOutputStreamLog(LogMode mode)
LogMode.mode - how the rule handles writes to the standard output stream.java.lang.NullPointerException - if mode is null.protected java.io.PrintStream getOriginalStream()
getOriginalStream in class PrintStreamLogprotected void setStream(java.io.PrintStream wrappedLog)
setStream in class PrintStreamLogCopyright © 2011-2015. All Rights Reserved.