import org.easymock.EasyMock; import org.easymock.EasyMockSupport; public class ExampleTest { private EasyMockSupport mockSupport; @Before public void setUp() { mockSupport = new EasyMockSupport(); } @Test public void testMockObject() { // Create a mock object for the class Foo Foo fooMock = mockSupport.createMock(Foo.class); // Define behavior for the mock object EasyMock.expect(fooMock.methodA()).andReturn("Mocked"); // Replay the mock object mockSupport.replayAll(); // Call the mocked method String result = fooMock.methodA(); // Verify that the mock object was called mockSupport.verifyAll(); // Check the result assertEquals("Mocked", result); } }
import org.easymock.EasyMock; import org.easymock.EasyMockSupport; public class ExampleTest { private EasyMockSupport mockSupport; @Before public void setUp() { mockSupport = new EasyMockSupport(); } @Test public void testMockObject() { // Create a mock object for the interface Bar Bar barMock = mockSupport.createMock(Bar.class); // Define behavior for the mock object EasyMock.expect(barMock.methodB()).andReturn("Mocked"); // Replay the mock object mockSupport.replayAll(); // Call the mocked method String result = barMock.methodB(); // Verify that the mock object was called mockSupport.verifyAll(); // Check the result assertEquals("Mocked", result); } }This code creates a mock object for the interface Bar and defines behavior using EasyMock.expect(). It then calls the mocked method and verifies that the mock object was called using mockSupport.verifyAll(). Overall, org.easymock is a useful package for creating mock objects in Java for testing purposes.