Class ThrowableTypeAssert<T extends Throwable>

java.lang.Object
org.assertj.core.api.ThrowableTypeAssert<T>
Type Parameters:
T - type of throwable to be thrown.

public class ThrowableTypeAssert<T extends Throwable> extends Object
Assertion class checking Throwable type.

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

  • Field Details

    • expectedThrowableType

      final Class<? extends T extends Throwable> expectedThrowableType
  • Constructor Details

    • ThrowableTypeAssert

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

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