开发者

EasyMock expect to call method with Collection type of parameter

I ran into problem:

expect(dao.save(collectionOfElements)).andReturn(otherCollection);

And when I replay then I call this DAO method with then I get

Unexpected method call save(someObj1, someObj2) 
save(someObj1, someObj2): expected: 1, actual: 0

someObj1 from unexpected call equals to someObj1 from expected call and elements are even in same order.

At first I solved this that way:

开发者_Python百科
expect(dao.save(isA(Collecion.class))).andReturn(otherCollection);

but now I have to test that does my service class calls dao.save with collection containing exactly 2 elements, so the isA(Collecion.class) doesn't work anymore.

How to solve this problem? Than You.


The problem may be that the first someObj1 and second someObj1 have the same toString (so appear the same) but they are not equals() == true.

I would check that the elements of the collections will be equal for your content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜