JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

You should be able to specify a lambda to return a reason

Open rjmunro opened this issue 4 years ago • 0 comments

It would be good if I can specify a reason as a lambda:

That way it can be evaluated only if it fails, and it can be passed the result of the evaluation without needing to call it again.

You could then do something like:

assertThat(
  (list) -> String.format("List is not empty, last item is %s", list.get(list.size() - 1)),
  somethingThatReturnsAList(),
  hasLength(0)
);

rjmunro avatar Jan 11 '22 12:01 rjmunro