Does the limitation on mocking final methods also apply to methods that have a final argument?I am not sure yet this is my problem but I encountered public T findById(final ID id) and got an exception on the when().thenReturn()org.mockito.exceptions.misusing.InvalidUseOfMatchersException:Misplaced argument matcher detected here:-> at com.cloud.network.CreatePrivateNetworkTest.setup(CreatePrivateNetworkTest.java:127)You cannot use argument matchers outside of verification or stubbing.Examples of correct usage of argument matchers:when(mock.get(anyInt())).thenReturn(null);doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());verify(mock).someMethod(contains("foo"))Also, this error might show up because you use argument matchers with methods that cannot be mocked.Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().at com.cloud.network.CreatePrivateNetworkTest.setup(CreatePrivateNetworkTest.java:127)...hi btw, nice to meet you all,Daan Hoogland--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Otherwise you should show us a snippet of your code, as Eric suggested.
They do not actually return nulls. This is a trimmed version. The point is that the first one works, and the second doesn't. The original test has 7 dependencies to a class that is being tested. Only last the three from my example don't work.
Is the doReturn-construct preferable over a thenReturn?
You received this message because you are subscribed to a topic in the Google Groups "mockito" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mockito/Ul9yMcZqnKY/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mockito+u...@googlegroups.com.
Ok, thanks for the explanation. I actually replaced mocks with spies as my test wasn't working. I'll experiment some more and let you know.
One more question: is it possible to reinit mockito e.g. remove the when behaviour in the teardown/@after method?