Mockito MybatisPlus baseMapper:can not find lambda cache for this property
夜深静悄悄 2020-01-14 02:05:31 背景:使用了MybatisPlus,在对service层进行单元测试时,为保证数据与应用隔离,采用Mock的方式.
问题:Mockito对Mapper进行mock后,相关的TableInfo信息无法初始化,导致Wrapper组装条件时
报:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [****] of entity [Entity]
分析:排错时发现LambdaUtils.getColumnMap(aClass)中无数据;
原因:首先是MybatisPlus的bug,经过分析后排除,再次考虑TableInfo的初始化过程被中止,或者被Mock替换了,更有可能是压根就没有触发(没有具体研究过测试框架的,无法给出结果,但是不影响解决问题)
方案:解决的方案是手动触发相关缓存信息收集(或许还有更优雅的方案)
方式:在执行目标方法之前添加TableInfoHelper.initTableInfo(null, Xxx.class);