bb.util
Class JUnitExecutor.StdStreamSwapper

java.lang.Object
  extended by org.junit.runner.notification.RunListener
      extended by bb.util.JUnitExecutor.RunListenerAbstract
          extended by bb.util.JUnitExecutor.StdStreamSwapper
Enclosing class:
JUnitExecutor

private static class JUnitExecutor.StdStreamSwapper
extends JUnitExecutor.RunListenerAbstract

Every time that a test method is about to be executed, this intercepts the standard streams (out and err) and captures any output. The last line of each stream's output is continously overwritten to the console to let the user know what the test method is generating. Each stream's complete output is saved to a dedicated file once the test method finishes. This both reduces the console clutter as well as makes it extremely easy to find the output from a given test method.

This class is multithread safe: every method is synchronized.


Field Summary
private  File classDir
           
private  File fileErr
           
private  File fileOut
           
 
Fields inherited from class bb.util.JUnitExecutor.RunListenerAbstract
className, methodName
 
Constructor Summary
private JUnitExecutor.StdStreamSwapper()
           
 
Method Summary
private  void onProblem(String message, Throwable t)
          Handles problems generated by the JUnit framework itself (including this class), as opposed to Throwables raised by the test methods (which should get caught by the JUnit framework and passed to testFailure).
 void testFailure(Failure failure)
           
 void testFinished(Description description)
           
 void testIgnored(Description description)
          Note: the Junit 4 javadocs do not describe this method well (as of 2008/5/8), but it currently is called instead of testStarted if the method is annotated with both @Ignore and @Test.
 void testRunFinished(Result result)
           
 void testRunStarted(Description description)
           
 void testStarted(Description description)
           
 
Methods inherited from class bb.util.JUnitExecutor.RunListenerAbstract
parseNames
 
Methods inherited from class org.junit.runner.notification.RunListener
testAssumptionFailure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classDir

private File classDir

fileOut

private File fileOut

fileErr

private File fileErr
Constructor Detail

JUnitExecutor.StdStreamSwapper

private JUnitExecutor.StdStreamSwapper()
Method Detail

testRunStarted

public void testRunStarted(Description description)
Overrides:
testRunStarted in class RunListener

testStarted

public void testStarted(Description description)
Overrides:
testStarted in class RunListener

testIgnored

public void testIgnored(Description description)
Note: the Junit 4 javadocs do not describe this method well (as of 2008/5/8), but it currently is called instead of testStarted if the method is annotated with both @Ignore and @Test. In this case, there will be no subsequent call to testFinished; only this method is called.

Overrides:
testIgnored in class RunListener

testFailure

public void testFailure(Failure failure)
Overrides:
testFailure in class RunListener

testFinished

public void testFinished(Description description)
Overrides:
testFinished in class RunListener

testRunFinished

public void testRunFinished(Result result)
Overrides:
testRunFinished in class RunListener

onProblem

private void onProblem(String message,
                       Throwable t)
                throws RuntimeException
Handles problems generated by the JUnit framework itself (including this class), as opposed to Throwables raised by the test methods (which should get caught by the JUnit framework and passed to testFailure).

This method simply calls StdStreams.unswap and then throws a new RuntimeException made from message and t.

Throws:
RuntimeException