Package com.google.common.truth
Interface FailureStrategy
-
public interface FailureStrategyDefines what to do when a check fails.This type does not appear directly in a fluent assertion chain, but you choose a
FailureStrategyby choosing which method to call at the beginning of the chain.Built-in strategies include:
- assertions
- expectations
- assumptions
- (and some useful only to people who implement custom subjects, described below)
For more information about the fluent chain, see this FAQ entry.
For people extending Truth
Custom
FailureStrategyimplementations are unusual. If you think you need one, consider these alternatives:- To test a custom subject, use
ExpectFailure. - To create subjects for other objects related to your actual value (for chained assertions),
use
Subject.check(String, Object...), which preserves the existingFailureStrategyand other context. - To return a no-op subject after a previous assertion has failed (for chained assertions),
use
Subject.ignoreCheck()
When you really do need to create your own strategy, rather than expose your
FailureStrategyinstance to users, expose aStandardSubjectBuilderinstance usingStandardSubjectBuilder.forCustomFailureStrategy(STRATEGY).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidfail(AssertionError failure)Handles a failure.
-
-
-
Method Detail
-
fail
void fail(AssertionError failure)
Handles a failure. The parameter is anAssertionErroror subclass thereof, and it contains information about the failure, which may include:- message:
getMessage() - cause:
getCause() - actual and expected values:
ComparisonFailure.getActual(),ComparisonFailure.getExpected() - stack trace:
Throwable.getStackTrace()
We encourage implementations to record as much of this information as practical in the exceptions they may throw or the other records they may make.
- message:
-
-