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

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

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

import org.junit.contrib.java.lang.system.internal.DisallowWrite;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import static org.junit.contrib.java.lang.system.internal.PrintStreamHandler.SYSTEM_ERR;

/**
 * {@code DisallowWriteToSystemErr} lets a test fail if it tries to write
 * something to {@code System.err}.
 *
 * 

For that purpose you only have to add {@code DisallowWriteToSystemErr} * rule to your test class *

 * public class TestClass {
 *   @Rule
 *   public final DisallowWriteToSystemErr disallowWriteToSystemErr
 *     = new DisallowWriteToSystemErr();
 *
 *   @Test
 *   public void this_test_fails() {
 *     System.err.println("some text");
 *   }
 * }
 * 
* * @see DisallowWriteToSystemOut * @since 1.14.0 */ public class DisallowWriteToSystemErr implements TestRule { private final DisallowWrite disallowWrite = new DisallowWrite(SYSTEM_ERR); public Statement apply(final Statement base, Description description) { return disallowWrite.createStatement(base); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy