增加 dept 模块的单测覆盖率

pull/80/head
YunaiV 2023-12-03 21:26:51 +08:00
parent f806995de3
commit 18785550da
3 changed files with 31 additions and 8 deletions

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.system.service.dept;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO;
@ -10,8 +9,6 @@ import org.springframework.lang.Nullable;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
/**
* Service
*
@ -44,12 +41,10 @@ public interface PostService {
/**
*
*
* @param ids
* @param ids
* @return
*/
default List<PostDO> getPostList(@Nullable Collection<Long> ids) {
return getPostList(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus()));
}
List<PostDO> getPostList(@Nullable Collection<Long> ids);
/**
*
@ -58,7 +53,8 @@ public interface PostService {
* @param statuses
* @return
*/
List<PostDO> getPostList(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
List<PostDO> getPostList(@Nullable Collection<Long> ids,
@Nullable Collection<Integer> statuses);
/**
*

View File

@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -107,6 +108,14 @@ public class PostServiceImpl implements PostService {
}
}
@Override
public List<PostDO> getPostList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return postMapper.selectBatchIds(ids);
}
@Override
public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses) {
return postMapper.selectList(ids, statuses);

View File

@ -155,6 +155,24 @@ public class PostServiceImplTest extends BaseDbUnitTest {
@Test
public void testGetPostList() {
// mock 数据
PostDO postDO01 = randomPojo(PostDO.class);
postMapper.insert(postDO01);
// 测试 id 不匹配
PostDO postDO02 = randomPojo(PostDO.class);
postMapper.insert(postDO02);
// 准备参数
List<Long> ids = singletonList(postDO01.getId());
// 调用
List<PostDO> list = postService.getPostList(ids);
// 断言
assertEquals(1, list.size());
assertPojoEquals(postDO01, list.get(0));
}
@Test
public void testGetPostList_idsAndStatus() {
// mock 数据
PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
postMapper.insert(postDO01);