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 */ 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?
Here's how I handle exceptions in unit tests: If you aren't explicitly testing for the exception then you should add a throws clause to the method - if the exception was thrown and you weren't expecting it to be thrown then that's a test fail.
EasyMock can ensure whether a mock is being used or not. It is done using the verify() method.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With