test: add SysDictTypeConverter 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.SysDictType;
|
||||
import cn.novalon.manage.db.entity.SysDictTypeEntity;
|
||||
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 SysDictTypeConverterTest {
|
||||
|
||||
private SysDictTypeConverter converter;
|
||||
private SysDictTypeEntity testEntity;
|
||||
private SysDictType testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysDictTypeConverter();
|
||||
|
||||
testEntity = new SysDictTypeEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setDictName("用户状态");
|
||||
testEntity.setDictType("user_status");
|
||||
testEntity.setStatus("1");
|
||||
testEntity.setRemark("用户状态字典");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysDictType();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setDictName("用户状态");
|
||||
testDomain.setDictType("user_status");
|
||||
testDomain.setStatus("1");
|
||||
testDomain.setRemark("用户状态字典");
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysDictType result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getDictName()).isEqualTo(testEntity.getDictName());
|
||||
assertThat(result.getDictType()).isEqualTo(testEntity.getDictType());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
assertThat(result.getRemark()).isEqualTo(testEntity.getRemark());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysDictTypeEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getDictName()).isEqualTo(testDomain.getDictName());
|
||||
assertThat(result.getDictType()).isEqualTo(testDomain.getDictType());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
assertThat(result.getRemark()).isEqualTo(testDomain.getRemark());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysDictType result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysDictTypeEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user