Export to GitHub

mockito - issue #355

When using matchers, all arguments have to be provided by matchers.


Posted on Jul 16, 2012 by Massive Rabbit

What steps will reproduce the problem? 1. Writing when clause in such a way
Mockito.when(srv.doSth(new Date(),Mockito.any(Date.class),Mockito.any(String.class))).thenReturn(5);

What is the expected output? What do you see instead? I expect that such a call ends up without exception. Let's suppose that i would like to test my srv#doSth method in a case that first parameter is concrete instance of Date or something, and I do not care about other parameters.

I get such an error instead... org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 3 matchers expected, 2 recorded. This exception may occur if matchers are combined with raw values: //incorrect: someMethod(anyObject(), "raw String"); When using matchers, all arguments have to be provided by matchers. For example: //correct: someMethod(anyObject(), eq("String by matcher"));

For more info see javadoc for Matchers class. at com.blogspot.codeblocker.mockito.MockitoExampleTest.testMockitoAny(MockitoExampleTest.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

What version of the product are you using? On what operating system? I'm using mockito-all-1.9.0 on windows system (if the last information is important)

Please provide any additional information below. no additional information

Comment #1

Posted on Jul 17, 2012 by Happy Horse

Not a defect but a limitation of how things work. As said by the expressive exception message: either you don't use matchers at all, or you must use matchers for all arguments placeholders.

Comment #2

Posted on Jul 17, 2012 by Massive Rabbit

This limitation is in some kind a defect. Please try to improve described behaviour in future versions.

Comment #3

Posted on Jul 17, 2012 by Happy Horse

Hi,

I understand this is bulky to force using eq on a real instance, but there is no otherway that we know of to work with matchers.

Cheers, Brice

Comment #4

Posted on Dec 2, 2012 by Happy Horse

(No comment was entered for this change.)

Status: WontFix

Labels:
Type-Defect Priority-Medium Matchers