test: add SysUserConverter unit tests
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package cn.novalon.manage.db.converter;
|
||||||
|
|
||||||
|
import cn.novalon.manage.sys.core.domain.SysUser;
|
||||||
|
import cn.novalon.manage.db.entity.SysUserEntity;
|
||||||
|
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 SysUserConverterTest {
|
||||||
|
|
||||||
|
private SysUserConverter converter;
|
||||||
|
private SysUserEntity testEntity;
|
||||||
|
private SysUser testDomain;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
converter = new SysUserConverter();
|
||||||
|
|
||||||
|
testEntity = new SysUserEntity();
|
||||||
|
testEntity.setId(1L);
|
||||||
|
testEntity.setUsername("testuser");
|
||||||
|
testEntity.setPassword("encoded_password");
|
||||||
|
testEntity.setEmail("test@example.com");
|
||||||
|
testEntity.setRoleId(1L);
|
||||||
|
testEntity.setStatus(1);
|
||||||
|
testEntity.setCreatedAt(LocalDateTime.now());
|
||||||
|
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||||
|
|
||||||
|
testDomain = new SysUser();
|
||||||
|
testDomain.setId(1L);
|
||||||
|
testDomain.setUsername("testuser");
|
||||||
|
testDomain.setPassword("encoded_password");
|
||||||
|
testDomain.setEmail("test@example.com");
|
||||||
|
testDomain.setRoleId(1L);
|
||||||
|
testDomain.setStatus(1);
|
||||||
|
testDomain.setCreatedAt(LocalDateTime.now());
|
||||||
|
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToDomain() {
|
||||||
|
SysUser result = converter.toDomain(testEntity);
|
||||||
|
|
||||||
|
assertThat(result).isNotNull();
|
||||||
|
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||||
|
assertThat(result.getUsername()).isEqualTo(testEntity.getUsername());
|
||||||
|
assertThat(result.getPassword()).isEqualTo(testEntity.getPassword());
|
||||||
|
assertThat(result.getEmail()).isEqualTo(testEntity.getEmail());
|
||||||
|
assertThat(result.getRoleId()).isEqualTo(testEntity.getRoleId());
|
||||||
|
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToEntity() {
|
||||||
|
SysUserEntity result = converter.toEntity(testDomain);
|
||||||
|
|
||||||
|
assertThat(result).isNotNull();
|
||||||
|
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||||
|
assertThat(result.getUsername()).isEqualTo(testDomain.getUsername());
|
||||||
|
assertThat(result.getPassword()).isEqualTo(testDomain.getPassword());
|
||||||
|
assertThat(result.getEmail()).isEqualTo(testDomain.getEmail());
|
||||||
|
assertThat(result.getRoleId()).isEqualTo(testDomain.getRoleId());
|
||||||
|
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToDomainWithNull() {
|
||||||
|
SysUser result = converter.toDomain(null);
|
||||||
|
assertThat(result).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToEntityWithNull() {
|
||||||
|
SysUserEntity result = converter.toEntity(null);
|
||||||
|
assertThat(result).isNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user