This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UserTest): basic implementation of UserTest created
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/com/example/comerce/core/entities/UserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.example.comerce.core.entities; | ||
|
||
import com.example.comerce.shared.helpers.validators.entities.UUIDValidator; | ||
import jakarta.validation.Validation; | ||
import jakarta.validation.Validator; | ||
import jakarta.validation.ValidatorFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public final class UserTest { | ||
private final User globalUser = new User(); | ||
private Validator validator; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
final ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); | ||
validator = (Validator) factory.getValidator(); | ||
final UUID userId = UUID.randomUUID(); | ||
globalUser.setUser_id(userId); | ||
globalUser.setName("Alessandro Lima"); | ||
globalUser.setEmail("[email protected]"); | ||
globalUser.setCpf("12345678901"); | ||
globalUser.setTelephone("12345678901"); | ||
globalUser.setPassword("123456"); | ||
} | ||
|
||
@Test | ||
public void testUser() { | ||
final User user = new User(); | ||
|
||
final UUID userId = UUID.randomUUID(); | ||
user.setUser_id(userId); | ||
user.setName("Alessandro Lima"); | ||
user.setEmail("[email protected]"); | ||
user.setCpf("12345678901"); | ||
user.setTelephone("12345678901"); | ||
user.setPassword("123456"); | ||
|
||
assertEquals(userId, user.getUser_id()); | ||
assertEquals("Alessandro Lima", user.getName()); | ||
assertEquals("[email protected]" , user.getEmail()); | ||
assertEquals("12345678901", user.getCpf()); | ||
assertEquals("12345678901", user.getTelephone()); | ||
assertEquals("123456", user.getPassword()); | ||
} | ||
|
||
@Test | ||
public void testInvalidUserId() { | ||
String userId = !UUIDValidator | ||
.validateUUID("userId", "123e4567-e89b-12d3-a456-42661417400") | ||
? "UUID inválido" : "UUID válido"; | ||
assertEquals("UUID inválido", userId); | ||
} | ||
} |