I have written a custom Hamcrest Matcher<Double>
to use with Mockito.doubleThat
.
I want to "override the toString()
" method, so to speak, so that if there's a failure, the error is more verbose. Here's the JUnit failure trace:
Argument(s) are different! Wanted:
dependedOnComponent.method(
<Double matcher>
);
-> at my.domain.TestClass.testMethod(TestClass.java:123)
Actual invocation has different arguments:
dependedOnComponent.method(
123.45,
);
-> at my.domain.SystemUnderTest.callingMethod(SystemUnderTest.java:456)
As you can see, it prints <Double matcher>
. Is it possible to override that message? Instead, I would like to see, as an example:
Argument(s) are different! Wanted:
dependedOnComponent.method(
120 < matcher < 121
);
But a different instantiantion of my matcher class might be:
Argument(s) are different! Wanted:
dependedOnComponent.method(
1 < matcher < 200
);
I don't need to know how to write the code to generate the numbers or the syntax, I just need to know WHERE to put it.