org.ccnx.ccn.test.ThreadAssertionRunner Class Reference

Junit cannot catch exceptions from spawned threads. More...

List of all members.

Public Member Functions

 ThreadAssertionRunner (final Runnable runner)
void start ()
void join () throws InterruptedException, Error, Exception
boolean isAlive ()

Detailed Description

Junit cannot catch exceptions from spawned threads.

This wrapper class will catch assertion failures in a Runnable and report them to the caller.

Junit Assert.X method throw an AssertionError, which is a Throwable -> Error -> AssertionError. So, we capture both an Error and an Exception. Don't use Throwable, as those get messy to handle in the caller.

How to use: 1) Create a Runnable class (could even be anonymous inner class), and wrap it in a ThreadAssertionRunner:

ThreadAssertionRunner tar = new ThreadAssertionRunner(new MyRunner(some_parameter));

2) Start the Runner like a thread:

tar.start();

3) Do normal processing, then stop your runnable. You must join the Runner to wait for exit. THIS STEP IS REQUIRED (it's the join that reports any exceptions or errors from the run() method of your runnable):

tar.join();


The documentation for this class was generated from the following file:
Generated on Fri May 13 16:27:51 2011 for Content-Centric Networking in Java by  doxygen 1.6.3