Mockito - 2 minute tutorial

How to stub method to accept any argument

The previous example mocked a class with hardcoded argument. However mockito is quite powerful. You can use methods like anyInt() of class org.mockito.Mockito to set the mock objects behaviour when it is called with any integer as argument.

Also, notice the how the behaviour of method isEmpty() is mocked below.