Class Throwables


  • public class Throwables
    extends java.lang.Object
    Reusable assertions for Throwables.
    • Constructor Detail

      • Throwables

        Throwables()
    • 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.
      • assertHasCause

        public void assertHasCause​(AssertionInfo info,
                                   java.lang.Throwable actual,
                                   java.lang.Throwable expectedCause)
      • 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.
      • assertHasStackTraceContaining

        public void assertHasStackTraceContaining​(AssertionInfo info,
                                                  java.lang.Throwable actual,
                                                  java.lang.String description)
        Asserts that the stack trace 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 stack trace.
        Throws:
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the stack trace of the actual Throwable does not contain the given description.
      • assertHasMessageMatching

        public void assertHasMessageMatching​(AssertionInfo info,
                                             java.lang.Throwable actual,
                                             java.lang.String regex)
        Asserts that the message of the actual Throwable matches with the given regular expression.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        regex - the regular expression of value expected to be matched 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 match the given regular expression.
        java.lang.NullPointerException - if the regex is null
      • 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.
      • assertHasCauseInstanceOf

        public void assertHasCauseInstanceOf​(AssertionInfo info,
                                             java.lang.Throwable actual,
                                             java.lang.Class<? extends java.lang.Throwable> type)
        Assert that the cause of actual Throwable is an instance of the given type.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        type - the expected cause type.
        Throws:
        java.lang.NullPointerException - if given type is null.
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the actual Throwable has no cause.
        java.lang.AssertionError - if the cause of the actual Throwable is not an instance of the given type.
      • assertHasCauseExactlyInstanceOf

        public void assertHasCauseExactlyInstanceOf​(AssertionInfo info,
                                                    java.lang.Throwable actual,
                                                    java.lang.Class<? extends java.lang.Throwable> type)
        Assert that the cause of actual Throwable is exactly an instance of the given type.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        type - the expected cause type.
        Throws:
        java.lang.NullPointerException - if given type is null.
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the actual Throwable has no cause.
        java.lang.AssertionError - if the cause of the actual Throwable is not exactly an instance of the given type.
      • assertHasRootCauseInstanceOf

        public void assertHasRootCauseInstanceOf​(AssertionInfo info,
                                                 java.lang.Throwable actual,
                                                 java.lang.Class<? extends java.lang.Throwable> type)
        Assert that the root cause of actual Throwable is an instance of the given type.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        type - the expected cause type.
        Throws:
        java.lang.NullPointerException - if given type is null.
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the actual Throwable has no cause.
        java.lang.AssertionError - if the cause of the actual Throwable is not an instance of the given type.
      • assertHasRootCauseExactlyInstanceOf

        public void assertHasRootCauseExactlyInstanceOf​(AssertionInfo info,
                                                        java.lang.Throwable actual,
                                                        java.lang.Class<? extends java.lang.Throwable> type)
        Assert that the root cause of actual Throwable is exactly an instance of the given type.
        Parameters:
        info - contains information about the assertion.
        actual - the given Throwable.
        type - the expected cause type.
        Throws:
        java.lang.NullPointerException - if given type is null.
        java.lang.AssertionError - if the actual Throwable is null.
        java.lang.AssertionError - if the actual Throwable has no cause.
        java.lang.AssertionError - if the root cause of the actual Throwable is not exactly an instance of the given type.
      • assertHasNoSuppressedExceptions

        public void assertHasNoSuppressedExceptions​(AssertionInfo info,
                                                    java.lang.Throwable actual)
      • assertHasSuppressedException

        public void assertHasSuppressedException​(AssertionInfo info,
                                                 java.lang.Throwable actual,
                                                 java.lang.Throwable expectedSuppressedException)
      • assertNotNull

        private static void assertNotNull​(AssertionInfo info,
                                          java.lang.Throwable actual)
      • compareThrowable

        private static boolean compareThrowable​(java.lang.Throwable actual,
                                                java.lang.Throwable expected)