开发者

Expecting anything as parameter to mock using EasyMock

Using EasyMock I want to be able to say that I expect a specific method called on my mock, but I do not care about the parameter which are used to call the mock.

SomeInterface mock = EasyMock.createMock(SomeInterface.class);
mock.send(/*anything*/);
replay(mock);

/* Perform actions that will eventually invoke mock */
开发者_StackOverflow社区
verify(mock);

Is this possible, and how?

Additionally if I want to accept any object that derives from a specific base class, how do I specify that?


To accept any object as parameter:

mock.send(anyObject());

(You may need to cast the expression to the desired type.)

In addition, to accept any object of a specific type, use:

mock.send(isA(SomeObject.class));


Additionally if I want to accept any object that derives from a specific base class, how do I specify that?

mock.send(anyObject(Myclass.class));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜