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;
import org.junit.contrib.java.lang.system.internal.PrintStreamLog;
/**
* 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
protected PrintStream getOriginalStream() {
return err;
}
@Override
protected void setStream(PrintStream wrappedLog) {
setErr(wrappedLog);
}
}