Previous comments have caused that and accepts only two arguments, and that an option that takes three or more will be beneficial. The following code solves this recursively, allowing you to specify multiple patterns in varargs:
public static String conjunction(String... matchers) { if (matchers.length < 2) { throw new IllegalArgumentException("matchers.length must be >= 2"); } else if (matchers.length == 2) { return and(matchers[0], matchers[1]); } else { final String[] tail = new String[matchers.length - 1]; System.arraycopy(matchers, 1, tail, 0, tail.length); return and(matchers[0], conjunction(tail)); } }
subject to the following imports:
import static org.mockito.AdditionalMatchers.*; import static org.mockito.Mockito.*;
Emil koutanov
source share