Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mybatisplus常用方法mock失败 #300

Open
itxiaobai123 opened this issue Nov 9, 2022 · 2 comments
Open

mybatisplus常用方法mock失败 #300

itxiaobai123 opened this issue Nov 9, 2022 · 2 comments

Comments

@itxiaobai123
Copy link

mybatisplus的BaseMapper中selectOne方法mock失败而delete却mock成功?有大佬知道这是为什么吗

@xqzw123
Copy link

xqzw123 commented Nov 1, 2023

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
Copy link

xqzw123 commented Nov 1, 2023

解决了,Mock方法写的不对导致。
正确写法如下
@MockInvoke(targetClass = TaskRepository.class,targetMethod = "byId")
public AGGREGATE byId(Serializable id){
TaskDto taskDto = easyRandom.nextObject(TaskDto.class);
return (AGGREGATE)taskDto;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants