Class ThrowableSubject
java.lang.Object
com.google.common.truth.Subject
com.google.common.truth.ThrowableSubject
- Direct Known Subclasses:
TruthFailureSubject
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);
- Author:
- Kurt Alfred Kluever
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.Factory<SubjectT extends Subject, ActualT>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ThrowableSubject
(FailureMetadata metadata, @Nullable Throwable actual) Constructor for use by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionfinal ThrowableSubject
Returns a newThrowableSubject
that supports assertions on this throwable's direct cause.final StringSubject
Returns aStringSubject
to make assertions about the throwable's message.Methods inherited from class com.google.common.truth.Subject
actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
-
Constructor Details
-
ThrowableSubject
Constructor for use by subclasses. If you want to create an instance of this class itself, callcheck(...)
.that(actual)
.
-
-
Method Details
-
hasMessageThat
Returns aStringSubject
to make assertions about the throwable's message. -
hasCauseThat
Returns a newThrowableSubject
that supports assertions on this throwable's direct cause. This method can be invoked repeatedly (e.g.assertThat(e).hasCauseThat().hasCauseThat()....
to assert on a particular indirect cause.
-