org.apache.qpid.test.framework
Class ExceptionMonitor

java.lang.Object
  extended by org.apache.qpid.test.framework.ExceptionMonitor
All Implemented Interfaces:
ExceptionListener

public class ExceptionMonitor
extends Object
implements ExceptionListener

An exception monitor, listens for JMS exception on a connection or consumer. It record all exceptions that it receives and provides methods to test the number and type of exceptions received.

CRC Card
Responsibilities Collaborations
Record all exceptions received.


Field Summary
(package private)  List<Exception> exceptions
          Holds the received exceptions.
 
Constructor Summary
ExceptionMonitor()
           
 
Method Summary
 boolean assertExceptionOfType(Class exceptionClass)
          Checks that at least one exception of the the specified type, has been received.
 boolean assertNoExceptions()
          Checks that no exceptions have been received.
 boolean assertOneJMSException()
          Checks that exactly one exception has been received.
 boolean assertOneJMSExceptionWithLinkedCause(Class aClass)
          Checks that exactly one exception, with a linked cause of the specified type, has been received.
static String getStackTrace(Throwable t)
          Prints an exception stack trace into a string.
 void onException(JMSException e)
          Receives incoming exceptions.
 void reset()
          Clears the record of received exceptions.
 int size()
          Reports the number of exceptions held by this monitor.
 String toString()
          Provides a dump of the stack traces of all exceptions that this exception monitor was notified of.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

exceptions

List<Exception> exceptions
Holds the received exceptions.

Constructor Detail

ExceptionMonitor

public ExceptionMonitor()
Method Detail

onException

public void onException(JMSException e)
Receives incoming exceptions.

Specified by:
onException in interface ExceptionListener
Parameters:
e - The exception to record.

assertNoExceptions

public boolean assertNoExceptions()
Checks that no exceptions have been received.

Returns:
true if no exceptions have been received, false otherwise.

assertOneJMSException

public boolean assertOneJMSException()
Checks that exactly one exception has been received.

Returns:
true if exactly one exception been received, false otherwise.

assertOneJMSExceptionWithLinkedCause

public boolean assertOneJMSExceptionWithLinkedCause(Class aClass)
Checks that exactly one exception, with a linked cause of the specified type, has been received.

Parameters:
aClass - The type of the linked cause.
Returns:
true if exactly one exception, with a linked cause of the specified type, been received, false otherwise.

assertExceptionOfType

public boolean assertExceptionOfType(Class exceptionClass)
Checks that at least one exception of the the specified type, has been received.

Parameters:
exceptionClass - The type of the exception.
Returns:
true if at least one exception of the specified type has been received, false otherwise.

size

public int size()
Reports the number of exceptions held by this monitor.

Returns:
The number of exceptions held by this monitor.

reset

public void reset()
Clears the record of received exceptions.


toString

public String toString()
Provides a dump of the stack traces of all exceptions that this exception monitor was notified of. Mainly use for debugging/test failure reporting purposes.

Overrides:
toString in class Object
Returns:
A string containing a dump of the stack traces of all exceptions.

getStackTrace

public static String getStackTrace(Throwable t)
Prints an exception stack trace into a string.

Parameters:
t - The throwable to get the stack trace from.
Returns:
A string containing the throwables stack trace.


Licensed to the Apache Software Foundation