mybatisplus常用方法mock失败
itxiaobai123 opened this issue · 2 comments
itxiaobai123 commented
mybatisplus的BaseMapper中selectOne方法mock失败而delete却mock成功?有大佬知道这是为什么吗
xqzw123 commented
mock同样遇到byId失败,但byIds成功。
`public interface Repository<AGGREGATE, ID extends Serializable>{
/**
* 按id查找
*
* @param id
* @return
*/
AGGREGATE byId(ID id);
/**
* 按id查找集合
*
* @param ids
* @return
*/
List<AGGREGATE> byIds(List<ID> ids);
}
public interface TaskRepository extends Repository<TaskDto,Long>{
}
@repository
public class TaskRepositoryImpl implements TaskRepository {
@OverRide
public TaskDto byId(Long id) {
return taskMapping.targetToSource(taskInfoDao.selectById(id));
}
@Override
public List<TaskDto> byIds(List<Long> ids) {
final List<TaskEntity> list = new LambdaQueryChainWrapper<>(taskInfoDao).in(TaskEntity::getId, ids).list();
return taskMapping.targetToSource(list);
}
}`
xqzw123 commented
解决了,Mock方法写的不对导致。
正确写法如下
@MockInvoke(targetClass = TaskRepository.class,targetMethod = "byId")
public AGGREGATE byId(Serializable id){
TaskDto taskDto = easyRandom.nextObject(TaskDto.class);
return (AGGREGATE)taskDto;
}