org.junit.contrib.java.lang.system.StandardErrorStreamLog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of system-rules Show documentation
Show all versions of system-rules Show documentation
A collection of JUnit rules for testing code which uses java.lang.System.
package org.junit.contrib.java.lang.system;
import static java.lang.System.err;
import static java.lang.System.setErr;
import java.io.PrintStream;
/**
* The {@code StandardErrorStreamLog} captures writes to the standard error
* stream. The text written is available via {@link #getLog()}.
*
*
* public void MyTest {
* @Rule
* public final StandardErrorStreamLog log = new StandardErrorStreamLog();
*
* @Test
* public void overrideProperty() {
* System.err.print("hello world");
* assertEquals("hello world", log.getLog());
* }
* }
*
*/
public class StandardErrorStreamLog extends PrintStreamLog {
@Override
PrintStream getOriginalStream() {
return err;
}
@Override
void setStream(PrintStream wrappedLog) {
setErr(wrappedLog);
}
}