From 1011de327868cf81e8c40bbee7b591dd559cb2f0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 1 Feb 2023 00:07:34 +0800 Subject: [PATCH] 完善 DeptServiceImpl 单元测试 --- yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImpl.java | 4 ++-- yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java | 6 +++--- yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java | 8 ++++---- yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java | 4 ++-- yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java | 43 ++++++++++++++++++------------------------- yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java | 60 +++++++++++++++++++++++++----------------------------------- yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java | 2 +- yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java | 4 ++-- yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java | 274 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java | 2 +- yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java | 6 +++--- 12 files changed, 412 insertions(+), 352 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImpl.java index 49bfdac..d15e1b6 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImpl.java @@ -216,7 +216,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { roleApi.validRoles(options); } else if (ObjectUtils.equalsAny(type, BpmTaskAssignRuleTypeEnum.DEPT_MEMBER.getType(), BpmTaskAssignRuleTypeEnum.DEPT_LEADER.getType())) { - deptApi.validDepts(options); + deptApi.validateDeptList(options); } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.POST.getType())) { postApi.validPosts(options); } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER.getType())) { @@ -293,7 +293,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { } private Set calculateTaskCandidateUsersByDeptLeader(BpmTaskAssignRuleDO rule) { - List depts = deptApi.getDepts(rule.getOptions()); + List depts = deptApi.getDeptList(rule.getOptions()); return convertSet(depts, DeptRespDTO::getLeaderUserId); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java index c9b456b..c3d143e 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java @@ -29,7 +29,7 @@ public interface DeptApi { * @param ids 部门编号数组 * @return 部门信息数组 */ - List getDepts(Collection ids); + List getDeptList(Collection ids); /** * 校验部门们是否有效。如下情况,视为无效: @@ -38,7 +38,7 @@ public interface DeptApi { * * @param ids 角色编号数组 */ - void validDepts(Collection ids); + void validateDeptList(Collection ids); /** * 获得指定编号的部门 Map @@ -47,7 +47,7 @@ public interface DeptApi { * @return 部门 Map */ default Map getDeptMap(Set ids) { - List list = getDepts(ids); + List list = getDeptList(ids); return CollectionUtils.convertMap(list, DeptRespDTO::getId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java index 5721030..c1676ca 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java @@ -28,14 +28,14 @@ public class DeptApiImpl implements DeptApi { } @Override - public List getDepts(Collection ids) { - List depts = deptService.getDepts(ids); + public List getDeptList(Collection ids) { + List depts = deptService.getDeptList(ids); return DeptConvert.INSTANCE.convertList03(depts); } @Override - public void validDepts(Collection ids) { - deptService.validDepts(ids); + public void validateDeptList(Collection ids) { + deptService.validateDeptList(ids); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java index 0a292e2..f60415c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java @@ -58,7 +58,7 @@ public class DeptController { @ApiOperation("获取部门列表") @PreAuthorize("@ss.hasPermission('system:dept:query')") public CommonResult> listDepts(DeptListReqVO reqVO) { - List list = deptService.getSimpleDepts(reqVO); + List list = deptService.getDeptList(reqVO); list.sort(Comparator.comparing(DeptDO::getSort)); return success(DeptConvert.INSTANCE.convertList(list)); } @@ -69,7 +69,7 @@ public class DeptController { // 获得部门列表,只要开启状态的 DeptListReqVO reqVO = new DeptListReqVO(); reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - List list = deptService.getSimpleDepts(reqVO); + List list = deptService.getDeptList(reqVO); // 排序后,返回给前端 list.sort(Comparator.comparing(DeptDO::getSort)); return success(DeptConvert.INSTANCE.convertList02(list)); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java index a6c30bc..87033d4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java @@ -52,7 +52,7 @@ public interface DeptService { * @param reqVO 筛选条件请求 VO * @return 部门列表 */ - List getSimpleDepts(DeptListReqVO reqVO); + List getDeptList(DeptListReqVO reqVO); /** * 获得所有子部门,从缓存中 @@ -61,7 +61,7 @@ public interface DeptService { * @param recursive 是否递归获取所有 * @return 子部门列表 */ - List getDeptsByParentIdFromCache(Long parentId, boolean recursive); + List getDeptListByParentIdFromCache(Long parentId, boolean recursive); /** * 获得部门信息数组 @@ -69,7 +69,21 @@ public interface DeptService { * @param ids 部门编号数组 * @return 部门信息数组 */ - List getDepts(Collection ids); + List getDeptList(Collection ids); + + /** + * 获得指定编号的部门 Map + * + * @param ids 部门编号数组 + * @return 部门 Map + */ + default Map getDeptMap(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyMap(); + } + List list = getDeptList(ids); + return CollectionUtils.convertMap(list, DeptDO::getId); + } /** * 获得部门信息 @@ -86,27 +100,6 @@ public interface DeptService { * * @param ids 角色编号数组 */ - void validDepts(Collection ids); + void validateDeptList(Collection ids); - /** - * 获得指定编号的部门列表 - * - * @param ids 部门编号数组 - * @return 部门列表 - */ - List getSimpleDepts(Collection ids); - - /** - * 获得指定编号的部门 Map - * - * @param ids 部门编号数组 - * @return 部门 Map - */ - default Map getDeptMap(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return Collections.emptyMap(); - } - List list = getSimpleDepts(ids); - return CollectionUtils.convertMap(list, DeptDO::getId); - } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index 6262eaf..24a93cd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; @@ -19,13 +17,11 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.time.LocalDateTime; import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -95,7 +91,7 @@ public class DeptServiceImpl implements DeptService { if (reqVO.getParentId() == null) { reqVO.setParentId(DeptIdEnum.ROOT.getId()); } - checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); + validateForCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); // 插入部门 DeptDO dept = DeptConvert.INSTANCE.convert(reqVO); deptMapper.insert(dept); @@ -110,7 +106,7 @@ public class DeptServiceImpl implements DeptService { if (reqVO.getParentId() == null) { reqVO.setParentId(DeptIdEnum.ROOT.getId()); } - checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); + validateForCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); // 更新部门 DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO); deptMapper.updateById(updateObj); @@ -121,10 +117,10 @@ public class DeptServiceImpl implements DeptService { @Override public void deleteDept(Long id) { // 校验是否存在 - checkDeptExists(id); + validateDeptExists(id); // 校验是否有子部门 if (deptMapper.selectCountByParentId(id) > 0) { - throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN); + throw exception(DEPT_EXITS_CHILDREN); } // 删除部门 deptMapper.deleteById(id); @@ -133,16 +129,16 @@ public class DeptServiceImpl implements DeptService { } @Override - public List getSimpleDepts(DeptListReqVO reqVO) { + public List getDeptList(DeptListReqVO reqVO) { return deptMapper.selectList(reqVO); } @Override - public List getDeptsByParentIdFromCache(Long parentId, boolean recursive) { + public List getDeptListByParentIdFromCache(Long parentId, boolean recursive) { if (parentId == null) { return Collections.emptyList(); } - List result = new ArrayList<>(); // TODO 芋艿:待优化,新增缓存,避免每次遍历的计算 + List result = new ArrayList<>(); // 递归,简单粗暴 this.getDeptsByParentIdFromCache(result, parentId, recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次 @@ -182,65 +178,65 @@ public class DeptServiceImpl implements DeptService { recursiveCount - 1, parentDeptMap)); } - private void checkCreateOrUpdate(Long id, Long parentId, String name) { + private void validateForCreateOrUpdate(Long id, Long parentId, String name) { // 校验自己存在 - checkDeptExists(id); + validateDeptExists(id); // 校验父部门的有效性 - checkParentDeptEnable(id, parentId); + validateParentDeptEnable(id, parentId); // 校验部门名的唯一性 - checkDeptNameUnique(id, parentId, name); + validateDeptNameUnique(id, parentId, name); } - private void checkParentDeptEnable(Long id, Long parentId) { + private void validateParentDeptEnable(Long id, Long parentId) { if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) { return; } // 不能设置自己为父部门 if (parentId.equals(id)) { - throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR); + throw exception(DEPT_PARENT_ERROR); } // 父岗位不存在 DeptDO dept = deptMapper.selectById(parentId); if (dept == null) { - throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS); + throw exception(DEPT_PARENT_NOT_EXITS); } // 父部门被禁用 if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) { - throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE); + throw exception(DEPT_NOT_ENABLE); } // 父部门不能是原来的子部门 - List children = this.getDeptsByParentIdFromCache(id, true); + List children = this.getDeptListByParentIdFromCache(id, true); if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) { - throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD); + throw exception(DEPT_PARENT_IS_CHILD); } } - private void checkDeptExists(Long id) { + private void validateDeptExists(Long id) { if (id == null) { return; } DeptDO dept = deptMapper.selectById(id); if (dept == null) { - throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND); + throw exception(DEPT_NOT_FOUND); } } - private void checkDeptNameUnique(Long id, Long parentId, String name) { + private void validateDeptNameUnique(Long id, Long parentId, String name) { DeptDO menu = deptMapper.selectByParentIdAndName(parentId, name); if (menu == null) { return; } // 如果 id 为空,说明不用比较是否为相同 id 的岗位 if (id == null) { - throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE); + throw exception(DEPT_NAME_DUPLICATE); } if (!menu.getId().equals(id)) { - throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE); + throw exception(DEPT_NAME_DUPLICATE); } } @Override - public List getDepts(Collection ids) { + public List getDeptList(Collection ids) { return deptMapper.selectBatchIds(ids); } @@ -250,13 +246,12 @@ public class DeptServiceImpl implements DeptService { } @Override - public void validDepts(Collection ids) { + public void validateDeptList(Collection ids) { if (CollUtil.isEmpty(ids)) { return; } // 获得科室信息 - List depts = deptMapper.selectBatchIds(ids); - Map deptMap = CollectionUtils.convertMap(depts, DeptDO::getId); + Map deptMap = getDeptMap(ids); // 校验 ids.forEach(id -> { DeptDO dept = deptMap.get(id); @@ -269,9 +264,4 @@ public class DeptServiceImpl implements DeptService { }); } - @Override - public List getSimpleDepts(Collection ids) { - return deptMapper.selectBatchIds(ids); - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java index c40a8e3..59ab61e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java @@ -418,7 +418,7 @@ public class PermissionServiceImpl implements PermissionService { } // 情况四,DEPT_DEPT_AND_CHILD if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_AND_CHILD.getScope())) { - List depts = deptService.getDeptsByParentIdFromCache(userDeptIdCache.get(), true); + List depts = deptService.getDeptListByParentIdFromCache(userDeptIdCache.get(), true); CollUtil.addAll(result.getDeptIds(), CollectionUtils.convertList(depts, DeptDO::getId)); // 添加本身部门编号 CollUtil.addAll(result.getDeptIds(), userDeptIdCache.get()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 50c78c8..ef6f975 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -299,7 +299,7 @@ public class AdminUserServiceImpl implements AdminUserService { if (deptId == null) { return Collections.emptySet(); } - Set deptIds = convertSet(deptService.getDeptsByParentIdFromCache( + Set deptIds = convertSet(deptService.getDeptListByParentIdFromCache( deptId, true), DeptDO::getId); deptIds.add(deptId); // 包括自身 return deptIds; @@ -317,7 +317,7 @@ public class AdminUserServiceImpl implements AdminUserService { // 校验邮箱唯一 checkEmailUnique(id, email); // 校验部门处于开启状态 - deptService.validDepts(CollectionUtils.singleton(deptId)); + deptService.validateDeptList(CollectionUtils.singleton(deptId)); // 校验岗位处于开启状态 postService.validPosts(postIds); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java new file mode 100644 index 0000000..593c2cb --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java @@ -0,0 +1,351 @@ +package cn.iocoder.yudao.module.system.service.dept; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; +import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; +import cn.iocoder.yudao.module.system.enums.dept.DeptIdEnum; +import cn.iocoder.yudao.module.system.mq.producer.dept.DeptProducer; +import com.google.common.collect.Multimap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; +import static java.util.Collections.singletonList; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.verify; + +/** + * {@link DeptServiceImpl} 的单元测试类 + * + * @author niudehua + */ +@Import(DeptServiceImpl.class) +public class DeptServiceImplTest extends BaseDbUnitTest { + + @Resource + private DeptServiceImpl deptService; + @Resource + private DeptMapper deptMapper; + @MockBean + private DeptProducer deptProducer; + + @BeforeEach + public void setUp() { + // 清理租户上下文 + TenantContextHolder.clear(); + } + + @Test + public void testInitLocalCache() { + // mock 数据 + DeptDO deptDO1 = randomDeptDO(); + deptMapper.insert(deptDO1); + DeptDO deptDO2 = randomDeptDO(); + deptMapper.insert(deptDO2); + + // 调用 + deptService.initLocalCache(); + // 断言 deptCache 缓存 + Map deptCache = deptService.getDeptCache(); + assertEquals(2, deptCache.size()); + assertPojoEquals(deptDO1, deptCache.get(deptDO1.getId())); + assertPojoEquals(deptDO2, deptCache.get(deptDO2.getId())); + // 断言 parentDeptCache 缓存 + Multimap parentDeptCache = deptService.getParentDeptCache(); + assertEquals(2, parentDeptCache.size()); + assertPojoEquals(deptDO1, parentDeptCache.get(deptDO1.getParentId())); + assertPojoEquals(deptDO2, parentDeptCache.get(deptDO2.getParentId())); + } + + @Test + public void testListDepts() { + // mock 数据 + DeptDO dept = randomPojo(DeptDO.class, o -> { // 等会查询到 + o.setName("开发部"); + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); + }); + deptMapper.insert(dept); + // 测试 name 不匹配 + deptMapper.insert(ObjectUtils.cloneIgnoreId(dept, o -> o.setName("发"))); + // 测试 status 不匹配 + deptMapper.insert(ObjectUtils.cloneIgnoreId(dept, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); + // 准备参数 + DeptListReqVO reqVO = new DeptListReqVO(); + reqVO.setName("开"); + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); + + // 调用 + List sysDeptDOS = deptService.getDeptList(reqVO); + // 断言 + assertEquals(1, sysDeptDOS.size()); + assertPojoEquals(dept, sysDeptDOS.get(0)); + } + + @Test + public void testCreateDept_success() { + // 准备参数 + DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> { + o.setParentId(DeptIdEnum.ROOT.getId()); + o.setStatus(randomCommonStatus()); + }); + + // 调用 + Long deptId = deptService.createDept(reqVO); + // 断言 + assertNotNull(deptId); + // 校验记录的属性是否正确 + DeptDO deptDO = deptMapper.selectById(deptId); + assertPojoEquals(reqVO, deptDO); + // 校验调用 + verify(deptProducer).sendDeptRefreshMessage(); + } + + @Test + public void testUpdateDept_success() { + // mock 数据 + DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); + deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 + // 准备参数 + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { + // 设置更新的 ID + o.setParentId(DeptIdEnum.ROOT.getId()); + o.setId(dbDeptDO.getId()); + o.setStatus(randomCommonStatus()); + }); + + // 调用 + deptService.updateDept(reqVO); + // 校验是否更新正确 + DeptDO deptDO = deptMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, deptDO); + // 校验调用 + verify(deptProducer).sendDeptRefreshMessage(); + } + + @Test + public void testDeleteDept_success() { + // mock 数据 + DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); + deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbDeptDO.getId(); + + // 调用 + deptService.deleteDept(id); + // 校验数据不存在了 + assertNull(deptMapper.selectById(id)); + // 校验调用 + verify(deptProducer).sendDeptRefreshMessage(); + } + + @Test + public void testValidateDept_nameDuplicateForUpdate() { + // mock 数据 + DeptDO deptDO = randomDeptDO(); + // 设置根节点部门 + deptDO.setParentId(DeptIdEnum.ROOT.getId()); + deptMapper.insert(deptDO); + // mock 数据 稍后模拟重复它的 name + DeptDO nameDeptDO = randomDeptDO(); + // 设置根节点部门 + nameDeptDO.setParentId(DeptIdEnum.ROOT.getId()); + deptMapper.insert(nameDeptDO); + // 准备参数 + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { + // 设置根节点部门 + o.setParentId(DeptIdEnum.ROOT.getId()); + // 设置更新的 ID + o.setId(deptDO.getId()); + // 模拟 name 重复 + o.setName(nameDeptDO.getName()); + }); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.updateDept(reqVO), DEPT_NAME_DUPLICATE); + } + + @Test + public void testValidateDept_parentNotExitsForCreate() { + // 准备参数 + DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, + o -> o.setStatus(randomCommonStatus())); + + // 调用,并断言异常 + assertServiceException(() -> deptService.createDept(reqVO), DEPT_PARENT_NOT_EXITS); + } + + @Test + public void testValidateDept_notFoundForDelete() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.deleteDept(id), DEPT_NOT_FOUND); + } + + @Test + public void testValidateDept_exitsChildrenForDelete() { + // mock 数据 + DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); + deptMapper.insert(parentDept);// @Sql: 先插入出一条存在的数据 + // 准备参数 + DeptDO childrenDeptDO = randomPojo(DeptDO.class, o -> { + o.setParentId(parentDept.getId()); + o.setStatus(randomCommonStatus()); + }); + // 插入子部门 + deptMapper.insert(childrenDeptDO); + // 调用, 并断言异常 + assertServiceException(() -> deptService.deleteDept(parentDept.getId()), DEPT_EXITS_CHILDREN); + } + + @Test + public void testValidateDept_parentErrorForUpdate() { + // mock 数据 + DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); + deptMapper.insert(dbDeptDO); + // 准备参数 + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { + // 设置自己为父部门 + o.setParentId(dbDeptDO.getId()); + // 设置更新的 ID + o.setId(dbDeptDO.getId()); + }); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_ERROR); + } + + @Test + public void testValidateDept_notEnableForCreate() { + // mock 数据 + DeptDO deptDO = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())); + deptMapper.insert(deptDO); + // 准备参数 + DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> { + // 设置未启用的部门为父部门 + o.setParentId(deptDO.getId()); + }); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.createDept(reqVO), DEPT_NOT_ENABLE); + } + + @Test + public void testCheckDept_parentIsChildForUpdate() { + // mock 数据 + DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); + deptMapper.insert(parentDept); + DeptDO childDept = randomPojo(DeptDO.class, o -> { + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); + o.setParentId(parentDept.getId()); + }); + deptMapper.insert(childDept); + // 初始化本地缓存 + deptService.initLocalCache(); + + // 准备参数 + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { + // 设置自己的子部门为父部门 + o.setParentId(childDept.getId()); + // 设置更新的 ID + o.setId(parentDept.getId()); + }); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_IS_CHILD); + } + + @Test + public void testGetDeptList() { + // mock 数据 + DeptDO deptDO01 = randomDeptDO(); + deptMapper.insert(deptDO01); + DeptDO deptDO02 = randomDeptDO(); + deptMapper.insert(deptDO02); + // 准备参数 + List ids = Arrays.asList(deptDO01.getId(), deptDO02.getId()); + + // 调用 + List deptDOList = deptService.getDeptList(ids); + // 断言 + assertEquals(2, deptDOList.size()); + assertEquals(deptDO01, deptDOList.get(0)); + assertEquals(deptDO02, deptDOList.get(1)); + } + + @Test + public void testGetDept() { + // mock 数据 + DeptDO deptDO = randomDeptDO(); + deptMapper.insert(deptDO); + // 准备参数 + Long id = deptDO.getId(); + + // 调用 + DeptDO dbDept = deptService.getDept(id); + // 断言 + assertEquals(deptDO, dbDept); + } + + @Test + public void testValidateDeptList_success() { + // mock 数据 + DeptDO deptDO = randomDeptDO().setStatus(CommonStatusEnum.ENABLE.getStatus()); + deptMapper.insert(deptDO); + // 准备参数 + List ids = singletonList(deptDO.getId()); + + // 调用,无需断言 + deptService.validateDeptList(ids); + } + + @Test + public void testValidateDeptList_notFound() { + // 准备参数 + List ids = singletonList(randomLongId()); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.validateDeptList(ids), DEPT_NOT_FOUND); + } + + @Test + public void testValidateDeptList_notEnable() { + // mock 数据 + DeptDO deptDO = randomDeptDO().setStatus(CommonStatusEnum.DISABLE.getStatus()); + deptMapper.insert(deptDO); + // 准备参数 + List ids = singletonList(deptDO.getId()); + + // 调用, 并断言异常 + assertServiceException(() -> deptService.validateDeptList(ids), DEPT_NOT_ENABLE); + } + + @SafeVarargs + private static DeptDO randomDeptDO(Consumer... consumers) { + Consumer consumer = (o) -> { + o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 + }; + return randomPojo(DeptDO.class, ArrayUtils.append(consumer, consumers)); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java deleted file mode 100644 index 6b4ff10..0000000 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java +++ /dev/null @@ -1,274 +0,0 @@ -package cn.iocoder.yudao.module.system.service.dept; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; -import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; -import cn.iocoder.yudao.module.system.enums.dept.DeptIdEnum; -import cn.iocoder.yudao.module.system.mq.producer.dept.DeptProducer; -import com.google.common.collect.Multimap; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; - -import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * {@link DeptServiceImpl} 的单元测试类 - * - * @author niudehua - */ -@Import(DeptServiceImpl.class) -public class DeptServiceTest extends BaseDbUnitTest { - - @Resource - private DeptServiceImpl deptService; - @Resource - private DeptMapper deptMapper; - @MockBean - private DeptProducer deptProducer; - - @BeforeEach - public void setUp() { - // 清理租户上下文 - TenantContextHolder.clear(); - } - - @Test - public void testInitLocalCache() { - // mock 数据 - DeptDO deptDO1 = randomDeptDO(); - deptMapper.insert(deptDO1); - DeptDO deptDO2 = randomDeptDO(); - deptMapper.insert(deptDO2); - - // 调用 - deptService.initLocalCache(); - // 断言 deptCache 缓存 - Map deptCache = deptService.getDeptCache(); - assertEquals(2, deptCache.size()); - assertPojoEquals(deptDO1, deptCache.get(deptDO1.getId())); - assertPojoEquals(deptDO2, deptCache.get(deptDO2.getId())); - // 断言 parentDeptCache 缓存 - Multimap parentDeptCache = deptService.getParentDeptCache(); - assertEquals(2, parentDeptCache.size()); - assertPojoEquals(deptDO1, parentDeptCache.get(deptDO1.getParentId())); - assertPojoEquals(deptDO2, parentDeptCache.get(deptDO2.getParentId())); - } - - @Test - void testListDepts() { - // mock 数据 - DeptDO dept = randomPojo(DeptDO.class, o -> { // 等会查询到 - o.setName("开发部"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - }); - deptMapper.insert(dept); - // 测试 name 不匹配 - deptMapper.insert(ObjectUtils.cloneIgnoreId(dept, o -> o.setName("发"))); - // 测试 status 不匹配 - deptMapper.insert(ObjectUtils.cloneIgnoreId(dept, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 准备参数 - DeptListReqVO reqVO = new DeptListReqVO(); - reqVO.setName("开"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - // 调用 - List sysDeptDOS = deptService.getSimpleDepts(reqVO); - // 断言 - assertEquals(1, sysDeptDOS.size()); - assertPojoEquals(dept, sysDeptDOS.get(0)); - } - - @Test - void testCreateDept_success() { - // 准备参数 - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, - o -> { - o.setParentId(DeptIdEnum.ROOT.getId()); - o.setStatus(randomCommonStatus()); - }); - // 调用 - Long deptId = deptService.createDept(reqVO); - // 断言 - assertNotNull(deptId); - // 校验记录的属性是否正确 - DeptDO deptDO = deptMapper.selectById(deptId); - assertPojoEquals(reqVO, deptDO); - // 校验调用 - verify(deptProducer, times(1)).sendDeptRefreshMessage(); - } - - @Test - void testUpdateDept_success() { - // mock 数据 - DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); - deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 - // 准备参数 - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { - // 设置更新的 ID - o.setParentId(DeptIdEnum.ROOT.getId()); - o.setId(dbDeptDO.getId()); - o.setStatus(randomCommonStatus()); - }); - // 调用 - deptService.updateDept(reqVO); - // 校验是否更新正确 - DeptDO deptDO = deptMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, deptDO); - } - - @Test - void testDeleteDept_success() { - // mock 数据 - DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); - deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbDeptDO.getId(); - // 调用 - deptService.deleteDept(id); - // 校验数据不存在了 - assertNull(deptMapper.selectById(id)); - } - - @Test - void testCheckDept_nameDuplicateForUpdate() { - // mock 数据 - DeptDO deptDO = randomDeptDO(); - // 设置根节点部门 - deptDO.setParentId(DeptIdEnum.ROOT.getId()); - deptMapper.insert(deptDO); - // mock 数据 稍后模拟重复它的 name - DeptDO nameDeptDO = randomDeptDO(); - // 设置根节点部门 - nameDeptDO.setParentId(DeptIdEnum.ROOT.getId()); - deptMapper.insert(nameDeptDO); - // 准备参数 - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, - o -> { - // 设置根节点部门 - o.setParentId(DeptIdEnum.ROOT.getId()); - // 设置更新的 ID - o.setId(deptDO.getId()); - // 模拟 name 重复 - o.setName(nameDeptDO.getName()); - }); - // 调用, 并断言异常 - assertServiceException(() -> deptService.updateDept(reqVO), DEPT_NAME_DUPLICATE); - } - - @Test - void testCheckDept_parentNotExitsForCreate() { - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, - o -> o.setStatus(randomCommonStatus())); - // 调用,并断言异常 - assertServiceException(() -> deptService.createDept(reqVO), DEPT_PARENT_NOT_EXITS); - } - - @Test - void testCheckDept_notFoundForDelete() { - // 准备参数 - Long id = randomLongId(); - // 调用, 并断言异常 - assertServiceException(() -> deptService.deleteDept(id), DEPT_NOT_FOUND); - } - - @Test - void testCheckDept_exitsChildrenForDelete() { - // mock 数据 - DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); - deptMapper.insert(parentDept);// @Sql: 先插入出一条存在的数据 - // 准备参数 - DeptDO childrenDeptDO = randomPojo(DeptDO.class, o -> { - o.setParentId(parentDept.getId()); - o.setStatus(randomCommonStatus()); - }); - // 插入子部门 - deptMapper.insert(childrenDeptDO); - // 调用, 并断言异常 - assertServiceException(() -> deptService.deleteDept(parentDept.getId()), DEPT_EXITS_CHILDREN); - } - - @Test - void testCheckDept_parentErrorForUpdate() { - // mock 数据 - DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); - deptMapper.insert(dbDeptDO); - // 准备参数 - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, - o -> { - // 设置自己为父部门 - o.setParentId(dbDeptDO.getId()); - // 设置更新的 ID - o.setId(dbDeptDO.getId()); - }); - // 调用, 并断言异常 - assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_ERROR); - } - - @Test - void testCheckDept_notEnableForCreate() { - // mock 数据 - DeptDO deptDO = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())); - deptMapper.insert(deptDO); - // 准备参数 - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, - o -> { - // 设置未启用的部门为副部门 - o.setParentId(deptDO.getId()); - }); - // 调用, 并断言异常 - assertServiceException(() -> deptService.createDept(reqVO), DEPT_NOT_ENABLE); - } - - @Test - void testCheckDept_parentIsChildForUpdate() { - // mock 数据 - DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); - deptMapper.insert(parentDept); - DeptDO childDept = randomPojo(DeptDO.class, o -> { - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setParentId(parentDept.getId()); - }); - deptMapper.insert(childDept); - // 初始化本地缓存 - deptService.initLocalCache(); - // 准备参数 - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, - o -> { - // 设置自己的子部门为父部门 - o.setParentId(childDept.getId()); - // 设置更新的 ID - o.setId(parentDept.getId()); - }); - // 调用, 并断言异常 - assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_IS_CHILD); - } - - @SafeVarargs - private static DeptDO randomDeptDO(Consumer... consumers) { - Consumer consumer = (o) -> { - o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 - }; - return randomPojo(DeptDO.class, ArrayUtils.append(consumer, consumers)); - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java index afc4c0c..93e521b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceTest.java @@ -509,7 +509,7 @@ public class PermissionServiceTest extends BaseDbUnitTest { when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L), null, null); // 最后返回 null 的目的,看看会不会重复调用 // mock 方法(部门) DeptDO deptDO = randomPojo(DeptDO.class); - when(deptService.getDeptsByParentIdFromCache(eq(3L), eq(true))) + when(deptService.getDeptListByParentIdFromCache(eq(3L), eq(true))) .thenReturn(singletonList(deptDO)); // 调用 diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java index 2822789..c78efcc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java @@ -299,7 +299,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门 // mock 方法 List deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L))); - when(deptService.getDeptsByParentIdFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList); + when(deptService.getDeptListByParentIdFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList); // 调用 PageResult pageResult = userService.getUserPage(reqVO); @@ -322,7 +322,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门 // mock 方法 List deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L))); - when(deptService.getDeptsByParentIdFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList); + when(deptService.getDeptListByParentIdFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList); // 调用 List list = userService.getUsers(reqVO); @@ -366,7 +366,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { UserImportExcelVO importUser = randomPojo(UserImportExcelVO.class, o -> { }); // mock 方法,模拟失败 - doThrow(new ServiceException(DEPT_NOT_FOUND)).when(deptService).validDepts(any()); + doThrow(new ServiceException(DEPT_NOT_FOUND)).when(deptService).validateDeptList(any()); // 调用 UserImportRespVO respVO = userService.importUsers(newArrayList(importUser), true); -- libgit2 0.21.4