ripper234 ripper234 - 1 year ago 121
Java Question

Using Mockito's generic "any()" method

I have an interface with a method that expects an array of Foo:

public interface IBar {
void DoStuff(Foo[] arr);

I am mocking this interface using Mockito, and I'd like to assert that DoStuff() is called, but I don't want to validate what argument are passed - "don't care".

How do I write the following code using any(), the generic method, instead of anyObject()?

IBar bar = mock(IBar.class);

Answer Source

This should work

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;

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