org.opennms.test
Class ThrowableAnticipator

java.lang.Object
  extended by junit.framework.Assert
      extended by org.opennms.test.ThrowableAnticipator

public class ThrowableAnticipator
extends junit.framework.Assert


Field Summary
static String IGNORE_MESSAGE
           
 
Constructor Summary
ThrowableAnticipator()
          Create a new anticipator with default failFast setting of true.
ThrowableAnticipator(boolean failFast)
          Create a new anticipator with the specified failFast setting.
 
Method Summary
 void anticipate(Throwable t)
          Anticipate a specific java.lang.Throwable.
 void fail(String message, Throwable t)
          Generate an AssertionFailedError with the specified cause.
 boolean isFailFast()
          Returns the failFast value for this anticipator.
 void reset()
          Reset the class back to its initial state as if it had just been instantiated.
 void setFailFast(boolean failFast)
          Set the failFast value for this anticipator.
 void throwableReceived(Throwable t)
          Process a received throwable.
 void verifyAnticipated()
          Perform after-test verification that all anticipated java.lang.Throwable's have been seen and that no unanticipated java.lang.Throwable's have been seen.
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IGNORE_MESSAGE

public static final String IGNORE_MESSAGE
See Also:
Constant Field Values
Constructor Detail

ThrowableAnticipator

public ThrowableAnticipator()
Create a new anticipator with default failFast setting of true.


ThrowableAnticipator

public ThrowableAnticipator(boolean failFast)
Create a new anticipator with the specified failFast setting.

Parameters:
failFast - whether unanticipated exceptions will cause an immediate junit.framework.Assert#fail(String). See #setFailFast(boolean) for details.
Method Detail

anticipate

public void anticipate(Throwable t)
Anticipate a specific java.lang.Throwable.

Parameters:
t - The java.lang.Throwable to anticipate. Both the class and the message will be matched.

throwableReceived

public void throwableReceived(Throwable t)
Process a received throwable. See #setFailFast(boolean) for the effects of the failFast setting on when errors are signaled.

Parameters:
t - The received throwable.
Throws:
junit.framework.AssertionFailedError - if failFast is set to true and an unanticipated java.lang.Throwable is received.

setFailFast

public void setFailFast(boolean failFast)
                 throws junit.framework.AssertionFailedError
Set the failFast value for this anticipator. This controls what happens when an unanticipation throwable is received #receiveThrowable(Throwable).

Parameters:
failFast - when set to true (the default), an unanticipated throwable will cause #receiveThrowable(Throwable) to call junit.framework.Assert#fail(). When set to false, the error will be delayed until #verifyAnticipated() is called.
Throws:
junit.framework.AssertionFailedError - if failFast is being changed from false to true and one or more unanticipated exceptions have been received.

isFailFast

public boolean isFailFast()
Returns the failFast value for this anticipator.

Returns:
failFast value. See #setFailFast(boolean) for details.

reset

public void reset()
Reset the class back to its initial state as if it had just been instantiated.


verifyAnticipated

public void verifyAnticipated()
                       throws junit.framework.AssertionFailedError
Perform after-test verification that all anticipated java.lang.Throwable's have been seen and that no unanticipated java.lang.Throwable's have been seen.

Throws:
junit.framework.AssertionFailedError - if one or more anticipated Throwables were not received or one or more unanticipated Throwables were received.

fail

public void fail(String message,
                 Throwable t)
          throws junit.framework.AssertionFailedError
Generate an AssertionFailedError with the specified cause.

Parameters:
message - error message
t - java.lang.Throwable that caused this error to be thrown
Throws:
junit.framework.AssertionFailedError - always thrown. Generated based on the parameters passed.


Copyright © 2009. All Rights Reserved.