I’m trying to setup mocks for mongodb in my java code, and I’m getting the following exception:
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
DBCursor$$EnhancerByMockitoWithCGLIB$$fc4f0e22 cannot be returned by getOptions()
getOptions() should return int
The line of code that generates this is:
when(col.find(query)).thenReturn(cursor);
Where col is a mocked DBCollection, query is a mocked DBObject, and cursor is a mocked DBCursor.
I’ve found the following very vague but probably relevant problem description:
Just found the issue, the find(DBObject obj) method is final in DBCollection:
http://grepcode.com/file/repo1.maven.org/maven2/org.mongodb/mongo-java-driver/2.1/com/mongodb/DBCollection.java
PowerMock ultimately solved my issue since it allows mocking final methods.