Stephan Stephan - 1 year ago 350
Java Question

Mockito: Match any String except one

How can I write a matcher using Mockito that matches any string except a specific one?

I have tried using some hamcrest matchers to negate and combine other matchers, but the hamcrest matchers all return values of type

which dont work very well with Mockito matchers.

Answer Source

The solution I used:


Where argThat is a Mockito matcher,
and not is a Hamcrest Matcher

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download