🔧 简化 post 和 dept 模块的 VO

This commit is contained in:
YunaiV
2023-12-02 10:18:27 +08:00
parent a5c59c6079
commit a9c8f6c8e9
14 changed files with 86 additions and 134 deletions

View File

@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.dept;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
import org.junit.jupiter.api.Test;
@ -39,7 +38,8 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateDept() {
// 准备参数
DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> {
DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> {
o.setId(null); // 防止 id 被设置
o.setParentId(DeptDO.PARENT_ID_ROOT);
o.setStatus(randomCommonStatus());
});
@ -50,7 +50,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
assertNotNull(deptId);
// 校验记录的属性是否正确
DeptDO deptDO = deptMapper.selectById(deptId);
assertPojoEquals(reqVO, deptDO);
assertPojoEquals(reqVO, deptDO, "id");
}
@Test
@ -59,7 +59,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus()));
deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据
// 准备参数
DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> {
DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> {
// 设置更新的 ID
o.setParentId(DeptDO.PARENT_ID_ROOT);
o.setId(dbDeptDO.getId());

View File

@ -43,7 +43,8 @@ public class PostServiceImplTest extends BaseDbUnitTest {
public void testCreatePost_success() {
// 准备参数
PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class,
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()));
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()))
.setId(null); // 防止 id 被设置
// 调用
Long postId = postService.createPost(reqVO);
@ -51,7 +52,7 @@ public class PostServiceImplTest extends BaseDbUnitTest {
assertNotNull(postId);
// 校验记录的属性是否正确
PostDO post = postMapper.selectById(postId);
assertPojoEquals(reqVO, post);
assertPojoEquals(reqVO, post, "id");
}
@Test
@ -225,4 +226,5 @@ public class PostServiceImplTest extends BaseDbUnitTest {
};
return randomPojo(PostDO.class, ArrayUtils.append(consumer, consumers));
}
}