import static org.junit.Assert.assertEquals; import org.easymock.EasyMock; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.internal.runners.JUnit4ClassRunner; import org.junit.runner.RunWith; import org.unitils.easymock.EasyMockUnitils; @RunWith(JUnit4ClassRunner.class) public class HelloworldTest { private HelloworldInterface mockHelloWorld; @Before public void setUp() throws Exception { mockHelloWorld = EasyMockUnitils.createMock(HelloworldInterface.class); } @After public void tearDown() throws Exception { //A clear or reset should happen here ! } @Test public void testSayHello() { EasyMock.expect(mockHelloWorld.sayHello()).andReturn("Hello world !"); EasyMockUnitils.replay(); assertEquals("Hello world !", mockHelloWorld.sayHello()); EasyMockUnitils.verify(); } @Test public void testSayGoodbye() { EasyMock.expect(mockHelloWorld.sayHello()).andReturn("Bye bye world !"); EasyMockUnitils.replay();//The second replay throws an exception ! assertEquals("Bye bye world !", mockHelloWorld.sayHello()); EasyMockUnitils.verify(); } }