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
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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 5 | -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | |
| 6 | 5 | import cn.iocoder.yudao.module.system.api.dict.DictDataApi; |
| 7 | 6 | import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; |
| 8 | 7 | import org.junit.jupiter.api.BeforeEach; |
| 9 | 8 | import org.junit.jupiter.api.Test; |
| 10 | 9 | import org.mockito.Mock; |
| 11 | 10 | |
| 11 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 12 | 12 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 13 | 13 | import static org.mockito.Mockito.when; |
| 14 | 14 | |
| ... | ... | @@ -26,28 +26,23 @@ public class DictFrameworkUtilsTest extends BaseMockitoUnitTest { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 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 | 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 | 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 | 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 | } | ... | ... |