0

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?

Ashkan Aryan
  • 3,504
  • 4
  • 30
  • 44

1 Answers1

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

See the javadoc for details.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • The javadoc link has been moved. See all method declarations for `aryEq` at http://easymock.org/api/org/easymock/EasyMock.html – nsane Apr 25 '16 at 05:43