Commit d9121ca8b307642a45e16089963d551f932acc6f
Committed by
Gitee
!423 test: 字典数据模块单元测试
Merge pull request !423 from 与或非/test/dict
Showing
2 changed files
with
55 additions
and
0 deletions
yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml
| @@ -39,5 +39,12 @@ | @@ -39,5 +39,12 @@ | ||
| 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 | + | ||
| 43 | + <!-- Test 测试相关 --> | ||
| 44 | + <dependency> | ||
| 45 | + <groupId>cn.iocoder.boot</groupId> | ||
| 46 | + <artifactId>yudao-spring-boot-starter-test</artifactId> | ||
| 47 | + <scope>test</scope> | ||
| 48 | + </dependency> | ||
| 42 | </dependencies> | 49 | </dependencies> |
| 43 | </project> | 50 | </project> |
yudao-framework/yudao-spring-boot-starter-biz-dict/src/test/java/cn/iocoder/yudao/framework/dict/core/util/DictFrameworkUtilsTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.dict.core.util; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | ||
| 5 | +import cn.iocoder.yudao.module.system.api.dict.DictDataApi; | ||
| 6 | +import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; | ||
| 7 | +import org.junit.jupiter.api.BeforeEach; | ||
| 8 | +import org.junit.jupiter.api.Test; | ||
| 9 | +import org.mockito.Mock; | ||
| 10 | + | ||
| 11 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 12 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 13 | +import static org.mockito.Mockito.when; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * {@link DictFrameworkUtils} 的单元测试 | ||
| 17 | + */ | ||
| 18 | +public class DictFrameworkUtilsTest extends BaseMockitoUnitTest { | ||
| 19 | + | ||
| 20 | + @Mock | ||
| 21 | + private DictDataApi dictDataApi; | ||
| 22 | + | ||
| 23 | + @BeforeEach | ||
| 24 | + public void setUp() { | ||
| 25 | + DictFrameworkUtils.init(dictDataApi); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Test | ||
| 29 | + public void testGetDictDataLabel() { | ||
| 30 | + // mock 数据 | ||
| 31 | + DictDataRespDTO dataRespDTO = randomPojo(DictDataRespDTO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 32 | + // mock 方法 | ||
| 33 | + when(dictDataApi.getDictData(dataRespDTO.getDictType(), dataRespDTO.getValue())).thenReturn(dataRespDTO); | ||
| 34 | + // 断言返回值 | ||
| 35 | + assertEquals(dataRespDTO.getLabel(), DictFrameworkUtils.getDictDataLabel(dataRespDTO.getDictType(), dataRespDTO.getValue())); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + @Test | ||
| 39 | + public void testParseDictDataValue() { | ||
| 40 | + // mock 数据 | ||
| 41 | + DictDataRespDTO resp = randomPojo(DictDataRespDTO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 42 | + // mock 方法 | ||
| 43 | + when(dictDataApi.parseDictData(resp.getDictType(), resp.getLabel())).thenReturn(resp); | ||
| 44 | + // 断言返回值 | ||
| 45 | + assertEquals(resp.getValue(), DictFrameworkUtils.parseDictDataValue(resp.getDictType(), resp.getLabel())); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | +} |