2 Minutes To Code (β Version)

Easymock - 2 minute tutorial

How to verify mocked object after basic use

Besides defining mock behaviour, Easymock allows us to check whether the stubbed methods were called as expected or not by using the method verify(...) of class org.easymock.EasyMock.

This is shown in the example below.
package com.techfundaes.easymockBag;

import static org.easymock.EasyMock.*;

import java.util.List;

public class VerifySimple
{
	public static void main(String[] args)
	{
		List myList = createMock(List.class);
		
		expect(myList.get(0)).andReturn("abc");
		
		replay(myList);
		
		myList.get(0);
		
		verify(myList);
	}
}