2 Minutes To Code (β Version)

Mockito - 2 minute tutorial

Verify stubbed method - Frequency

Mockito provides api to verify whetehr the stubbed methods were called a given number of time, at least n times , at most n times etc using methods times(...), never(), atLeast(), atMost() of class org.mockito.Mockito as shown below.
package com.techfundaes.mockitoBag;

import static org.mockito.Mockito.*;
import java.util.List;

public class VerfifyMethodCallCount
{
    public static void main(String[] args)
    {		
		List myMockedList = mock(List.class);
		myMockedList.clear();
		myMockedList.get(0);
		myMockedList.get(1);
		myMockedList.add("a");
		myMockedList.add("b");
		myMockedList.add("c");
		verify(myMockedList).clear();
		verify(myMockedList, times(1)).clear();
		verify(myMockedList, times(2)).get(anyInt());
		verify(myMockedList, times(3)).add(anyObject());
		verify(myMockedList, never()).remove(anyObject());
		verify(myMockedList, atLeast(2)).add(anyObject());
		verify(myMockedList, atMost(1)).clear();
	}
}