How to combine multiple Mockito matchers with a logical “and”/”or”?

This is possible using org.mockito.AdditionalMatchers:

import static org.mockito.AdditionalMatchers.and;

verify(mockClass).doSomething(
         and(Matchers.startsWith("prefix"), 
             Matchers.endsWith("suffix"));

There are also org.mockito.AdditionalMatchers.or and org.mockito.AdditionalMatchers.not.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)