ListmockList = EasyMock.createMock(List.class); expect(mockList.get(0)).andReturn("Hello"); replay(mockList); String result = mockList.get(0); assertEquals("Hello", result); verify(mockList);
Calculator mockCalculator = EasyMock.createMock(Calculator.class); expect(mockCalculator.add(2, 3)).andReturn(5); replay(mockCalculator); int result = mockCalculator.add(2, 3); assertEquals(5, result); verify(mockCalculator);In this example, we create a mock object of a Calculator class that has an add method. We set an expectation that the add method will be called with the arguments 2 and 3 and will return the integer 5. We then replay the mock object and invoke its add method with the same arguments, storing the result in a variable named result. Finally, we assert that the result is equal to 5 using the assertEquals method. Overall, EasyMock's assertEquals method is a useful tool for testing Java applications that use mock objects. It is a part of the org.easymock package library in Java.