1、deptService单测完善;2、贴皮veneer service单测剥离真实db,使用纯mock;

This commit is contained in:
gaoqr
2026-01-22 11:37:22 +08:00
parent f22f3bb2ba
commit 7b919d7adb
4 changed files with 184 additions and 77 deletions
@@ -299,20 +299,18 @@ public class DeptServiceImpl implements DeptService {
* @param deptDO
*/
private void validParentDept(DeptDO deptDO) {
if (ObjectUtil.isNotNull(deptDO) && ObjectUtil.isNotNull(deptDO.getParentId())) {
Long parentId = deptDO.getParentId();
DeptDO parentDept = deptMapper.selectById(parentId);
if (ObjectUtil.equal(parentId, 0L)) {
// 上级部门id是0代表是机构下最顶级的部门
return;
}
if (parentDept == null) {
throw new ServiceException(ErrorCodeConstants.DEPT_PARENT_NOT_EXITS);
} else if (!CommonStatusEnum.ENABLE.getStatus().equals(parentDept.getStatus())) {
throw new ServiceException(ErrorCodeConstants.DEPT_DISABLE, parentDept.getName());
} else {
validParentDept(parentDept);
}
Long parentId = deptDO.getParentId();
DeptDO parentDept = deptMapper.selectById(parentId);
if (ObjectUtil.equal(parentId, 0L)) {
// 上级部门id是0代表是机构下最顶级的部门
return;
}
if (parentDept == null) {
throw new ServiceException(ErrorCodeConstants.DEPT_PARENT_NOT_EXITS);
} else if (!CommonStatusEnum.ENABLE.getStatus().equals(parentDept.getStatus())) {
throw new ServiceException(ErrorCodeConstants.DEPT_DISABLE, parentDept.getName());
} else {
validParentDept(parentDept);
}
}
@@ -1,5 +1,6 @@
package com.cf.imes.module.system.service.dept;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
@@ -625,12 +626,20 @@ class DeptServiceImplTest extends BaseMockitoUnitTest {
Set<Long> allInvalidDeptIds = deptService.getAllInvalidDeptIds(organId);
assertEquals(disableCount, allInvalidDeptIds.size());
OrganContextHolder.setOrganId(organId);
Set<Long> noOrganAllInvalidDeptIds = deptService.getAllInvalidDeptIds(null);
assertEquals(disableCount, noOrganAllInvalidDeptIds.size());
//
//
}
@Test
@WithMockLoginUser(organId = 100L)
void getAllInvalidDeptIds_outerOrganIdNull(){
OrganContextHolder.setOrganId(SecurityFrameworkUtils.getUserOrganId());
deptService.getAllInvalidDeptIds(null);
verify(deptMapper).selectList(any(LambdaQueryWrapper.class));
}
@Test
void testDeptNotExist_shouldReturn() {
// 不插入任何部门,确保 deptId 不存在
@@ -662,6 +671,7 @@ class DeptServiceImplTest extends BaseMockitoUnitTest {
DeptDO dept = new DeptDO();
dept.setName("测试部-启用");
dept.setStatus(CommonStatusEnum.ENABLE.getStatus());
dept.setParentId(DeptDO.PARENT_ID_ROOT);
Long id = dept.getId();
when(deptMapper.selectById(id)).thenReturn(dept);
@@ -700,6 +710,7 @@ class DeptServiceImplTest extends BaseMockitoUnitTest {
parent.setId(100L);
parent.setName("上级部门-启用");
parent.setStatus(CommonStatusEnum.ENABLE.getStatus());
parent.setParentId(DeptDO.PARENT_ID_ROOT);
// 子部门启用
DeptDO child = new DeptDO();
@@ -749,6 +760,7 @@ class DeptServiceImplTest extends BaseMockitoUnitTest {
top.setId(100L);
top.setName("顶级部门-启用");
top.setStatus(CommonStatusEnum.ENABLE.getStatus());
top.setParentId(DeptDO.PARENT_ID_ROOT);
// 中间部门启用
DeptDO middle = new DeptDO();