unit-testing - 带有替换注释的 Micronaut 模拟存储库接口
问题描述
我有一个CrudRepository类型的存储库实现。我试图用另一个扩展它的接口来模拟这个接口。
我注意到,如果我调用 findAll 方法,它会按预期工作,但是当我调用 findById 方法时,我会收到如下错误:
Micronaut Data method is missing compilation time query information. Ensure that the Micronaut Data annotation processors are declared in your build and try again with a clean re-build.
java.lang.IllegalStateException: Micronaut Data method is missing compilation time query information. Ensure that the Micronaut Data annotation processors are declared in your build and try again with a clean re-build.
at io.micronaut.data.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:97)
这个类是要模拟的类
@Repository
interface RepositoryHibernate: CrudRepository<Entity, Long>
这是被嘲笑的班级
@Replaces(RepositoryHibernate::class)
abstract class RepositoryCrudMock: RepositoryHibernate {
val elements = mutableListOf(test1, test2, test3, test4)
override fun findAll(): MutableIterable<Entity> {
return elements
}
override fun findById(id: Long): Optional<Entity> {
return when(id) {
1L -> Optional.of(test1)
2L -> Optional.of(test2)
3L -> Optional.of(test3)
4L -> Optional.of(test4)
else -> Optional.of(Entity())
}
}
}
解决方案
推荐阅读
- python - SQLALchemy AsyncSession 的 schema_translate_map
- html - 如何将文件上传到html画布?
- scala - 是否可以手动执行和转换行为
- angular - 无法以角度运行 ng serve 命令
- artificial-intelligence - 用于视频脚本生成的 GPT-NEO 培训
- javascript - 前端设计系统有资料吗?
- nginx - 配置nginx访问url中没有端口的网站
- node.js - Issue with image download using node
- javascript - 上传多个带有预览的图像并删除它们
- google-apps-script - Google Sheet Appscript - 根据另一个单元格值清除一些单元格值