test: add SysConfigConverter unit tests
This commit is contained in:
+79
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user