Commit 4dab6d0217c211130361d2c23b73d8842932e6d4

Authored by YunaiV
1 parent dab751dc

✅ 增加 dept 模块的单测覆盖率

yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java
1 package cn.iocoder.yudao.module.system.service.dept; 1 package cn.iocoder.yudao.module.system.service.dept;
2 2
3 -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;  
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; 4 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
6 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; 5 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO;
@@ -10,8 +9,6 @@ import org.springframework.lang.Nullable; @@ -10,8 +9,6 @@ import org.springframework.lang.Nullable;
10 import java.util.Collection; 9 import java.util.Collection;
11 import java.util.List; 10 import java.util.List;
12 11
13 -import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;  
14 -  
15 /** 12 /**
16 * 岗位 Service 接口 13 * 岗位 Service 接口
17 * 14 *
@@ -44,12 +41,10 @@ public interface PostService { @@ -44,12 +41,10 @@ public interface PostService {
44 /** 41 /**
45 * 获得岗位列表 42 * 获得岗位列表
46 * 43 *
47 - * @param ids 岗位编号数组。如果为空,不进行筛选 44 + * @param ids 岗位编号数组
48 * @return 部门列表 45 * @return 部门列表
49 */ 46 */
50 - default List<PostDO> getPostList(@Nullable Collection<Long> ids) {  
51 - return getPostList(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus()));  
52 - } 47 + List<PostDO> getPostList(@Nullable Collection<Long> ids);
53 48
54 /** 49 /**
55 * 获得符合条件的岗位列表 50 * 获得符合条件的岗位列表
@@ -58,7 +53,8 @@ public interface PostService { @@ -58,7 +53,8 @@ public interface PostService {
58 * @param statuses 状态数组。如果为空,不进行筛选 53 * @param statuses 状态数组。如果为空,不进行筛选
59 * @return 部门列表 54 * @return 部门列表
60 */ 55 */
61 - List<PostDO> getPostList(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); 56 + List<PostDO> getPostList(@Nullable Collection<Long> ids,
  57 + @Nullable Collection<Integer> statuses);
62 58
63 /** 59 /**
64 * 获得岗位分页列表 60 * 获得岗位分页列表
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
@@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated; @@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
13 13
14 import javax.annotation.Resource; 14 import javax.annotation.Resource;
15 import java.util.Collection; 15 import java.util.Collection;
  16 +import java.util.Collections;
16 import java.util.List; 17 import java.util.List;
17 import java.util.Map; 18 import java.util.Map;
18 19
@@ -108,6 +109,14 @@ public class PostServiceImpl implements PostService { @@ -108,6 +109,14 @@ public class PostServiceImpl implements PostService {
108 } 109 }
109 110
110 @Override 111 @Override
  112 + public List<PostDO> getPostList(Collection<Long> ids) {
  113 + if (CollUtil.isEmpty(ids)) {
  114 + return Collections.emptyList();
  115 + }
  116 + return postMapper.selectBatchIds(ids);
  117 + }
  118 +
  119 + @Override
111 public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses) { 120 public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses) {
112 return postMapper.selectList(ids, statuses); 121 return postMapper.selectList(ids, statuses);
113 } 122 }
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java
@@ -156,6 +156,24 @@ public class PostServiceImplTest extends BaseDbUnitTest { @@ -156,6 +156,24 @@ public class PostServiceImplTest extends BaseDbUnitTest {
156 @Test 156 @Test
157 public void testGetPostList() { 157 public void testGetPostList() {
158 // mock 数据 158 // mock 数据
  159 + PostDO postDO01 = randomPojo(PostDO.class);
  160 + postMapper.insert(postDO01);
  161 + // 测试 id 不匹配
  162 + PostDO postDO02 = randomPojo(PostDO.class);
  163 + postMapper.insert(postDO02);
  164 + // 准备参数
  165 + List<Long> ids = singletonList(postDO01.getId());
  166 +
  167 + // 调用
  168 + List<PostDO> list = postService.getPostList(ids);
  169 + // 断言
  170 + assertEquals(1, list.size());
  171 + assertPojoEquals(postDO01, list.get(0));
  172 + }
  173 +
  174 + @Test
  175 + public void testGetPostList_idsAndStatus() {
  176 + // mock 数据
159 PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); 177 PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
160 postMapper.insert(postDO01); 178 postMapper.insert(postDO01);
161 // 测试 status 不匹配 179 // 测试 status 不匹配