提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.dict.core.util; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.enums.CommonStatusEnum; |
|
4 |
import com.iailab.framework.dict.core.DictFrameworkUtils; |
|
5 |
import com.iailab.framework.test.core.ut.BaseMockitoUnitTest; |
|
6 |
import com.iailab.module.system.api.dict.DictDataApi; |
|
7 |
import com.iailab.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 com.iailab.framework.common.pojo.CommonResult.success; |
|
13 |
import static com.iailab.framework.test.core.util.RandomUtils.randomPojo; |
|
14 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
15 |
import static org.mockito.Mockito.when; |
|
16 |
|
|
17 |
/** |
|
18 |
* {@link DictFrameworkUtils} 的单元测试 |
|
19 |
*/ |
|
20 |
public class DictFrameworkUtilsTest extends BaseMockitoUnitTest { |
|
21 |
|
|
22 |
@Mock |
|
23 |
private DictDataApi dictDataApi; |
|
24 |
|
|
25 |
@BeforeEach |
|
26 |
public void setUp() { |
|
27 |
DictFrameworkUtils.init(dictDataApi); |
|
28 |
} |
|
29 |
|
|
30 |
@Test |
|
31 |
public void testGetDictDataLabel() { |
|
32 |
// mock 数据 |
|
33 |
DictDataRespDTO dataRespDTO = randomPojo(DictDataRespDTO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); |
|
34 |
// mock 方法 |
|
35 |
when(dictDataApi.getDictData(dataRespDTO.getDictType(), dataRespDTO.getValue())).thenReturn(success(dataRespDTO)); |
|
36 |
|
|
37 |
// 断言返回值 |
|
38 |
assertEquals(dataRespDTO.getLabel(), DictFrameworkUtils.getDictDataLabel(dataRespDTO.getDictType(), dataRespDTO.getValue())); |
|
39 |
} |
|
40 |
|
|
41 |
@Test |
|
42 |
public void testParseDictDataValue() { |
|
43 |
// mock 数据 |
|
44 |
DictDataRespDTO resp = randomPojo(DictDataRespDTO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); |
|
45 |
// mock 方法 |
|
46 |
when(dictDataApi.parseDictData(resp.getDictType(), resp.getLabel())).thenReturn(success(resp)); |
|
47 |
// 断言返回值 |
|
48 |
assertEquals(resp.getValue(), DictFrameworkUtils.parseDictDataValue(resp.getDictType(), resp.getLabel())); |
|
49 |
} |
|
50 |
|
|
51 |
} |