mlinhard / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by mailto...@gmail.com on 16 Jul 2012 at 9:23

GoogleCodeExporter commented 9 years ago
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.

Original comment by brice.du...@gmail.com on 17 Jul 2012 at 12:16

GoogleCodeExporter commented 9 years ago
This limitation is in some kind a defect. Please try to improve described 
behaviour in future versions.

Original comment by mailto...@gmail.com on 17 Jul 2012 at 6:22

GoogleCodeExporter commented 9 years ago
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

Original comment by brice.du...@gmail.com on 17 Jul 2012 at 8:28

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 2 Dec 2012 at 10:21