我正在尝试在我的java代码中为mongodb设置模拟,我得到以下异常:org.mockito.exceptions.misusing.WrongTypeOfReturnValue:DBCursor$$EnhancerByMockitoWithCGLIB$$fc4f0e22 cannot be returned by getOptions()ge...
我正在尝试在我的java代码中为mongodb设置模拟,我得到以下异常:
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
DBCursor$$EnhancerByMockitoWithCGLIB$$fc4f0e22 cannot be returned by getOptions()
getOptions() should return int
生成它的代码行是:
when(col.find(query)).thenReturn(cursor);
其中col是模拟的DBCollection,查询是模拟的DBObject,而游标是模拟的DBCursor.
我发现以下非常模糊但可能相关的问题描述:
http://osdir.com/ml/mongodb-user/2010-08/msg02102.html
解决方法:
刚发现问题,find(DBObject obj)方法在DBCollection中是最终的:
http://grepcode.com/file/repo1.maven.org/maven2/org.mongodb/mongo-java-driver/2.1/com/mongodb/DBCollection.java
PowerMock最终解决了我的问题,因为它允许模拟最终方法.
本文标题为:java – mongodb mockito不能一起工作?
基础教程推荐
- java多线程-内存模型 2023-09-01
- java 中Spring task定时任务的深入理解 2023-07-31
- Java设计模式之组合模式 2023-06-01
- java性能优化四种常见垃圾收集器汇总 2023-02-26
- Java Redis Redisson配置教程详解 2023-03-30
- java根据负载自动抓取jstack dump详情 2023-06-01
- 在Java中轻松使用工厂设计模式介绍 2023-05-13
- java控制台实现学生信息管理系统 2022-11-03
- JSP实现简单人事管理系统 2023-07-31
- Spring Cloud详解实现声明式微服务调用OpenFeign方法 2023-03-06
