2 Minutes To Code (β Version)

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.
package com.techfundaes.mockitoBag;

import static org.mockito.Mockito.*;

import java.util.ArrayList;
import java.util.List;

public class CustomizeMethodBehaviourAdvanced
	public static void main(String[] args)
		List myMockedList = mock(ArrayList.class);