19

With JMock:

context.checking(new Expectations() {{
    // Other oneOf() will() statements ...

    oneOf(shopAccount).enter(100, with(any(String.class)));
    will(returnValue(true));

   // Other oneOf() will() statements ...
}});

The following exception will be raised during execution:

java.lang.IllegalArgumentException: not all parameters were given explicit matchers: either all parameters must be specified by matchers or all must be specified by values, you cannot mix matchers and values.

Why i cannot do this way? using with(any(Klass.class)) ?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Édipo Féderle
  • 4,169
  • 5
  • 31
  • 35

1 Answers1

23

if you use a with clause for any parameter, you must use them for all the parameters, try

oneOf(shopAccount).enter(with(equalTo(100)), with(any(String.class)));

skaffman
  • 398,947
  • 96
  • 818
  • 769
Steve Freeman
  • 2,707
  • 19
  • 14
  • 3
    Isn't it `with(equal(100))`, not `equalTo`? – Lukas Jan 28 '13 at 20:28
  • is you mean 'equals()', then that's a method on Object that returns a boolean. 'equalto()' is a static matcher method that returns a matcher. – Steve Freeman Feb 27 '13 at 16:35
  • 2
    @Lukas `org.jmock.Expectations.equal(T)` and `org.hamcrest.core.IsEqual.equalTo(T)` are defined equivalently (at least in versions jmock-2.5.1 and junit-4.8.2), so either would work. – Max Nanasy Mar 07 '13 at 01:40