public class ATest { private B mockB; private A a; @Before public void setUp() { mockB = EasyMock.createMock(B.class); a = new A(mockB); } @Test public void testMethod() { EasyMock.expect(mockB.someMethod()).andReturn(42); EasyMock.replay(mockB); int result = a.methodUnderTest(); assertEquals(42, result); EasyMock.verify(mockB); } }In this example, ATest sets up a mock of B and passes it to an instance of A in the setUp() method. Then, in the testMethod() test case, we use EasyMock's expect() method to define what result B's someMethod() method should return when called. We follow that up with EasyMock's replay() method, which tells the mock to start recording method calls. Finally, we call the methodUnderTest() method of A, which internally calls someMethod() of the mocked B. Afterward, we verify that the mock was called as expected using the verify() method of EasyMock. Overall, using EasyMock allows us to isolate our tests from external dependencies, thus making them more reliable and easier to maintain.