All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.contrib.java.lang.system.StandardErrorStreamLog Maven / Gradle / Ivy

There is a newer version: 1.19.0
Show newest version
package org.junit.contrib.java.lang.system;

import static org.junit.contrib.java.lang.system.LogMode.LOG_AND_WRITE_TO_STREAM;
import static org.junit.contrib.java.lang.system.LogMode.LOG_ONLY;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
 * @deprecated Please use {@link SystemErrRule}.
 *
 * 

The {@code StandardErrorStreamLog} records 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 captureErrorStream() {
 *       System.err.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 error stream. * *
 *   @Test
 *   public void captureErrorStream() {
 *     System.err.print("before");
 *     log.clear();
 *     System.err.print("afterwards");
 *     assertEquals("afterwards", log.getLog());
 *   }
 * 
* *

Prevent output to the standard error stream

* In general it is not necessary that a test writes to the standard error * stream. Avoiding this output may speed up the test and reduce the clutter * on the commandline. *

The test does not write to the stream if the rule is created with the * {@link org.junit.contrib.java.lang.system.LogMode#LOG_ONLY} mode. *

 * @Rule
 * public final StandardErrorStreamLog log = new StandardErrorStreamLog(LOG_ONLY);
*/ @Deprecated public class StandardErrorStreamLog implements TestRule { private final SystemErrRule systemErrRule = new SystemErrRule(); /** * @deprecated Please use * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()}. * *

Creates a rule that records writes while they are still written to the * standard error stream. */ public StandardErrorStreamLog() { this(LOG_AND_WRITE_TO_STREAM); } /** * @deprecated Please use * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()} * instead of * {@code new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM)} or * {@link SystemErrRule#enableLog() new SystemErrRule().enableLog()}.{@link SystemErrRule#mute() mute()} * instead of {@code new StandardErrorStreamLog(LogMode.LOG_ONLY)}. * *

Creates a rule that records writes to the standard error stream * according to the specified {@code LogMode}. * * @param mode how the rule handles writes to the standard error stream. * @throws java.lang.NullPointerException if {@code mode} is null. */ public StandardErrorStreamLog(LogMode mode) { if (mode == null) throw new NullPointerException("The LogMode is missing."); systemErrRule.enableLog(); if (mode == LOG_ONLY) systemErrRule.mute(); } /** * @deprecated Please use * {@link org.junit.contrib.java.lang.system.SystemErrRule#clearLog()}. * *

Clears the log. The log can be used again. */ @Deprecated public void clear() { systemErrRule.clearLog(); } /** * @deprecated Please use * {@link org.junit.contrib.java.lang.system.SystemErrRule#getLog()}. * *

Returns the text written to the standard error stream. * * @return the text written to the standard error stream. */ @Deprecated public String getLog() { return systemErrRule.getLog(); } public Statement apply(Statement base, Description description) { return systemErrRule.apply(base, description); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy