Class ThrowableAnticipator


  • public class ThrowableAnticipator
    extends org.junit.Assert

    ThrowableAnticipator class.

    Version:
    $Id: $
    Author:
    ranger
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String IGNORE_MESSAGE
      Constant IGNORE_MESSAGE="*** ThrowableAnticipator ignore Throwab"{trunked}
    • Constructor Summary

      Constructors 
      Constructor Description
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 org.junit.Assert

        assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
    • Field Detail

      • IGNORE_MESSAGE

        public static final String IGNORE_MESSAGE
        Constant IGNORE_MESSAGE="*** ThrowableAnticipator ignore Throwab"{trunked}
        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.