I am trying to write a custom matcher that navigates deep down the object graph to check an important property.
assertThat( writeRequest, hasRole("admin") );
When this fails I'd like to see a message like:
Expected: "admin"
but: was "read-only"
However, when the assertion fails, it prints out the toString()
on the writeRequest
which means that the information I want would be deep in the string. To make matters worse, along the object graph is a generated class which does not @Override
Object.toString()
so that you cannot even find out (without logging or breakpoints) what the actual role the user had was!
So, in Hamcrest, is there any way to customize the output that appears in the but: was
clause?