完善 AdminUserServiceImpl 的单元测试

This commit is contained in:
YunaiV 2023-02-28 00:17:02 +08:00
parent 6c9ef97122
commit be465d758b
2 changed files with 4 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import cn.iocoder.yudao.module.system.service.dept.DeptService;
import cn.iocoder.yudao.module.system.service.dept.PostService;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@ -75,6 +76,7 @@ public class AdminUserServiceImpl implements AdminUserService {
private FileApi fileApi;
@Override
@DSTransactional // 多租户多 DB 场景使用 @DSTransactional 实现事务避免 @Transactional 无法切换数据源
public Long createUser(UserCreateReqVO reqVO) {
// 校验账户配合
tenantService.handleTenantInfo(tenant -> {

View File

@ -345,7 +345,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
reqVO.setDeptId(1L); // 其中1L 2L 的父部门
// mock 方法
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
when(deptService.getChildDeptIdListFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList);
when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList);
// 调用
PageResult<AdminUserDO> pageResult = userService.getUserPage(reqVO);
@ -368,7 +368,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
reqVO.setDeptId(1L); // 其中1L 2L 的父部门
// mock 方法
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
when(deptService.getChildDeptIdListFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList);
when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList);
// 调用
List<AdminUserDO> list = userService.getUserList(reqVO);