From b0c73b786a698fa9db8d2593e3f5bf97c7cc625e Mon Sep 17 00:00:00 2001 From: wangzhs Date: Wed, 15 Mar 2023 14:23:42 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=B5=8B=E8=AF=95][=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB]=E6=B5=8B=E8=AF=95=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductCategoryServiceImplTest.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java index 0b8cd30bd..09c4f7927 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java @@ -18,6 +18,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq 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.product.dal.dataobject.category.ProductCategoryDO.PARENT_ID_NULL; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; @@ -38,9 +39,16 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { @Test public void testCreateCategory_success() { // 准备参数 - ProductCategoryCreateReqVO reqVO = randomPojo(ProductCategoryCreateReqVO.class); + ProductCategoryCreateReqVO reqVO = randomPojo(ProductCategoryCreateReqVO.class,o -> { + // 设置PC端图片可为空 + o.setBigPicUrl(null); + }); + // mock 父类 - ProductCategoryDO parentProductCategory = randomPojo(ProductCategoryDO.class, o -> o.setId(reqVO.getParentId())); + ProductCategoryDO parentProductCategory = randomPojo(ProductCategoryDO.class, o -> { + reqVO.setParentId(o.getId()); + o.setParentId(PARENT_ID_NULL); + }); productCategoryMapper.insert(parentProductCategory); // 调用 @@ -108,7 +116,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { public void testGetCategoryLevel() { // mock 数据 ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class, - o -> o.setParentId(ProductCategoryDO.PARENT_ID_NULL)); + o -> o.setParentId(PARENT_ID_NULL)); productCategoryMapper.insert(category1); ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class, o -> o.setParentId(category1.getId())); @@ -129,7 +137,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 o.setName("奥特曼"); o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setParentId(ProductCategoryDO.PARENT_ID_NULL); + o.setParentId(PARENT_ID_NULL); }); productCategoryMapper.insert(dbCategory); // 测试 name 不匹配 @@ -142,7 +150,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); reqVO.setName("特曼"); reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL); + reqVO.setParentId(PARENT_ID_NULL); // 调用 List list = productCategoryService.getEnableCategoryList(reqVO);