Commit e5957f91339f71acb2be8ef452932451b165e221

Authored by gaibu
1 parent c419c1e1

test: 字典数据模块单元测试

yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml
... ... @@ -39,5 +39,11 @@
39 39 <groupId>com.google.guava</groupId>
40 40 <artifactId>guava</artifactId>
41 41 </dependency>
  42 + <!-- Test 测试相关 -->
  43 + <dependency>
  44 + <groupId>cn.iocoder.boot</groupId>
  45 + <artifactId>yudao-spring-boot-starter-test</artifactId>
  46 + <scope>test</scope>
  47 + </dependency>
42 48 </dependencies>
43 49 </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.framework.test.core.util.RandomUtils;
  6 +import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
  7 +import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
  8 +import org.junit.jupiter.api.BeforeEach;
  9 +import org.junit.jupiter.api.Test;
  10 +import org.mockito.Mock;
  11 +
  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 getDictDataLabelTest() {
  30 + DictDataRespDTO dataRespDTO = randomPojo();
  31 + 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 +
  36 + @Test
  37 + public void parseDictDataValueTest() {
  38 + DictDataRespDTO resp = randomPojo();
  39 + when(dictDataApi.parseDictData(resp.getDictType(), resp.getLabel())).thenReturn(resp);
  40 + String value = DictFrameworkUtils.parseDictDataValue(resp.getDictType(), resp.getLabel());
  41 + assertEquals(resp.getValue(), value);
  42 + }
  43 +
  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 +}
... ...