Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

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);

...

verify(bar).doStuff((Foo[]) anyObject());

1 Answer

0 votes
by (46k points)

This should work

import static org.mockito.ArgumentMatchers.any;

import static org.mockito.Mockito.verify;

verify(bar).DoStuff(any(Foo[].class));

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 30, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

Browse Categories

...