I have a method:
expect(processor.process(arg1, list));
expectLastCall().anyTImes();
Now, I need the list to contain certain values. And the problem is that the values have to be added to the list in a right order, otherwise the list won’t equal the real list. So I cannot just make a new list and add values into it, because if method process changed order of adding values into the list, the test would fail.
I tried this
List list=createMock(List.class);
expect(list.add(value1)).andReturn(true);
expect(lst.add(value2)).andReturn(true);
but he gives this exception:
java.lang.AssertionError:
Unexpected method call process(arg, [Listvalue1,Listvalue2]):
process(arg, EasyMock for interface java.util.List): expected: 1, actual: 0
Thanks a lot.
You could use
IAnswerandEasyMock.getCurrentArguments()and then manually assert the contents of the listA big drawback of using EasyMock.getCurrentArguments() is that it is not “refactor-safe” (If you change the order of the parameters it will break the test).
Hope it helps.