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

org.junit.contrib.java.lang.system.DisallowWriteToSystemOut 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_OUT;

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy