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 | 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 19 | 19 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| 20 | 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 | 22 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS; |
| 22 | 23 | import static org.junit.jupiter.api.Assertions.*; |
| 23 | 24 | |
| ... | ... | @@ -38,9 +39,16 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { |
| 38 | 39 | @Test |
| 39 | 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 | 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 | 52 | productCategoryMapper.insert(parentProductCategory); |
| 45 | 53 | |
| 46 | 54 | // 调用 |
| ... | ... | @@ -108,7 +116,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { |
| 108 | 116 | public void testGetCategoryLevel() { |
| 109 | 117 | // mock 数据 |
| 110 | 118 | ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class, |
| 111 | - o -> o.setParentId(ProductCategoryDO.PARENT_ID_NULL)); | |
| 119 | + o -> o.setParentId(PARENT_ID_NULL)); | |
| 112 | 120 | productCategoryMapper.insert(category1); |
| 113 | 121 | ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class, |
| 114 | 122 | o -> o.setParentId(category1.getId())); |
| ... | ... | @@ -129,7 +137,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { |
| 129 | 137 | ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 |
| 130 | 138 | o.setName("奥特曼"); |
| 131 | 139 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 132 | - o.setParentId(ProductCategoryDO.PARENT_ID_NULL); | |
| 140 | + o.setParentId(PARENT_ID_NULL); | |
| 133 | 141 | }); |
| 134 | 142 | productCategoryMapper.insert(dbCategory); |
| 135 | 143 | // 测试 name 不匹配 |
| ... | ... | @@ -142,7 +150,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { |
| 142 | 150 | ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); |
| 143 | 151 | reqVO.setName("特曼"); |
| 144 | 152 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 145 | - reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL); | |
| 153 | + reqVO.setParentId(PARENT_ID_NULL); | |
| 146 | 154 | |
| 147 | 155 | // 调用 |
| 148 | 156 | List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO); | ... | ... |