/** * Begins a new call chain that ignores any failures. This is useful for subjects that normally * delegate with to other subjects by using {@link #check} but have already reported a failure. In * such cases it may still be necessary to return a {@code Subject} instance even though any * subsequent assertions are meaningless. For example, if a user chains together more {@link * ThrowableSubject#hasCauseThat} calls than the actual exception has causes, {@code hasCauseThat} * returns {@code ignoreCheck().that(... a dummy exception ...)}. */ protected final StandardSubjectBuilder ignoreCheck() { return StandardSubjectBuilder.forCustomFailureStrategy(IGNORE_STRATEGY); }
/** * Returns a test verb that expects the chained assertion to fail, and makes the failure available * via {@link #getFailure}. * * <p>An instance of {@code ExpectFailure} supports only one {@code whenTesting} call per test * method. The static {@link #expectFailure} method, by contrast, does not have this limitation. */ public StandardSubjectBuilder whenTesting() { checkState(inRuleContext, "ExpectFailure must be used as a JUnit @Rule"); if (failure != null) { throw SimpleAssertionError.create("ExpectFailure already captured a failure", failure); } if (failureExpected) { throw new AssertionError( "ExpectFailure.whenTesting() called previously, but did not capture a failure."); } failureExpected = true; return StandardSubjectBuilder.forCustomFailureStrategy(strategy); }