public final class TruthFailureSubject extends ThrowableSubject
AssertionError
objects thrown by Truth. TruthFailureSubject
contains
methods for asserting about the individual "facts" of those failures. This allows tests to avoid
asserting about the same fact more often than necessary, including avoiding asserting about facts
that are set by other subjects that the main subject delegates to. This keeps tests shorter and
less fragile.
To create an instance, call ExpectFailure.assertThat(java.lang.AssertionError)
.
This class accepts any AssertionError
value, but it will throw an exception if a
caller tries to access the facts of an error that wasn't produced by Truth.
Modifier and Type | Method and Description |
---|---|
IterableSubject |
factKeys()
Returns a subject for the list of fact keys.
|
StringSubject |
factValue(String key)
Returns a subject for the value with the given name.
|
StringSubject |
factValue(String key,
int index)
Returns a subject for the value of the
index -th instance of the fact with the given
name. |
hasCauseThat, hasMessage, hasMessageThat
actual, actualAsString, actualCustomStringRepresentation, check, check, equals, fail, fail, fail, failComparing, failComparing, failWithActual, failWithActual, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutActual, failWithoutSubject, failWithRawMessage, failWithRawMessageAndCause, getSubject, hashCode, ignoreCheck, internalCustomName, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameAs, isNull, isSameAs, named, toString
public IterableSubject factKeys()
public StringSubject factValue(String key)
The value is always a string, the String.valueOf
representation of the value passed
to Fact.fact(java.lang.String, java.lang.Object)
.
The value is never null:
factValue
throws an exception. To test for such facts, use factKeys()
.contains(...)
or a similar method.
fact("key", null)
), factValue
considers them have a string value,
the string "null."
If the failure under test contains more than one fact with the given key, this method will
fail the test. To assert about such a failure, use the
other overload of factValue
.
public StringSubject factValue(String key, int index)
index
-th instance of the fact with the given
name. Most Truth failures do not contain multiple facts with the same key, so most tests should
use the other overload of factValue
.Copyright © 2018. All rights reserved.