From 79b9151eb3692aa1433cab5c79d54d8341571445 Mon Sep 17 00:00:00 2001 From: chuck <361648887@qq.com> Date: Sun, 26 Jul 2026 18:59:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(test):=20=E6=9B=B4=E6=96=B0=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E6=9C=8D=E5=8A=A1=E6=B5=8B=E8=AF=95=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=B1=BB=E5=9E=8B=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 OrgException 和 OrgExceptionEnum 替换为 TemplateException 和 TemplateExceptionEnum - 修改所有相关的异常抛出和断言检查 - 确保测试代码与新的异常类型保持一致 --- .../service/impl/DeptServiceImplTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/structure-ddd-template-application/src/test/java/cn/structured/template/application/service/impl/DeptServiceImplTest.java b/structure-ddd-template-application/src/test/java/cn/structured/template/application/service/impl/DeptServiceImplTest.java index cddf30c..921a7df 100644 --- a/structure-ddd-template-application/src/test/java/cn/structured/template/application/service/impl/DeptServiceImplTest.java +++ b/structure-ddd-template-application/src/test/java/cn/structured/template/application/service/impl/DeptServiceImplTest.java @@ -7,8 +7,8 @@ import cn.structured.template.domain.repository.DeptRepository; import cn.structured.template.domain.service.DeptDomainService; import cn.structured.template.common.dto.DeptDTO; -import cn.structured.template.common.enums.OrgExceptionEnum; -import cn.structured.template.common.exception.OrgException; +import cn.structured.template.common.enums.TemplateExceptionEnum; +import cn.structured.template.common.exception.TemplateException; import cn.structured.template.common.query.DeptQuery; import cn.structured.template.common.vo.DeptVO; import org.junit.jupiter.api.BeforeEach; @@ -101,10 +101,10 @@ void create_whenHasParent_shouldSetTreePath() { @Test void create_whenParentNotFound_shouldThrowException() { dto.setParentId(99L); - doThrow(new OrgException(TemplateExceptionEnum.DEPT_PARENT_NOT_FOUND)) + doThrow(new TemplateException(TemplateExceptionEnum.DEPT_PARENT_NOT_FOUND)) .when(deptDomainService).buildTreePathOnCreate(any(DeptEntity.class)); - OrgException exception = assertThrows(OrgException.class, + TemplateException exception = assertThrows(TemplateException.class, () -> deptService.create(dto)); assertEquals(TemplateExceptionEnum.DEPT_PARENT_NOT_FOUND.getCode(), exception.getCode()); @@ -124,7 +124,7 @@ void update_shouldUpdateDept() { void update_whenDeptNotFound_shouldThrowException() { when(deptRepository.findById(1L)).thenReturn(null); - OrgException exception = assertThrows(OrgException.class, + TemplateException exception = assertThrows(TemplateException.class, () -> deptService.update(1L, dto)); assertEquals(TemplateExceptionEnum.DEPT_NOT_FOUND.getCode(), exception.getCode()); @@ -163,7 +163,7 @@ void deleteByIds_shouldDeleteDepts() { void deleteByIds_whenHasChildren_shouldThrowException() { when(deptRepository.countByParentId(1L)).thenReturn(1L); - OrgException exception = assertThrows(OrgException.class, + TemplateException exception = assertThrows(TemplateException.class, () -> deptService.deleteByIds(Collections.singletonList(1L))); assertEquals(TemplateExceptionEnum.DEPT_HAS_CHILDREN.getCode(), exception.getCode()); @@ -184,7 +184,7 @@ void findById_shouldReturnDeptVO() { void findById_whenDeptNotFound_shouldThrowException() { when(deptRepository.findById(1L)).thenReturn(null); - OrgException exception = assertThrows(OrgException.class, + TemplateException exception = assertThrows(TemplateException.class, () -> deptService.findById(1L)); assertEquals(TemplateExceptionEnum.DEPT_NOT_FOUND.getCode(), exception.getCode());