public static long countInvocations(Object mock, String methodName, Class<?>... parameters) {
        return mockingDetails(mock).getInvocations().stream()
                .map(InvocationOnMock::getMethod)
                .filter(m -> methodName.equals(m.getName()))
                .filter(m -> Arrays.equals(parameters, m.getParameterTypes()))
                .count();
    }
Count the number of times a method has been invoked on a mock object.
<p>
Sample usage:
<p>
<pre>
Producer<byte[], byte[]> producer = mock(Producer.class);
// ... run through some test case that uses the mocked producer
assertEquals(
    "Producer should have aborted every record it sent",
    countInvocations(producer, "abortTransaction"),
    countInvocations(producer, "send", ProducerRecord.class, Callback.class)
);
</pre>
@param mock the mock object whose method invocations should be counted; may not be null
@param methodName the name of the method whose invocations should be counted; may not be null
@param parameters the types of the parameters for the method whose invocations should be counted;
                  may be empty, but may not contain any null elements
@return the number of times the method was invoked on the mock
connect/runtime/src/test/java/org/apache/kafka/connect/test/util/MockitoUtils.java