Class Throwables


  • public class Throwables
    extends java.lang.Object
    Reusable assertions for Throwables.
    Author:
    Joel Costigliola
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assertHasMessage​(AssertionInfo info, java.lang.Throwable actual, java.lang.String message)
      Asserts that the given actual Throwable message is equal to the given one.
      void assertHasMessageContaining​(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
      Asserts that the message of the actual Throwable contains with the given description.
      void assertHasMessageEndingWith​(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
      Asserts that the message of the actual Throwable ends with the given description.
      void assertHasMessageStartingWith​(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
      Asserts that the message of the actual Throwable starts with the given description.
      void assertHasNoCause​(AssertionInfo info, java.lang.Throwable actual)
      Asserts that the actual Throwable does not have a cause.
      static Throwables instance()
      Returns the singleton instance of this class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • instance

        public static Throwables instance()
        Returns the singleton instance of this class.
        Returns:
        the singleton instance of this class.
      • assertHasMessage

        public void assertHasMessage​(AssertionInfo info,
                                     java.lang.Throwable actual,
                                     java.lang.String message)
        Asserts that the given actual Throwable message is equal to the given one.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        message - the expected message.
        Throws:
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the message of the actual Throwable is not equal to the given one.
      • assertHasNoCause

        public void assertHasNoCause​(AssertionInfo info,
                                     java.lang.Throwable actual)
        Asserts that the actual Throwable does not have a cause.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        Throws:
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the actual Throwable has a cause.
      • assertHasMessageStartingWith

        public void assertHasMessageStartingWith​(AssertionInfo info,
                                                 java.lang.Throwable actual,
                                                 java.lang.String description)
        Asserts that the message of the actual Throwable starts with the given description.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        description - the description expected to start the actual Throwable's message.
        Throws:
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the message of the actual Throwable does not start with the given description.
      • assertHasMessageContaining

        public void assertHasMessageContaining​(AssertionInfo info,
                                               java.lang.Throwable actual,
                                               java.lang.String description)
        Asserts that the message of the actual Throwable contains with the given description.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        description - the description expected to be contained in the actual Throwable's message.
        Throws:
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the message of the actual Throwable does not contain the given description.
      • assertHasMessageEndingWith

        public void assertHasMessageEndingWith​(AssertionInfo info,
                                               java.lang.Throwable actual,
                                               java.lang.String description)
        Asserts that the message of the actual Throwable ends with the given description.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        description - the description expected to end the actual Throwable's message.
        Throws:
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the message of the actual Throwable does not end with the given description.