hamcrest / JavaHamcrest

Java (and original) version of Hamcrest

Home Page:http://hamcrest.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

rjmunro opened this issue · 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)
);