Commit 2083fb78466938a3f0ca6250cbfc3b0139524e53
1 parent
e5957f91
test: 修改 code review
Showing
2 changed files
with
14 additions
and
18 deletions
yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml
| @@ -39,6 +39,7 @@ | @@ -39,6 +39,7 @@ | ||
| 39 | <groupId>com.google.guava</groupId> | 39 | <groupId>com.google.guava</groupId> |
| 40 | <artifactId>guava</artifactId> | 40 | <artifactId>guava</artifactId> |
| 41 | </dependency> | 41 | </dependency> |
| 42 | + | ||
| 42 | <!-- Test 测试相关 --> | 43 | <!-- Test 测试相关 --> |
| 43 | <dependency> | 44 | <dependency> |
| 44 | <groupId>cn.iocoder.boot</groupId> | 45 | <groupId>cn.iocoder.boot</groupId> |
yudao-framework/yudao-spring-boot-starter-biz-dict/src/test/java/cn/iocoder/yudao/framework/dict/core/util/DictFrameworkUtilsTest.java
| @@ -2,13 +2,13 @@ package cn.iocoder.yudao.framework.dict.core.util; | @@ -2,13 +2,13 @@ package cn.iocoder.yudao.framework.dict.core.util; | ||
| 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.test.core.ut.BaseMockitoUnitTest; | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 5 | -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 6 | import cn.iocoder.yudao.module.system.api.dict.DictDataApi; | 5 | import cn.iocoder.yudao.module.system.api.dict.DictDataApi; |
| 7 | import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; | 6 | import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; |
| 8 | import org.junit.jupiter.api.BeforeEach; | 7 | import org.junit.jupiter.api.BeforeEach; |
| 9 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
| 10 | import org.mockito.Mock; | 9 | import org.mockito.Mock; |
| 11 | 10 | ||
| 11 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 12 | import static org.junit.jupiter.api.Assertions.assertEquals; | 12 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 13 | import static org.mockito.Mockito.when; | 13 | import static org.mockito.Mockito.when; |
| 14 | 14 | ||
| @@ -26,28 +26,23 @@ public class DictFrameworkUtilsTest extends BaseMockitoUnitTest { | @@ -26,28 +26,23 @@ public class DictFrameworkUtilsTest extends BaseMockitoUnitTest { | ||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | @Test | 28 | @Test |
| 29 | - public void getDictDataLabelTest() { | ||
| 30 | - DictDataRespDTO dataRespDTO = randomPojo(); | 29 | + public void testGetDictDataLabel() { |
| 30 | + // mock 数据 | ||
| 31 | + DictDataRespDTO dataRespDTO = randomPojo(DictDataRespDTO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 32 | + // mock 方法 | ||
| 31 | when(dictDataApi.getDictData(dataRespDTO.getDictType(), dataRespDTO.getValue())).thenReturn(dataRespDTO); | 33 | when(dictDataApi.getDictData(dataRespDTO.getDictType(), dataRespDTO.getValue())).thenReturn(dataRespDTO); |
| 32 | - String dictDataLabel = DictFrameworkUtils.getDictDataLabel(dataRespDTO.getDictType(), dataRespDTO.getValue()); | ||
| 33 | - assertEquals(dataRespDTO.getLabel(), dictDataLabel); | 34 | + // 断言返回值 |
| 35 | + assertEquals(dataRespDTO.getLabel(), DictFrameworkUtils.getDictDataLabel(dataRespDTO.getDictType(), dataRespDTO.getValue())); | ||
| 34 | } | 36 | } |
| 35 | 37 | ||
| 36 | @Test | 38 | @Test |
| 37 | - public void parseDictDataValueTest() { | ||
| 38 | - DictDataRespDTO resp = randomPojo(); | 39 | + public void testParseDictDataValue() { |
| 40 | + // mock 数据 | ||
| 41 | + DictDataRespDTO resp = randomPojo(DictDataRespDTO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 42 | + // mock 方法 | ||
| 39 | when(dictDataApi.parseDictData(resp.getDictType(), resp.getLabel())).thenReturn(resp); | 43 | when(dictDataApi.parseDictData(resp.getDictType(), resp.getLabel())).thenReturn(resp); |
| 40 | - String value = DictFrameworkUtils.parseDictDataValue(resp.getDictType(), resp.getLabel()); | ||
| 41 | - assertEquals(resp.getValue(), value); | 44 | + // 断言返回值 |
| 45 | + assertEquals(resp.getValue(), DictFrameworkUtils.parseDictDataValue(resp.getDictType(), resp.getLabel())); | ||
| 42 | } | 46 | } |
| 43 | 47 | ||
| 44 | - private DictDataRespDTO randomPojo() { | ||
| 45 | - DictDataRespDTO dataRespDTO = new DictDataRespDTO(); | ||
| 46 | - dataRespDTO.setLabel(RandomUtils.randomString()); | ||
| 47 | - dataRespDTO.setValue(RandomUtils.randomString()); | ||
| 48 | - dataRespDTO.setDictType(RandomUtils.randomString()); | ||
| 49 | - dataRespDTO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 50 | - | ||
| 51 | - return dataRespDTO; | ||
| 52 | - } | ||
| 53 | } | 48 | } |