Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
feat(UserTest): basic implementation of UserTest created
Browse files Browse the repository at this point in the history
  • Loading branch information
alexZ7000 committed Oct 11, 2024
1 parent 3f84fc8 commit 02fec40
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/main/java/com/example/comerce/core/entities/User.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.comerce.core.entities;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import lombok.Getter;
import lombok.Setter;

Expand Down
59 changes: 59 additions & 0 deletions src/test/java/com/example/comerce/core/entities/UserTest.java
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);
}
}

0 comments on commit 02fec40

Please sign in to comment.