diff --git a/yudao-module-bs/yudao-module-bs-biz/src/test/java/cn/iocoder/yudao/module/bs/service/budget/BudgetServiceImplTest.java b/yudao-module-bs/yudao-module-bs-biz/src/test/java/cn/iocoder/yudao/module/bs/service/budget/BudgetServiceImplTest.java deleted file mode 100644 index 53d0de9c..00000000 --- a/yudao-module-bs/yudao-module-bs-biz/src/test/java/cn/iocoder/yudao/module/bs/service/budget/BudgetServiceImplTest.java +++ /dev/null @@ -1,211 +0,0 @@ -package cn.iocoder.yudao.module.bs.service.budget; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetCreateReqVO; -import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExportReqVO; -import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO; -import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO; -import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO; -import cn.iocoder.yudao.module.bs.dal.mysql.budget.BudgetMapper; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -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.randomLongId; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; -import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.BUDGET_NOT_EXISTS; -import static org.junit.jupiter.api.Assertions.*; - -/** - * {@link BudgetServiceImpl} 的单元测试类 - * - * @author chenqp - */ -@Import(BudgetServiceImpl.class) -public class BudgetServiceImplTest extends BaseDbUnitTest { - - @Resource - private BudgetServiceImpl budgetService; - - @Resource - private BudgetMapper budgetMapper; - - @Test - public void testCreateBudget_success() { - // 准备参数 - BudgetCreateReqVO reqVO = randomPojo(BudgetCreateReqVO.class); - - // 调用 - Long budgetId = budgetService.createBudget(reqVO); - // 断言 - assertNotNull(budgetId); - // 校验记录的属性是否正确 - BudgetDO budget = budgetMapper.selectById(budgetId); - assertPojoEquals(reqVO, budget); - } - - @Test - public void testUpdateBudget_success() { - // mock 数据 - BudgetDO dbBudget = randomPojo(BudgetDO.class); - budgetMapper.insert(dbBudget);// @Sql: 先插入出一条存在的数据 - // 准备参数 - BudgetUpdateReqVO reqVO = randomPojo(BudgetUpdateReqVO.class, o -> { - o.setId(dbBudget.getId()); // 设置更新的 ID - }); - - // 调用 - budgetService.updateBudget(reqVO); - // 校验是否更新正确 - BudgetDO budget = budgetMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, budget); - } - - @Test - public void testUpdateBudget_notExists() { - // 准备参数 - BudgetUpdateReqVO reqVO = randomPojo(BudgetUpdateReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> budgetService.updateBudget(reqVO), BUDGET_NOT_EXISTS); - } - - @Test - public void testDeleteBudget_success() { - // mock 数据 - BudgetDO dbBudget = randomPojo(BudgetDO.class); - budgetMapper.insert(dbBudget);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbBudget.getId(); - - // 调用 - budgetService.deleteBudget(id); - // 校验数据不存在了 - assertNull(budgetMapper.selectById(id)); - } - - @Test - public void testDeleteBudget_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> budgetService.deleteBudget(id), BUDGET_NOT_EXISTS); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetBudgetPage() { - // mock 数据 - BudgetDO dbBudget = randomPojo(BudgetDO.class, o -> { // 等会查询到 - o.setBudgetYear(null); - o.setAmount(null); - o.setUsedAmount(null); - o.setOccupyAmount(null); - o.setRemainAmount(null); - o.setDeptId(null); - o.setRemark(null); - o.setFiles(null); - o.setCreateTime(null); - }); - budgetMapper.insert(dbBudget); - // 测试 budgetYear 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setBudgetYear(null))); - // 测试 amount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setAmount(null))); - // 测试 usedAmount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setUsedAmount(null))); - // 测试 occupyAmount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setOccupyAmount(null))); - // 测试 remainAmount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemainAmount(null))); - // 测试 deptId 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setDeptId(null))); - // 测试 remark 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemark(null))); - // 测试 files 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setFiles(null))); - // 测试 createTime 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setCreateTime(null))); - // 准备参数 - BudgetPageReqVO reqVO = new BudgetPageReqVO(); - reqVO.setBudgetYear(null); - reqVO.setAmount(null); - reqVO.setUsedAmount(null); - reqVO.setOccupyAmount(null); - reqVO.setRemainAmount(null); - reqVO.setDeptId(null); - reqVO.setRemark(null); - reqVO.setFiles(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - - // 调用 - PageResult pageResult = budgetService.getBudgetPage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbBudget, pageResult.getList().get(0)); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetBudgetList() { - // mock 数据 - BudgetDO dbBudget = randomPojo(BudgetDO.class, o -> { // 等会查询到 - o.setBudgetYear(null); - o.setAmount(null); - o.setUsedAmount(null); - o.setOccupyAmount(null); - o.setRemainAmount(null); - o.setDeptId(null); - o.setRemark(null); - o.setFiles(null); - o.setCreateTime(null); - }); - budgetMapper.insert(dbBudget); - // 测试 budgetYear 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setBudgetYear(null))); - // 测试 amount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setAmount(null))); - // 测试 usedAmount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setUsedAmount(null))); - // 测试 occupyAmount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setOccupyAmount(null))); - // 测试 remainAmount 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemainAmount(null))); - // 测试 deptId 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setDeptId(null))); - // 测试 remark 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setRemark(null))); - // 测试 files 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setFiles(null))); - // 测试 createTime 不匹配 - budgetMapper.insert(cloneIgnoreId(dbBudget, o -> o.setCreateTime(null))); - // 准备参数 - BudgetExportReqVO reqVO = new BudgetExportReqVO(); - reqVO.setBudgetYear(null); - reqVO.setAmount(null); - reqVO.setUsedAmount(null); - reqVO.setOccupyAmount(null); - reqVO.setRemainAmount(null); - reqVO.setDeptId(null); - reqVO.setRemark(null); - reqVO.setFiles(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - - // 调用 - List list = budgetService.getBudgetList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbBudget, list.get(0)); - } - -} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/test/java/cn/iocoder/yudao/module/bs/service/feemanage/FeeManageServiceImplTest.java b/yudao-module-bs/yudao-module-bs-biz/src/test/java/cn/iocoder/yudao/module/bs/service/feemanage/FeeManageServiceImplTest.java deleted file mode 100644 index 87f2f528..00000000 --- a/yudao-module-bs/yudao-module-bs-biz/src/test/java/cn/iocoder/yudao/module/bs/service/feemanage/FeeManageServiceImplTest.java +++ /dev/null @@ -1,195 +0,0 @@ -package cn.iocoder.yudao.module.bs.service.feemanage; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageCreateReqVO; -import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageExportReqVO; -import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManagePageReqVO; -import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageUpdateReqVO; -import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO; -import cn.iocoder.yudao.module.bs.dal.mysql.feemanage.FeeManageMapper; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; - -import javax.annotation.Resource; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -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.randomLongId; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; -import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.FEE_MANAGE_NOT_EXISTS; -import static org.junit.jupiter.api.Assertions.*; - -/** - * {@link FeeManageServiceImpl} 的单元测试类 - * - * @author chenqp - */ -@Import(FeeManageServiceImpl.class) -public class FeeManageServiceImplTest extends BaseDbUnitTest { - - @Resource - private FeeManageServiceImpl feeManageService; - - @Resource - private FeeManageMapper feeManageMapper; - - @Test - public void testCreateFeeManage_success() { - // 准备参数 - FeeManageCreateReqVO reqVO = randomPojo(FeeManageCreateReqVO.class); - - // 调用 - Long feeManageId = feeManageService.createFeeManage(reqVO); - // 断言 - assertNotNull(feeManageId); - // 校验记录的属性是否正确 - FeeManageDO feeManage = feeManageMapper.selectById(feeManageId); - assertPojoEquals(reqVO, feeManage); - } - - @Test - public void testUpdateFeeManage_success() { - // mock 数据 - FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class); - feeManageMapper.insert(dbFeeManage);// @Sql: 先插入出一条存在的数据 - // 准备参数 - FeeManageUpdateReqVO reqVO = randomPojo(FeeManageUpdateReqVO.class, o -> { - o.setId(dbFeeManage.getId()); // 设置更新的 ID - }); - - // 调用 - feeManageService.updateFeeManage(reqVO); - // 校验是否更新正确 - FeeManageDO feeManage = feeManageMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, feeManage); - } - - @Test - public void testUpdateFeeManage_notExists() { - // 准备参数 - FeeManageUpdateReqVO reqVO = randomPojo(FeeManageUpdateReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> feeManageService.updateFeeManage(reqVO), FEE_MANAGE_NOT_EXISTS); - } - - @Test - public void testDeleteFeeManage_success() { - // mock 数据 - FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class); - feeManageMapper.insert(dbFeeManage);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbFeeManage.getId(); - - // 调用 - feeManageService.deleteFeeManage(id); - // 校验数据不存在了 - assertNull(feeManageMapper.selectById(id)); - } - - @Test - public void testDeleteFeeManage_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> feeManageService.deleteFeeManage(id), FEE_MANAGE_NOT_EXISTS); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetFeeManagePage() { - // mock 数据 - FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class, o -> { // 等会查询到 - o.setDeptId(null); - o.setRoleIds(null); - o.setAmount(null); - o.setArea(null); - o.setRemark(null); - o.setFiles(null); - o.setCreateTime(null); - }); - feeManageMapper.insert(dbFeeManage); - // 测试 deptId 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setDeptId(null))); - // 测试 roleIds 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRoleIds(null))); - // 测试 amount 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setAmount(null))); - // 测试 area 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setArea(null))); - // 测试 remark 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRemark(null))); - // 测试 files 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setFiles(null))); - // 测试 createTime 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setCreateTime(null))); - // 准备参数 - FeeManagePageReqVO reqVO = new FeeManagePageReqVO(); - reqVO.setDeptId(null); - reqVO.setRoleIds(null); - reqVO.setAmount(null); - reqVO.setArea(null); - reqVO.setRemark(null); - reqVO.setFiles(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - - // 调用 - PageResult pageResult = feeManageService.getFeeManagePage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbFeeManage, pageResult.getList().get(0)); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetFeeManageList() { - // mock 数据 - FeeManageDO dbFeeManage = randomPojo(FeeManageDO.class, o -> { // 等会查询到 - o.setDeptId(null); - o.setRoleIds(null); - o.setAmount(null); - o.setArea(null); - o.setRemark(null); - o.setFiles(null); - o.setCreateTime(null); - }); - feeManageMapper.insert(dbFeeManage); - // 测试 deptId 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setDeptId(null))); - // 测试 roleIds 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRoleIds(null))); - // 测试 amount 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setAmount(null))); - // 测试 area 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setArea(null))); - // 测试 remark 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setRemark(null))); - // 测试 files 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setFiles(null))); - // 测试 createTime 不匹配 - feeManageMapper.insert(cloneIgnoreId(dbFeeManage, o -> o.setCreateTime(null))); - // 准备参数 - FeeManageExportReqVO reqVO = new FeeManageExportReqVO(); - reqVO.setDeptId(null); - reqVO.setRoleIds(null); - reqVO.setAmount(null); - reqVO.setArea(null); - reqVO.setRemark(null); - reqVO.setFiles(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - - // 调用 - List list = feeManageService.getFeeManageList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbFeeManage, list.get(0)); - } - -}