mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	完善 SensitiveWordServiceImpl 单元测试
This commit is contained in:
		| @@ -16,13 +16,12 @@ import org.springframework.boot.test.mock.mockito.MockBean; | ||||
| import org.springframework.context.annotation.Import; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||||
| import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | ||||
| import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||||
| import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; | ||||
| import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||||
| import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | ||||
| import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | ||||
| @@ -135,6 +134,36 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||||
|         assertServiceException(() -> sensitiveWordService.deleteSensitiveWord(id), SENSITIVE_WORD_NOT_EXISTS); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testGetSensitiveWord() { | ||||
|         // mock 数据 | ||||
|         SensitiveWordDO sensitiveWord = randomPojo(SensitiveWordDO.class); | ||||
|         sensitiveWordMapper.insert(sensitiveWord); | ||||
|         // 准备参数 | ||||
|         Long id = sensitiveWord.getId(); | ||||
|  | ||||
|         // 调用 | ||||
|         SensitiveWordDO dbSensitiveWord = sensitiveWordService.getSensitiveWord(id); | ||||
|         // 断言 | ||||
|         assertPojoEquals(sensitiveWord, dbSensitiveWord); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testGetSensitiveWordList() { | ||||
|         // mock 数据 | ||||
|         SensitiveWordDO sensitiveWord01 = randomPojo(SensitiveWordDO.class); | ||||
|         sensitiveWordMapper.insert(sensitiveWord01); | ||||
|         SensitiveWordDO sensitiveWord02 = randomPojo(SensitiveWordDO.class); | ||||
|         sensitiveWordMapper.insert(sensitiveWord02); | ||||
|  | ||||
|         // 调用 | ||||
|         List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(); | ||||
|         // 断言 | ||||
|         assertEquals(2, list.size()); | ||||
|         assertEquals(sensitiveWord01, list.get(0)); | ||||
|         assertEquals(sensitiveWord02, list.get(1)); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testGetSensitiveWordPage() { | ||||
|         // mock 数据 | ||||
| @@ -156,7 +185,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||||
|         reqVO.setName("笨"); | ||||
|         reqVO.setTag("论坛"); | ||||
|         reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||||
|         reqVO.setCreateTime((new LocalDateTime[]{buildTime(2022, 2, 1),buildTime(2022, 2, 12)})); | ||||
|         reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); | ||||
|  | ||||
|         // 调用 | ||||
|         PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(reqVO); | ||||
| @@ -167,7 +196,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testGetSensitiveWordList() { | ||||
|     public void testGetSensitiveWordList_export() { | ||||
|         // mock 数据 | ||||
|         SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class, o -> { // 等会查询到 | ||||
|             o.setName("笨蛋"); | ||||
| @@ -187,7 +216,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||||
|         reqVO.setName("笨"); | ||||
|         reqVO.setTag("论坛"); | ||||
|         reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||||
|         reqVO.setCreateTime((new LocalDateTime[]{buildTime(2022, 2, 1),buildTime(2022, 2, 12)})); | ||||
|         reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); | ||||
|  | ||||
|         // 调用 | ||||
|         List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(reqVO); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV