How to create a custom message from a custom Mockito ArgumentMatcher?

I write ArgumentMatcher, and the gut comparisons come down to something like:

return A.value().equals(B.value()) && A.name().equals(B.name());

Unfortunately, when this does not go away, Mokito just tells me that it did not work. I want to add a custom message, for example, "Values โ€‹โ€‹do not match" or "Names do not match" (of course, I would like to give more information, but so far I can not understand this simple case, in the future).

Before (before working with Mockito), I remember that they have two methods: one for checking compliance and one for generating an error message (although it was painful to write both methods, but now I skip the second method).

Any ideas how to do this? Any help is appreciated!

+3
source share
2

. Hamcrest "describeTo". , EasyMock. Description viola, .

+4

Mockito.description() method:

verify(writer, never().description("exception was thrown"))
  .println(any(Object.class));
0

Source: https://habr.com/ru/post/1793255/


All Articles