Ashkan Aryan
Ashkan Aryan

Reputation: 3534

EasyMock Expectation with a void method and an object array as argument?

When using EasyMock to set expectations for a void method, is it possible to specify an Object array as one of the arguments for the method?

For example, if we have something like this:

Errors mockErrors = createMock(Errors.class);
...
mockErrors.rejectValue(Object[]{"5", "2"});
mockErrors.replay();

classUnderTest.someMethod();

whereby within ClassUnderTest, someMethod calls rejectValue(Object[]{"5", "2"});

However, despite the expectation being set to exactly what is being called, easy mock complains about an unexpected method call.

>     Unexpected method call rejectValue(["5", "2"]):
>         rejectValue(["5", "2"]): expected: 1, actual: 0

I presume that it's because under the hood it's relying on equals method on an Object[] and as the two are different it returns false and does not satisfy the condition.

Is there a way around it? As I'm not setting expectation using expect() I can use any()... is there a way of doing the same on a void method?

Upvotes: 0

Views: 2532

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

mockErrors.rejectValue(aryEq(new Object[] {"5", "2"}));

See the javadoc for details.

Upvotes: 6

Related Questions