I am currently trying to learn how to use easymock. I have the following code:
List list = EasyMock.createMock(List.class);
EasyMock.expect(list.size()).andReturn(0);
EasyMock.replay(list);
EasyMock.verify(list);
This, to me at least, should work — a list is initialized with nothing in it and the size should return 0. I get the following error, however:
java.lang.AssertionError:
Expectation failure on verify:
size(): expected: 1, actual: 0
I thought this was weird, so I changed the 0 in the line to a 1 and reran the test. I got the same error. Does anyone know what I’m doing wrong? Thanks in advance!
after
replayand beforeverify, you need to invoke the code that uses your mock. That code needs to call the expected method (sizein this case) and only that method. The error message means you set your mock up to expect a method call, but when you went to verify, you never called the method on the mock, which makes sense because you never used the mock.