Interface FailureStrategy


public interface FailureStrategy
Defines what to do when a check fails.

This type does not appear directly in a fluent assertion chain, but you choose a FailureStrategy by choosing which method to call at the beginning of the chain.

Built-in strategies include:

For more information about the fluent chain, see this FAQ entry.

For people extending Truth

Custom FailureStrategy implementations 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 existing FailureStrategy and 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 FailureStrategy instance to users, expose a StandardSubjectBuilder instance using StandardSubjectBuilder.forCustomFailureStrategy(STRATEGY).

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Handles a failure.