Commit fed9feb05fa69ec35a7209c1bda0bcf394bccf91
1 parent
05374216
完善 DictTypeServiceImpl 单元测试
Showing
3 changed files
with
85 additions
and
46 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
| @@ -41,6 +41,11 @@ public class LocalDateTimeUtils { | @@ -41,6 +41,11 @@ public class LocalDateTimeUtils { | ||
| 41 | return LocalDateTime.of(year, mouth, day, 0, 0, 0); | 41 | return LocalDateTime.of(year, mouth, day, 0, 0, 0); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | + public static LocalDateTime[] buildBetweenTime(int year1, int mouth1, int day1, | ||
| 45 | + int year2, int mouth2, int day2) { | ||
| 46 | + return new LocalDateTime[]{buildTime(year1, mouth1, day1), buildTime(year2, mouth2, day2)}; | ||
| 47 | + } | ||
| 48 | + | ||
| 44 | /** | 49 | /** |
| 45 | * 判断当前时间是否在该时间范围内 | 50 | * 判断当前时间是否在该时间范围内 |
| 46 | * | 51 | * |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java
| @@ -57,7 +57,8 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -57,7 +57,8 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 57 | @Override | 57 | @Override |
| 58 | public Long createDictType(DictTypeCreateReqVO reqVO) { | 58 | public Long createDictType(DictTypeCreateReqVO reqVO) { |
| 59 | // 校验正确性 | 59 | // 校验正确性 |
| 60 | - checkCreateOrUpdate(null, reqVO.getName(), reqVO.getType()); | 60 | + validateDictTypeForCreateOrUpdate(null, reqVO.getName(), reqVO.getType()); |
| 61 | + | ||
| 61 | // 插入字典类型 | 62 | // 插入字典类型 |
| 62 | DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO) | 63 | DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO) |
| 63 | .setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值 | 64 | .setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值 |
| @@ -68,7 +69,8 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -68,7 +69,8 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 68 | @Override | 69 | @Override |
| 69 | public void updateDictType(DictTypeUpdateReqVO reqVO) { | 70 | public void updateDictType(DictTypeUpdateReqVO reqVO) { |
| 70 | // 校验正确性 | 71 | // 校验正确性 |
| 71 | - checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); | 72 | + validateDictTypeForCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); |
| 73 | + | ||
| 72 | // 更新字典类型 | 74 | // 更新字典类型 |
| 73 | DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO); | 75 | DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO); |
| 74 | dictTypeMapper.updateById(updateObj); | 76 | dictTypeMapper.updateById(updateObj); |
| @@ -77,7 +79,7 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -77,7 +79,7 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 77 | @Override | 79 | @Override |
| 78 | public void deleteDictType(Long id) { | 80 | public void deleteDictType(Long id) { |
| 79 | // 校验是否存在 | 81 | // 校验是否存在 |
| 80 | - DictTypeDO dictType = checkDictTypeExists(id); | 82 | + DictTypeDO dictType = validateDictTypeExists(id); |
| 81 | // 校验是否有字典数据 | 83 | // 校验是否有字典数据 |
| 82 | if (dictDataService.countByDictType(dictType.getType()) > 0) { | 84 | if (dictDataService.countByDictType(dictType.getType()) > 0) { |
| 83 | throw exception(DICT_TYPE_HAS_CHILDREN); | 85 | throw exception(DICT_TYPE_HAS_CHILDREN); |
| @@ -91,17 +93,17 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -91,17 +93,17 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 91 | return dictTypeMapper.selectList(); | 93 | return dictTypeMapper.selectList(); |
| 92 | } | 94 | } |
| 93 | 95 | ||
| 94 | - private void checkCreateOrUpdate(Long id, String name, String type) { | 96 | + private void validateDictTypeForCreateOrUpdate(Long id, String name, String type) { |
| 95 | // 校验自己存在 | 97 | // 校验自己存在 |
| 96 | - checkDictTypeExists(id); | 98 | + validateDictTypeExists(id); |
| 97 | // 校验字典类型的名字的唯一性 | 99 | // 校验字典类型的名字的唯一性 |
| 98 | - checkDictTypeNameUnique(id, name); | 100 | + validateDictTypeNameUnique(id, name); |
| 99 | // 校验字典类型的类型的唯一性 | 101 | // 校验字典类型的类型的唯一性 |
| 100 | - checkDictTypeUnique(id, type); | 102 | + validateDictTypeUnique(id, type); |
| 101 | } | 103 | } |
| 102 | 104 | ||
| 103 | @VisibleForTesting | 105 | @VisibleForTesting |
| 104 | - public void checkDictTypeNameUnique(Long id, String name) { | 106 | + void validateDictTypeNameUnique(Long id, String name) { |
| 105 | DictTypeDO dictType = dictTypeMapper.selectByName(name); | 107 | DictTypeDO dictType = dictTypeMapper.selectByName(name); |
| 106 | if (dictType == null) { | 108 | if (dictType == null) { |
| 107 | return; | 109 | return; |
| @@ -116,7 +118,7 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -116,7 +118,7 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 116 | } | 118 | } |
| 117 | 119 | ||
| 118 | @VisibleForTesting | 120 | @VisibleForTesting |
| 119 | - public void checkDictTypeUnique(Long id, String type) { | 121 | + void validateDictTypeUnique(Long id, String type) { |
| 120 | if (StrUtil.isEmpty(type)) { | 122 | if (StrUtil.isEmpty(type)) { |
| 121 | return; | 123 | return; |
| 122 | } | 124 | } |
| @@ -134,7 +136,7 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -134,7 +136,7 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | @VisibleForTesting | 138 | @VisibleForTesting |
| 137 | - public DictTypeDO checkDictTypeExists(Long id) { | 139 | + DictTypeDO validateDictTypeExists(Long id) { |
| 138 | if (id == null) { | 140 | if (id == null) { |
| 139 | return null; | 141 | return null; |
| 140 | } | 142 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java renamed to yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java
| @@ -2,36 +2,36 @@ package cn.iocoder.yudao.module.system.service.dict; | @@ -2,36 +2,36 @@ package cn.iocoder.yudao.module.system.service.dict; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 6 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 5 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; | ||
| 7 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; |
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; |
| 11 | -import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 12 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 13 | -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 14 | import org.junit.jupiter.api.Test; | 13 | import org.junit.jupiter.api.Test; |
| 15 | import org.springframework.boot.test.mock.mockito.MockBean; | 14 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 16 | import org.springframework.context.annotation.Import; | 15 | import org.springframework.context.annotation.Import; |
| 17 | 16 | ||
| 18 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 19 | -import java.time.LocalDateTime; | ||
| 20 | import java.util.List; | 18 | import java.util.List; |
| 21 | import java.util.function.Consumer; | 19 | import java.util.function.Consumer; |
| 22 | 20 | ||
| 23 | import static cn.hutool.core.util.RandomUtil.randomEle; | 21 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 24 | -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 22 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| 23 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | ||
| 24 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 27 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | ||
| 28 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 28 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | ||
| 29 | import static org.junit.jupiter.api.Assertions.*; | 29 | import static org.junit.jupiter.api.Assertions.*; |
| 30 | import static org.mockito.ArgumentMatchers.eq; | 30 | import static org.mockito.ArgumentMatchers.eq; |
| 31 | import static org.mockito.Mockito.when; | 31 | import static org.mockito.Mockito.when; |
| 32 | 32 | ||
| 33 | @Import(DictTypeServiceImpl.class) | 33 | @Import(DictTypeServiceImpl.class) |
| 34 | -public class DictTypeServiceTest extends BaseDbUnitTest { | 34 | +public class DictTypeServiceImplTest extends BaseDbUnitTest { |
| 35 | 35 | ||
| 36 | @Resource | 36 | @Resource |
| 37 | private DictTypeServiceImpl dictTypeService; | 37 | private DictTypeServiceImpl dictTypeService; |
| @@ -52,19 +52,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -52,19 +52,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 52 | }); | 52 | }); |
| 53 | dictTypeMapper.insert(dbDictType); | 53 | dictTypeMapper.insert(dbDictType); |
| 54 | // 测试 name 不匹配 | 54 | // 测试 name 不匹配 |
| 55 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); | 55 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); |
| 56 | // 测试 type 不匹配 | 56 | // 测试 type 不匹配 |
| 57 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); | 57 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); |
| 58 | // 测试 status 不匹配 | 58 | // 测试 status 不匹配 |
| 59 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 59 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 60 | // 测试 createTime 不匹配 | 60 | // 测试 createTime 不匹配 |
| 61 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | 61 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |
| 62 | // 准备参数 | 62 | // 准备参数 |
| 63 | DictTypePageReqVO reqVO = new DictTypePageReqVO(); | 63 | DictTypePageReqVO reqVO = new DictTypePageReqVO(); |
| 64 | reqVO.setName("nai"); | 64 | reqVO.setName("nai"); |
| 65 | reqVO.setType("艿"); | 65 | reqVO.setType("艿"); |
| 66 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 66 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 67 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 10),buildTime(2021, 1, 20)})); | 67 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20)); |
| 68 | 68 | ||
| 69 | // 调用 | 69 | // 调用 |
| 70 | PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO); | 70 | PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO); |
| @@ -75,7 +75,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -75,7 +75,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | @Test | 77 | @Test |
| 78 | - public void testGetDictTypeList() { | 78 | + public void testGetDictTypeList_export() { |
| 79 | // mock 数据 | 79 | // mock 数据 |
| 80 | DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到 | 80 | DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到 |
| 81 | o.setName("yunai"); | 81 | o.setName("yunai"); |
| @@ -85,19 +85,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -85,19 +85,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 85 | }); | 85 | }); |
| 86 | dictTypeMapper.insert(dbDictType); | 86 | dictTypeMapper.insert(dbDictType); |
| 87 | // 测试 name 不匹配 | 87 | // 测试 name 不匹配 |
| 88 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); | 88 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); |
| 89 | // 测试 type 不匹配 | 89 | // 测试 type 不匹配 |
| 90 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); | 90 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); |
| 91 | // 测试 status 不匹配 | 91 | // 测试 status 不匹配 |
| 92 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 92 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 93 | // 测试 createTime 不匹配 | 93 | // 测试 createTime 不匹配 |
| 94 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | 94 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |
| 95 | // 准备参数 | 95 | // 准备参数 |
| 96 | DictTypeExportReqVO reqVO = new DictTypeExportReqVO(); | 96 | DictTypeExportReqVO reqVO = new DictTypeExportReqVO(); |
| 97 | reqVO.setName("nai"); | 97 | reqVO.setName("nai"); |
| 98 | reqVO.setType("艿"); | 98 | reqVO.setType("艿"); |
| 99 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 99 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 100 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 10),buildTime(2021, 1, 20)})); | 100 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20)); |
| 101 | 101 | ||
| 102 | // 调用 | 102 | // 调用 |
| 103 | List<DictTypeDO> list = dictTypeService.getDictTypeList(reqVO); | 103 | List<DictTypeDO> list = dictTypeService.getDictTypeList(reqVO); |
| @@ -107,7 +107,22 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -107,7 +107,22 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | @Test | 109 | @Test |
| 110 | - public void testGetDictType() { | 110 | + public void testGetDictType_id() { |
| 111 | + // mock 数据 | ||
| 112 | + DictTypeDO dbDictType = randomDictTypeDO(); | ||
| 113 | + dictTypeMapper.insert(dbDictType); | ||
| 114 | + // 准备参数 | ||
| 115 | + Long id = dbDictType.getId(); | ||
| 116 | + | ||
| 117 | + // 调用 | ||
| 118 | + DictTypeDO dictType = dictTypeService.getDictType(id); | ||
| 119 | + // 断言 | ||
| 120 | + assertNotNull(dictType); | ||
| 121 | + assertPojoEquals(dbDictType, dictType); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Test | ||
| 125 | + public void testGetDictType_type() { | ||
| 111 | // mock 数据 | 126 | // mock 数据 |
| 112 | DictTypeDO dbDictType = randomDictTypeDO(); | 127 | DictTypeDO dbDictType = randomDictTypeDO(); |
| 113 | dictTypeMapper.insert(dbDictType); | 128 | dictTypeMapper.insert(dbDictType); |
| @@ -183,40 +198,57 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -183,40 +198,57 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 183 | } | 198 | } |
| 184 | 199 | ||
| 185 | @Test | 200 | @Test |
| 186 | - public void testCheckDictDataExists_success() { | 201 | + public void testGetDictTypeList() { |
| 202 | + // 准备参数 | ||
| 203 | + DictTypeDO dictTypeDO01 = randomDictTypeDO(); | ||
| 204 | + dictTypeMapper.insert(dictTypeDO01); | ||
| 205 | + DictTypeDO dictTypeDO02 = randomDictTypeDO(); | ||
| 206 | + dictTypeMapper.insert(dictTypeDO02); | ||
| 207 | + // mock 方法 | ||
| 208 | + | ||
| 209 | + // 调用 | ||
| 210 | + List<DictTypeDO> dictTypeDOList = dictTypeService.getDictTypeList(); | ||
| 211 | + // 断言 | ||
| 212 | + assertEquals(2, dictTypeDOList.size()); | ||
| 213 | + assertPojoEquals(dictTypeDO01, dictTypeDOList.get(0)); | ||
| 214 | + assertPojoEquals(dictTypeDO02, dictTypeDOList.get(1)); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + @Test | ||
| 218 | + public void testValidateDictDataExists_success() { | ||
| 187 | // mock 数据 | 219 | // mock 数据 |
| 188 | DictTypeDO dbDictType = randomDictTypeDO(); | 220 | DictTypeDO dbDictType = randomDictTypeDO(); |
| 189 | dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据 | 221 | dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据 |
| 190 | 222 | ||
| 191 | // 调用成功 | 223 | // 调用成功 |
| 192 | - dictTypeService.checkDictTypeExists(dbDictType.getId()); | 224 | + dictTypeService.validateDictTypeExists(dbDictType.getId()); |
| 193 | } | 225 | } |
| 194 | 226 | ||
| 195 | @Test | 227 | @Test |
| 196 | - public void testCheckDictDataExists_notExists() { | ||
| 197 | - assertServiceException(() -> dictTypeService.checkDictTypeExists(randomLongId()), DICT_TYPE_NOT_EXISTS); | 228 | + public void testValidateDictDataExists_notExists() { |
| 229 | + assertServiceException(() -> dictTypeService.validateDictTypeExists(randomLongId()), DICT_TYPE_NOT_EXISTS); | ||
| 198 | } | 230 | } |
| 199 | 231 | ||
| 200 | @Test | 232 | @Test |
| 201 | - public void testCheckDictTypeUnique_success() { | 233 | + public void testValidateDictTypeUnique_success() { |
| 202 | // 调用,成功 | 234 | // 调用,成功 |
| 203 | - dictTypeService.checkDictTypeUnique(randomLongId(), randomString()); | 235 | + dictTypeService.validateDictTypeUnique(randomLongId(), randomString()); |
| 204 | } | 236 | } |
| 205 | 237 | ||
| 206 | @Test | 238 | @Test |
| 207 | - public void testCheckDictTypeUnique_valueDuplicateForCreate() { | 239 | + public void testValidateDictTypeUnique_valueDuplicateForCreate() { |
| 208 | // 准备参数 | 240 | // 准备参数 |
| 209 | String type = randomString(); | 241 | String type = randomString(); |
| 210 | // mock 数据 | 242 | // mock 数据 |
| 211 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); | 243 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); |
| 212 | 244 | ||
| 213 | // 调用,校验异常 | 245 | // 调用,校验异常 |
| 214 | - assertServiceException(() -> dictTypeService.checkDictTypeUnique(null, type), | 246 | + assertServiceException(() -> dictTypeService.validateDictTypeUnique(null, type), |
| 215 | DICT_TYPE_TYPE_DUPLICATE); | 247 | DICT_TYPE_TYPE_DUPLICATE); |
| 216 | } | 248 | } |
| 217 | 249 | ||
| 218 | @Test | 250 | @Test |
| 219 | - public void testCheckDictTypeUnique_valueDuplicateForUpdate() { | 251 | + public void testValidateDictTypeUnique_valueDuplicateForUpdate() { |
| 220 | // 准备参数 | 252 | // 准备参数 |
| 221 | Long id = randomLongId(); | 253 | Long id = randomLongId(); |
| 222 | String type = randomString(); | 254 | String type = randomString(); |
| @@ -224,30 +256,30 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -224,30 +256,30 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 224 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); | 256 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); |
| 225 | 257 | ||
| 226 | // 调用,校验异常 | 258 | // 调用,校验异常 |
| 227 | - assertServiceException(() -> dictTypeService.checkDictTypeUnique(id, type), | 259 | + assertServiceException(() -> dictTypeService.validateDictTypeUnique(id, type), |
| 228 | DICT_TYPE_TYPE_DUPLICATE); | 260 | DICT_TYPE_TYPE_DUPLICATE); |
| 229 | } | 261 | } |
| 230 | 262 | ||
| 231 | @Test | 263 | @Test |
| 232 | - public void testCheckDictTypNameUnique_success() { | 264 | + public void testValidateDictTypNameUnique_success() { |
| 233 | // 调用,成功 | 265 | // 调用,成功 |
| 234 | - dictTypeService.checkDictTypeNameUnique(randomLongId(), randomString()); | 266 | + dictTypeService.validateDictTypeNameUnique(randomLongId(), randomString()); |
| 235 | } | 267 | } |
| 236 | 268 | ||
| 237 | @Test | 269 | @Test |
| 238 | - public void testCheckDictTypeNameUnique_nameDuplicateForCreate() { | 270 | + public void testValidateDictTypeNameUnique_nameDuplicateForCreate() { |
| 239 | // 准备参数 | 271 | // 准备参数 |
| 240 | String name = randomString(); | 272 | String name = randomString(); |
| 241 | // mock 数据 | 273 | // mock 数据 |
| 242 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); | 274 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); |
| 243 | 275 | ||
| 244 | // 调用,校验异常 | 276 | // 调用,校验异常 |
| 245 | - assertServiceException(() -> dictTypeService.checkDictTypeNameUnique(null, name), | 277 | + assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(null, name), |
| 246 | DICT_TYPE_NAME_DUPLICATE); | 278 | DICT_TYPE_NAME_DUPLICATE); |
| 247 | } | 279 | } |
| 248 | 280 | ||
| 249 | @Test | 281 | @Test |
| 250 | - public void testCheckDictTypeNameUnique_nameDuplicateForUpdate() { | 282 | + public void testValidateDictTypeNameUnique_nameDuplicateForUpdate() { |
| 251 | // 准备参数 | 283 | // 准备参数 |
| 252 | Long id = randomLongId(); | 284 | Long id = randomLongId(); |
| 253 | String name = randomString(); | 285 | String name = randomString(); |
| @@ -255,7 +287,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -255,7 +287,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 255 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); | 287 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); |
| 256 | 288 | ||
| 257 | // 调用,校验异常 | 289 | // 调用,校验异常 |
| 258 | - assertServiceException(() -> dictTypeService.checkDictTypeNameUnique(id, name), | 290 | + assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(id, name), |
| 259 | DICT_TYPE_NAME_DUPLICATE); | 291 | DICT_TYPE_NAME_DUPLICATE); |
| 260 | } | 292 | } |
| 261 | 293 |