I'm trying to mock some mongo classes, so I don't need a connection (pretty standard stuff), but the following code gives me problems:
when(dbCollection.find(isA(DBObject.class))).thenReturn(dbCursor);
Running this me:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matches!
0 return matches, 1 record:
at ... GridFileManagerTest.beforeClass (GridFileManagerTest.java:67)
This exception may occur if the match is combined with raw values:
// false: someMethod (anyObject (), "raw String");
When using matches, all arguments must be provided by contests.
For instance:
// right:
someMethod (anyObject (), eq ("String by matcher"));
For more information, see javadoc for the Matchers class.
If I did this though:
when(dbCollection.find(mock(DBObject.class))).thenReturn(dbCursor);
he no longer has this problem. This is not like what I want - I want to return a value when the method is called with an object of type DBObject.
Thoughts?
source share