Class ThrowableTypeAssert<T extends java.lang.Throwable>

    • Field Detail

      • expectedThrowableType

        protected final java.lang.Class<? extends T extends java.lang.Throwable> expectedThrowableType
    • Constructor Detail

      • ThrowableTypeAssert

        public ThrowableTypeAssert​(java.lang.Class<? extends T> throwableType)
        Default constructor.
        Parameters:
        throwableType - class representing the target (expected) exception.
    • Method Detail

      • isThrownBy

        public ThrowableAssertAlternative<T> isThrownBy​(ThrowableAssert.ThrowingCallable throwingCallable)
        Assert that an exception of type T is thrown by the throwingCallable and allow to chain assertions on the thrown exception.

        Example:

         assertThatExceptionOfType(IOException.class).isThrownBy(() -> { throw new IOException("boom!"); })
                                               .withMessage("boom!"); 
        Parameters:
        throwingCallable - code throwing the exception of expected type
        Returns:
        return a ThrowableAssertAlternative.
      • checkThrowableType

        protected void checkThrowableType​(java.lang.Throwable throwable)
      • describedAs

        public ThrowableTypeAssert<T> describedAs​(Description description)
        Sets the description of the assertion that is going to be called after.

        You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.

        This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.

        Specified by:
        describedAs in interface Descriptable<T extends java.lang.Throwable>
        Parameters:
        description - the new description to set.
        Returns:
        this object.