![JAR search and dependency download from the Maven repository](/logo.png)
org.junit.contrib.java.lang.system.internal.PrintStreamLog 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.internal;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import org.junit.rules.ExternalResource;
public abstract class PrintStreamLog extends ExternalResource {
private final ByteArrayOutputStream log = new ByteArrayOutputStream();
private PrintStream originalStream;
@Override
protected void before() throws Throwable {
originalStream = getOriginalStream();
PrintStream wrappedLog = new PrintStream(log);
setStream(wrappedLog);
}
@Override
protected void after() {
setStream(originalStream);
}
protected abstract PrintStream getOriginalStream();
protected abstract void setStream(PrintStream wrappedLog);
/**
* Returns the text written to the standard error stream.
*
* @return the text written to the standard error stream.
*/
public String getLog() {
try {
return log.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy