You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once you call fail(), don't do anything else. If someone is using expect() (or some custom FailureStrategy that logs failures -- I think Google has at least one), fail() won't throw, so execution will continue.
This could result in multiple separate failure reports ("size is different," "missing element a," "missing element b"). (Sometimes that could be a good thing, but if it's a good thing, then we should do it for assert(), too, by putting everything in one fail() call!)
Worse, it could result in exceptions: If we fail() if the sizes of two collections differ but then continue to iterate over them in parallel, we're likely to throw NoSuchElementException. This defeats the purpose of expect() and might(?) obscure the real error.
We could maybe "solve" the former problem by wrapping the FailureStrategy in some kind of failOnlyTheFirstTimeStrategy, but this doesn't help with the second problem.
Related question: What happens with expect() and chained assertions like containsExactly().inOrder()? I guess that we need to return the "inOrder() always succeeds" object, which we should maybe stop calling IN_ORDER and documenting as though it means that. It's possible that the failOnlyTheFirstTimeStrategy approach could be useful here, but I'm wary of it.
We have some docs internally. Other things for us to cover:
AssertionErrordirectly: Callthis.fail():fail()generates the appropriate type of failure (e.g.,AssumptionViolatedExceptionwhen someone usesassume().fail()uses the user's failure message and subject name.fail()has message to disambiguate objects with the sametoString()but different classes.fail()comes in overloads that help you construct the message.assertThat(...): Delegate tocheck().that(...). (But note bug Do calls to Subject.check() lose the failureMessage? #199.) This preserves thefailureStrategy.fail(), don't do anything else. If someone is usingexpect()(or some customFailureStrategythat logs failures -- I think Google has at least one),fail()won't throw, so execution will continue.assert(), too, by putting everything in onefail()call!)fail()if the sizes of two collections differ but then continue to iterate over them in parallel, we're likely to throwNoSuchElementException. This defeats the purpose ofexpect()and might(?) obscure the real error.FailureStrategyin some kind offailOnlyTheFirstTimeStrategy, but this doesn't help with the second problem.expect()and chained assertions likecontainsExactly().inOrder()? I guess that we need to return the "inOrder()always succeeds" object, which we should maybe stop callingIN_ORDERand documenting as though it means that. It's possible that thefailOnlyTheFirstTimeStrategyapproach could be useful here, but I'm wary of it.failComparing()when substring/subsequence matches are helpful to highlight.named()(issue Consider removing self type <S> from Subject #202), we should document that.]