Class NotThrownAssert

    • Constructor Detail

      • NotThrownAssert

        public NotThrownAssert()
    • Method Detail

      • isThrownBy

        public void isThrownBy​(ThrowableAssert.ThrowingCallable code)
        Assert that no exception of any type is thrown by the throwingCallable.

        Example:

        assertThatNoException().isThrownBy(() -> { System.out.println("OK"); });
        Parameters:
        code - code not throwing any exception
        Throws:
        AssertionError - if the actual statement raised a Throwable.
      • describedAs

        public NotThrownAssert 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<NotThrownAssert>
        Parameters:
        description - the new description to set.
        Returns:
        this object.