Class ThrowableSubject

  • Direct Known Subclasses:
    TruthFailureSubject

    public class ThrowableSubject
    extends Subject
    A subject for Throwable values.

    Truth does not provide its own support for calling a method and automatically catching an expected exception, only for asserting on the exception after it has been caught. To catch the exception, we suggest assertThrows (JUnit), assertFailsWith (kotlin.test), or similar functionality from your testing library of choice.

     InvocationTargetException expected =
         assertThrows(InvocationTargetException.class, () -> method.invoke(null));
     assertThat(expected).hasCauseThat().isInstanceOf(IOException.class);
     
    • Constructor Detail

      • ThrowableSubject

        protected ThrowableSubject​(FailureMetadata metadata,
                                   @Nullable Throwable actual)
        The constructor is for use by subclasses only. If you want to create an instance of this class itself, call check(...).that(actual).