Commit b0c73b786a698fa9db8d2593e3f5bf97c7cc625e
1 parent
5674bfaf
[测试][商品分类]测试创建商品分类
Showing
1 changed file
with
13 additions
and
5 deletions
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 | @@ -18,6 +18,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq | ||
| 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 19 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 19 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| 20 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 20 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 21 | +import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.PARENT_ID_NULL; | ||
| 21 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS; | 22 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS; |
| 22 | import static org.junit.jupiter.api.Assertions.*; | 23 | import static org.junit.jupiter.api.Assertions.*; |
| 23 | 24 | ||
| @@ -38,9 +39,16 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | @@ -38,9 +39,16 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | ||
| 38 | @Test | 39 | @Test |
| 39 | public void testCreateCategory_success() { | 40 | public void testCreateCategory_success() { |
| 40 | // 准备参数 | 41 | // 准备参数 |
| 41 | - ProductCategoryCreateReqVO reqVO = randomPojo(ProductCategoryCreateReqVO.class); | 42 | + ProductCategoryCreateReqVO reqVO = randomPojo(ProductCategoryCreateReqVO.class,o -> { |
| 43 | + // 设置PC端图片可为空 | ||
| 44 | + o.setBigPicUrl(null); | ||
| 45 | + }); | ||
| 46 | + | ||
| 42 | // mock 父类 | 47 | // mock 父类 |
| 43 | - ProductCategoryDO parentProductCategory = randomPojo(ProductCategoryDO.class, o -> o.setId(reqVO.getParentId())); | 48 | + ProductCategoryDO parentProductCategory = randomPojo(ProductCategoryDO.class, o -> { |
| 49 | + reqVO.setParentId(o.getId()); | ||
| 50 | + o.setParentId(PARENT_ID_NULL); | ||
| 51 | + }); | ||
| 44 | productCategoryMapper.insert(parentProductCategory); | 52 | productCategoryMapper.insert(parentProductCategory); |
| 45 | 53 | ||
| 46 | // 调用 | 54 | // 调用 |
| @@ -108,7 +116,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | @@ -108,7 +116,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | ||
| 108 | public void testGetCategoryLevel() { | 116 | public void testGetCategoryLevel() { |
| 109 | // mock 数据 | 117 | // mock 数据 |
| 110 | ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class, | 118 | ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class, |
| 111 | - o -> o.setParentId(ProductCategoryDO.PARENT_ID_NULL)); | 119 | + o -> o.setParentId(PARENT_ID_NULL)); |
| 112 | productCategoryMapper.insert(category1); | 120 | productCategoryMapper.insert(category1); |
| 113 | ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class, | 121 | ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class, |
| 114 | o -> o.setParentId(category1.getId())); | 122 | o -> o.setParentId(category1.getId())); |
| @@ -129,7 +137,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | @@ -129,7 +137,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | ||
| 129 | ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 | 137 | ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 |
| 130 | o.setName("奥特曼"); | 138 | o.setName("奥特曼"); |
| 131 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 139 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 132 | - o.setParentId(ProductCategoryDO.PARENT_ID_NULL); | 140 | + o.setParentId(PARENT_ID_NULL); |
| 133 | }); | 141 | }); |
| 134 | productCategoryMapper.insert(dbCategory); | 142 | productCategoryMapper.insert(dbCategory); |
| 135 | // 测试 name 不匹配 | 143 | // 测试 name 不匹配 |
| @@ -142,7 +150,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | @@ -142,7 +150,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { | ||
| 142 | ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); | 150 | ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); |
| 143 | reqVO.setName("特曼"); | 151 | reqVO.setName("特曼"); |
| 144 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 152 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 145 | - reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL); | 153 | + reqVO.setParentId(PARENT_ID_NULL); |
| 146 | 154 | ||
| 147 | // 调用 | 155 | // 调用 |
| 148 | List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO); | 156 | List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO); |