开发者

Expecting anything as parameter to mock using EasyMock

开发者 https://www.devze.com 2023-03-31 05:08 出处:网络
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.

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

精彩评论

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