From 62154773b3ee2ae1a65f9f4a38477b168ed5554c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sat, 14 Mar 2026 16:19:47 +0800 Subject: [PATCH] test: add SysConfigConverter unit tests --- .../db/converter/SysConfigConverterTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/SysConfigConverterTest.java diff --git a/novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/SysConfigConverterTest.java b/novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/SysConfigConverterTest.java new file mode 100644 index 0000000..41b5d62 --- /dev/null +++ b/novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/SysConfigConverterTest.java @@ -0,0 +1,79 @@ +package cn.novalon.manage.db.converter; + +import cn.novalon.manage.sys.core.domain.SysConfig; +import cn.novalon.manage.db.entity.SysConfigEntity; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(MockitoExtension.class) +class SysConfigConverterTest { + + private SysConfigConverter converter; + private SysConfigEntity testEntity; + private SysConfig testDomain; + + @BeforeEach + void setUp() { + converter = new SysConfigConverter(); + + testEntity = new SysConfigEntity(); + testEntity.setId(1L); + testEntity.setConfigName("系统名称"); + testEntity.setConfigKey("system.name"); + testEntity.setConfigValue("Novalon管理系统"); + testEntity.setConfigType("string"); + testEntity.setCreatedAt(LocalDateTime.now()); + testEntity.setUpdatedAt(LocalDateTime.now()); + + testDomain = new SysConfig(); + testDomain.setId(1L); + testDomain.setConfigName("系统名称"); + testDomain.setConfigKey("system.name"); + testDomain.setConfigValue("Novalon管理系统"); + testDomain.setConfigType("string"); + testDomain.setCreatedAt(LocalDateTime.now()); + testDomain.setUpdatedAt(LocalDateTime.now()); + } + + @Test + void testToDomain() { + SysConfig result = converter.toDomain(testEntity); + + assertThat(result).isNotNull(); + assertThat(result.getId()).isEqualTo(testEntity.getId()); + assertThat(result.getConfigName()).isEqualTo(testEntity.getConfigName()); + assertThat(result.getConfigKey()).isEqualTo(testEntity.getConfigKey()); + assertThat(result.getConfigValue()).isEqualTo(testEntity.getConfigValue()); + assertThat(result.getConfigType()).isEqualTo(testEntity.getConfigType()); + } + + @Test + void testToEntity() { + SysConfigEntity result = converter.toEntity(testDomain); + + assertThat(result).isNotNull(); + assertThat(result.getId()).isEqualTo(testDomain.getId()); + assertThat(result.getConfigName()).isEqualTo(testDomain.getConfigName()); + assertThat(result.getConfigKey()).isEqualTo(testDomain.getConfigKey()); + assertThat(result.getConfigValue()).isEqualTo(testDomain.getConfigValue()); + assertThat(result.getConfigType()).isEqualTo(testDomain.getConfigType()); + } + + @Test + void testToDomainWithNull() { + SysConfig result = converter.toDomain(null); + assertThat(result).isNull(); + } + + @Test + void testToEntityWithNull() { + SysConfigEntity result = converter.toEntity(null); + assertThat(result).isNull(); + } +} \ No newline at end of file