org.junit.contrib.java.lang.system
Class StandardOutputStreamLog

java.lang.Object
  extended by org.junit.contrib.java.lang.system.StandardOutputStreamLog
All Implemented Interfaces:
org.junit.rules.TestRule

Deprecated. Please use SystemOutRule.

The StandardOutputStreamLog records writes to the standard output stream. The text written is available via getLog().

   public void MyTest {
     @Rule
     public final StandardOutputStreamLog log = new StandardOutputStreamLog();

     @Test
     public void captureOutputStream() {
       System.out.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 output stream.
   @Test
   public void captureOutputStream() {
     System.out.print("before");
     log.clear();
     System.out.print("afterwards");
     assertEquals("afterwards", log.getLog());
   }
 

Prevent output to the standard output stream

In general it is not necessary that a test writes to the standard output 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 LogMode.LOG_ONLY mode.

 @Rule
 public final StandardOutputStreamLog log = new StandardOutputStreamLog(LOG_ONLY);

@Deprecated
public class StandardOutputStreamLog
extends Object
implements org.junit.rules.TestRule


Constructor Summary
StandardOutputStreamLog()
          Deprecated. Please use new SystemOutRule().enableLog().

Creates a rule that records writes while they are still written to the standard output stream.

StandardOutputStreamLog(LogMode mode)
          Deprecated. Please use new SystemOutRule().enableLog() instead of new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM) or new SystemOutRule().enableLog().mute() instead of new StandardOutputStreamLog(LogMode.LOG_ONLY).

Creates a rule that records writes to the standard output stream according to the specified LogMode.

 
Method Summary
 org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
          Deprecated.  
 void clear()
          Deprecated. Please use SystemOutRule.clearLog().

Clears the log. The log can be used again.

 String getLog()
          Deprecated. Please use SystemOutRule.getLog().

Returns the text written to the standard output stream.

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardOutputStreamLog

public StandardOutputStreamLog()
Deprecated. Please use new SystemOutRule().enableLog().

Creates a rule that records writes while they are still written to the standard output stream.


StandardOutputStreamLog

public StandardOutputStreamLog(LogMode mode)
Deprecated. Please use new SystemOutRule().enableLog() instead of new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM) or new SystemOutRule().enableLog().mute() instead of new StandardOutputStreamLog(LogMode.LOG_ONLY).

Creates a rule that records writes to the standard output stream according to the specified LogMode.

Parameters:
mode - how the rule handles writes to the standard output stream.
Throws:
NullPointerException - if mode is null.
Method Detail

clear

@Deprecated
public void clear()
Deprecated. Please use SystemOutRule.clearLog().

Clears the log. The log can be used again.


getLog

@Deprecated
public String getLog()
Deprecated. Please use SystemOutRule.getLog().

Returns the text written to the standard output stream.

Returns:
the text written to the standard output stream.

apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
                                               org.junit.runner.Description description)
Deprecated. 
Specified by:
apply in interface org.junit.rules.TestRule


Copyright © 2011–2018. All rights reserved.