test: add DictionaryConverter unit tests
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package cn.novalon.manage.db.converter;
|
||||||
|
|
||||||
|
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||||
|
import cn.novalon.manage.db.entity.DictionaryEntity;
|
||||||
|
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 DictionaryConverterTest {
|
||||||
|
|
||||||
|
private DictionaryConverter converter;
|
||||||
|
private DictionaryEntity testEntity;
|
||||||
|
private Dictionary testDomain;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
converter = new DictionaryConverter();
|
||||||
|
|
||||||
|
testEntity = new DictionaryEntity();
|
||||||
|
testEntity.setId(1L);
|
||||||
|
testEntity.setType("user_status");
|
||||||
|
testEntity.setCode("active");
|
||||||
|
testEntity.setName("正常");
|
||||||
|
testEntity.setValue("0");
|
||||||
|
testEntity.setRemark("用户正常状态");
|
||||||
|
testEntity.setSort(1);
|
||||||
|
testEntity.setCreateBy("admin");
|
||||||
|
testEntity.setCreatedAt(LocalDateTime.now());
|
||||||
|
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||||
|
|
||||||
|
testDomain = new Dictionary();
|
||||||
|
testDomain.setId(1L);
|
||||||
|
testDomain.setType("user_status");
|
||||||
|
testDomain.setCode("active");
|
||||||
|
testDomain.setName("正常");
|
||||||
|
testDomain.setValue("0");
|
||||||
|
testDomain.setRemark("用户正常状态");
|
||||||
|
testDomain.setSort(1);
|
||||||
|
testDomain.setCreateBy("admin");
|
||||||
|
testDomain.setCreatedAt(LocalDateTime.now());
|
||||||
|
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToDomain() {
|
||||||
|
Dictionary result = converter.toDomain(testEntity);
|
||||||
|
|
||||||
|
assertThat(result).isNotNull();
|
||||||
|
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||||
|
assertThat(result.getType()).isEqualTo(testEntity.getType());
|
||||||
|
assertThat(result.getCode()).isEqualTo(testEntity.getCode());
|
||||||
|
assertThat(result.getName()).isEqualTo(testEntity.getName());
|
||||||
|
assertThat(result.getValue()).isEqualTo(testEntity.getValue());
|
||||||
|
assertThat(result.getRemark()).isEqualTo(testEntity.getRemark());
|
||||||
|
assertThat(result.getSort()).isEqualTo(testEntity.getSort());
|
||||||
|
assertThat(result.getCreateBy()).isEqualTo(testEntity.getCreateBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToEntity() {
|
||||||
|
DictionaryEntity result = converter.toEntity(testDomain);
|
||||||
|
|
||||||
|
assertThat(result).isNotNull();
|
||||||
|
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||||
|
assertThat(result.getType()).isEqualTo(testDomain.getType());
|
||||||
|
assertThat(result.getCode()).isEqualTo(testDomain.getCode());
|
||||||
|
assertThat(result.getName()).isEqualTo(testDomain.getName());
|
||||||
|
assertThat(result.getValue()).isEqualTo(testDomain.getValue());
|
||||||
|
assertThat(result.getRemark()).isEqualTo(testDomain.getRemark());
|
||||||
|
assertThat(result.getSort()).isEqualTo(testDomain.getSort());
|
||||||
|
assertThat(result.getCreateBy()).isEqualTo(testDomain.getCreateBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToDomainWithNull() {
|
||||||
|
Dictionary result = converter.toDomain(null);
|
||||||
|
assertThat(result).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToEntityWithNull() {
|
||||||
|
DictionaryEntity result = converter.toEntity(null);
|
||||||
|
assertThat(result).isNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user