完善 ErrorCodeServiceImpl 单元测试

This commit is contained in:
YunaiV 2023-02-01 08:04:36 +08:00
parent fed9feb05f
commit 9ca793919d
7 changed files with 79 additions and 48 deletions

View File

@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -19,9 +18,7 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
} }
default DeptDO selectByParentIdAndName(Long parentId, String name) { default DeptDO selectByParentIdAndName(Long parentId, String name) {
return selectOne(new LambdaQueryWrapper<DeptDO>() return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name);
.eq(DeptDO::getParentId, parentId)
.eq(DeptDO::getName, name));
} }
default Long selectCountByParentId(Long parentId) { default Long selectCountByParentId(Long parentId) {

View File

@ -2,11 +2,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Collection; import java.util.Collection;
@ -16,31 +15,32 @@ import java.util.List;
public interface PostMapper extends BaseMapperX<PostDO> { public interface PostMapper extends BaseMapperX<PostDO> {
default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) { default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
return selectList(new QueryWrapperX<PostDO>().inIfPresent("id", ids) return selectList(new LambdaQueryWrapperX<PostDO>()
.inIfPresent("status", statuses)); .inIfPresent(PostDO::getId, ids)
.inIfPresent(PostDO::getStatus, statuses));
} }
default PageResult<PostDO> selectPage(PostPageReqVO reqVO) { default PageResult<PostDO> selectPage(PostPageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<PostDO>() return selectPage(reqVO, new LambdaQueryWrapperX<PostDO>()
.likeIfPresent("code", reqVO.getCode()) .likeIfPresent(PostDO::getCode, reqVO.getCode())
.likeIfPresent("name", reqVO.getName()) .likeIfPresent(PostDO::getName, reqVO.getName())
.eqIfPresent("status", reqVO.getStatus()) .eqIfPresent(PostDO::getStatus, reqVO.getStatus())
.orderByDesc("id")); .orderByDesc(PostDO::getId));
} }
default List<PostDO> selectList(PostExportReqVO reqVO) { default List<PostDO> selectList(PostExportReqVO reqVO) {
return selectList(new QueryWrapperX<PostDO>() return selectList(new LambdaQueryWrapperX<PostDO>()
.likeIfPresent("code", reqVO.getCode()) .likeIfPresent(PostDO::getCode, reqVO.getCode())
.likeIfPresent("name", reqVO.getName()) .likeIfPresent(PostDO::getName, reqVO.getName())
.eqIfPresent("status", reqVO.getStatus())); .eqIfPresent(PostDO::getStatus, reqVO.getStatus()));
} }
default PostDO selectByName(String name) { default PostDO selectByName(String name) {
return selectOne(new QueryWrapper<PostDO>().eq("name", name)); return selectOne(PostDO::getName, name);
} }
default PostDO selectByCode(String code) { default PostDO selectByCode(String code) {
return selectOne(new QueryWrapper<PostDO>().eq("code", code)); return selectOne(PostDO::getCode, code);
} }
} }

View File

@ -17,13 +17,11 @@ import java.util.List;
public interface DictDataMapper extends BaseMapperX<DictDataDO> { public interface DictDataMapper extends BaseMapperX<DictDataDO> {
default DictDataDO selectByDictTypeAndValue(String dictType, String value) { default DictDataDO selectByDictTypeAndValue(String dictType, String value) {
return selectOne(new LambdaQueryWrapper<DictDataDO>().eq(DictDataDO::getDictType, dictType) return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getValue, value);
.eq(DictDataDO::getValue, value));
} }
default DictDataDO selectByDictTypeAndLabel(String dictType, String label) { default DictDataDO selectByDictTypeAndLabel(String dictType, String label) {
return selectOne(new LambdaQueryWrapper<DictDataDO>().eq(DictDataDO::getDictType, dictType) return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getLabel, label);
.eq(DictDataDO::getLabel, label));
} }
default List<DictDataDO> selectByDictTypeAndValues(String dictType, Collection<String> values) { default List<DictDataDO> selectByDictTypeAndValues(String dictType, Collection<String> values) {

View File

@ -36,11 +36,11 @@ public interface ErrorCodeMapper extends BaseMapperX<ErrorCodeDO> {
} }
default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) { default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) {
return selectList(new LambdaQueryWrapperX<ErrorCodeDO>().in(ErrorCodeDO::getCode, codes)); return selectList(ErrorCodeDO::getCode, codes);
} }
default ErrorCodeDO selectByCode(Integer code) { default ErrorCodeDO selectByCode(Integer code) {
return selectOne(new LambdaQueryWrapperX<ErrorCodeDO>().eq(ErrorCodeDO::getCode, code)); return selectOne(ErrorCodeDO::getCode, code);
} }
default List<ErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) { default List<ErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) {

View File

@ -58,7 +58,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
@Override @Override
public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) { public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) {
// 校验存在 // 校验存在
this.validateErrorCodeExists(updateReqVO.getId()); validateErrorCodeExists(updateReqVO.getId());
// 校验 code 重复 // 校验 code 重复
validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId());
@ -71,7 +71,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
@Override @Override
public void deleteErrorCode(Long id) { public void deleteErrorCode(Long id) {
// 校验存在 // 校验存在
this.validateErrorCodeExists(id); validateErrorCodeExists(id);
// 删除 // 删除
errorCodeMapper.deleteById(id); errorCodeMapper.deleteById(id);
} }
@ -100,7 +100,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
} }
@VisibleForTesting @VisibleForTesting
public void validateErrorCodeExists(Long id) { void validateErrorCodeExists(Long id) {
if (errorCodeMapper.selectById(id) == null) { if (errorCodeMapper.selectById(id) == null) {
throw exception(ERROR_CODE_NOT_EXISTS); throw exception(ERROR_CODE_NOT_EXISTS);
} }

View File

@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.system.service.errorcode;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO;
import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO;
@ -22,7 +22,9 @@ import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
@ -57,7 +59,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
@Test @Test
public void testUpdateErrorCode_success() { public void testUpdateErrorCode_success() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(); ErrorCodeDO dbErrorCode = randomErrorCodeDO();
errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> { ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> {
@ -75,7 +77,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
@Test @Test
public void testDeleteErrorCode_success() { public void testDeleteErrorCode_success() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(); ErrorCodeDO dbErrorCode = randomErrorCodeDO();
errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
Long id = dbErrorCode.getId(); Long id = dbErrorCode.getId();
@ -96,7 +98,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
reqVO.setApplicationName("tu"); reqVO.setApplicationName("tu");
reqVO.setCode(1); reqVO.setCode(1);
reqVO.setMessage("ma"); reqVO.setMessage("ma");
reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 11, 1),buildTime(2020, 11, 30)})); reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30));
// 调用 // 调用
PageResult<ErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(reqVO); PageResult<ErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(reqVO);
@ -110,7 +112,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
* 初始化 getErrorCodePage 方法的测试数据 * 初始化 getErrorCodePage 方法的测试数据
*/ */
private ErrorCodeDO initGetErrorCodePage() { private ErrorCodeDO initGetErrorCodePage() {
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到 ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> { // 等会查询到
o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType());
o.setApplicationName("tudou"); o.setApplicationName("tudou");
o.setCode(1); o.setCode(1);
@ -119,20 +121,20 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
}); });
errorCodeMapper.insert(dbErrorCode); errorCodeMapper.insert(dbErrorCode);
// 测试 type 不匹配 // 测试 type 不匹配
errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())));
// 测试 applicationName 不匹配 // 测试 applicationName 不匹配
errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan")));
// 测试 code 不匹配 // 测试 code 不匹配
errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCode(2)));
// 测试 message 不匹配 // 测试 message 不匹配
errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai"))); errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai")));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12)))); errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12))));
return dbErrorCode; return dbErrorCode;
} }
@Test @Test
public void testGetErrorCodeList() { public void testGetErrorCodeList_export() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = initGetErrorCodePage(); ErrorCodeDO dbErrorCode = initGetErrorCodePage();
// 准备参数 // 准备参数
@ -141,7 +143,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
reqVO.setApplicationName("tu"); reqVO.setApplicationName("tu");
reqVO.setCode(1); reqVO.setCode(1);
reqVO.setMessage("ma"); reqVO.setMessage("ma");
reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 11, 1),buildTime(2020, 11, 30)})); reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30));
// 调用 // 调用
List<ErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO); List<ErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO);
@ -155,7 +157,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
// 准备参数 // 准备参数
Integer code = randomInteger(); Integer code = randomInteger();
// mock 数据 // mock 数据
errorCodeMapper.insert(randomInfErrorCodeDO(o -> o.setCode(code))); errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code)));
// 调用校验异常 // 调用校验异常
assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, null), assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, null),
@ -168,7 +170,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
Long id = randomLongId(); Long id = randomLongId();
Integer code = randomInteger(); Integer code = randomInteger();
// mock 数据 // mock 数据
errorCodeMapper.insert(randomInfErrorCodeDO(o -> o.setCode(code))); errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code)));
// 调用校验异常 // 调用校验异常
assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, id), assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, id),
@ -204,7 +206,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
@Test @Test
public void testAutoGenerateErrorCodes_021() { public void testAutoGenerateErrorCodes_021() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())); ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()));
errorCodeMapper.insert(dbErrorCode); errorCodeMapper.insert(dbErrorCode);
// 准备参数 // 准备参数
ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class,
@ -224,7 +226,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
@Test @Test
public void testAutoGenerateErrorCodes_022() { public void testAutoGenerateErrorCodes_022() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()));
errorCodeMapper.insert(dbErrorCode); errorCodeMapper.insert(dbErrorCode);
// 准备参数 // 准备参数
ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class,
@ -244,7 +246,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
@Test @Test
public void testAutoGenerateErrorCodes_023() { public void testAutoGenerateErrorCodes_023() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()));
errorCodeMapper.insert(dbErrorCode); errorCodeMapper.insert(dbErrorCode);
// 准备参数 // 准备参数
ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class,
@ -265,7 +267,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
@Test @Test
public void testAutoGenerateErrorCodes_024() { public void testAutoGenerateErrorCodes_024() {
// mock 数据 // mock 数据
ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()));
errorCodeMapper.insert(dbErrorCode); errorCodeMapper.insert(dbErrorCode);
// 准备参数 // 准备参数
ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class,
@ -279,10 +281,44 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest {
assertPojoEquals(generateReqDTO, errorCode); assertPojoEquals(generateReqDTO, errorCode);
} }
@Test
public void testGetErrorCode() {
// 准备参数
ErrorCodeDO errorCodeDO = randomErrorCodeDO();
errorCodeMapper.insert(errorCodeDO);
// mock 方法
Long id = errorCodeDO.getId();
// 调用
ErrorCodeDO dbErrorCode = errorCodeService.getErrorCode(id);
// 断言
assertPojoEquals(errorCodeDO, dbErrorCode);
}
@Test
public void testGetErrorCodeList() {
// 准备参数
ErrorCodeDO errorCodeDO01 = randomErrorCodeDO(
o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 10)));
errorCodeMapper.insert(errorCodeDO01);
ErrorCodeDO errorCodeDO02 = randomErrorCodeDO(
o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 12)));
errorCodeMapper.insert(errorCodeDO02);
// mock 方法
String applicationName = "yunai_server";
LocalDateTime minUpdateTime = buildTime(2022, 1, 11);
// 调用
List<ErrorCodeRespDTO> errorCodeList = errorCodeService.getErrorCodeList(applicationName, minUpdateTime);
// 断言
assertEquals(1, errorCodeList.size());
assertPojoEquals(errorCodeDO02, errorCodeList.get(0));
}
// ========== 随机对象 ========== // ========== 随机对象 ==========
@SafeVarargs @SafeVarargs
private static ErrorCodeDO randomInfErrorCodeDO(Consumer<ErrorCodeDO>... consumers) { private static ErrorCodeDO randomErrorCodeDO(Consumer<ErrorCodeDO>... consumers) {
Consumer<ErrorCodeDO> consumer = (o) -> { Consumer<ErrorCodeDO> consumer = (o) -> {
o.setType(randomEle(ErrorCodeTypeEnum.values()).getType()); // 保证 key 的范围 o.setType(randomEle(ErrorCodeTypeEnum.values()).getType()); // 保证 key 的范围
}; };