Class NotThrownAssert

java.lang.Object
org.assertj.core.api.NotThrownAssert
All Implemented Interfaces:
Descriptable<NotThrownAssert>

public class NotThrownAssert extends Object implements Descriptable<NotThrownAssert>
Assertion class checking a ThrowableAssert.ThrowingCallable throws no exception.

The class itself does not do much, it delegates the work to ThrowableAssert after calling isThrownBy(ThrowingCallable).

Since:
3.17.0
See Also:
  • Field Details

  • Constructor Details

    • NotThrownAssert

      public NotThrownAssert()
  • Method Details

    • 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.