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

Commit

Permalink
fix: correcting User unit test and Validations in DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
alexZ7000 committed Oct 15, 2024
1 parent aa2e1f7 commit 5086135
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/example/comerce/core/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public final class UserDTO {
@Size(min = 11, max = 11, message = "Telefone deve ter 11 caracteres")
private String telephone;

@NotBlank(message = "CPF não pode estar em branco")
@Size(min = 11, max = 11, message = "CPF deve ter 11 caracteres")
private String cpf;

@NotBlank(message = "Email não pode estar em branco")
@Email(message = "E-mail inválido")
private String email;

@NotBlank(message = "Senha não pode estar em branco")
@Size(min = 6, max = 255, message = "Senha deve ter no mínimo 6 e no máximo 255 caracteres")
private String password;

Expand Down
13 changes: 0 additions & 13 deletions src/test/java/com/example/comerce/ComerceApplicationTests.java

This file was deleted.

12 changes: 6 additions & 6 deletions src/test/java/com/example/comerce/core/entities/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public void testInvalidEmail() {
@Test
public void testInvalidCpf() {
// Teste 1: CPF em branco
globalUser.setCpf("");
globalUser.setCpf(" ");
Map<String, String> violationMessages = ValidationUtil.validateAndGetViolations(validator, globalUser);
assertEquals("CPF deve ter 11 caracteres", violationMessages.get("cpf"));
assertEquals("CPF não pode estar em branco", violationMessages.get("cpf"));

// Teste 2: CPF inválido
globalUser.setCpf("1234567890");
Expand All @@ -150,22 +150,22 @@ public void testInvalidCpf() {
@Test
public void testInvalidTelephone() {
// Teste 1: Telefone em branco
globalUser.setTelephone("");
globalUser.setTelephone(" ");
Map<String, String> violationMessages = ValidationUtil.validateAndGetViolations(validator, globalUser);
assertEquals("Telefone não pode estar em branco", violationMessages.get("telephone"));

// Teste 2: Telefone inválido
globalUser.setTelephone("1234567890");
globalUser.setTelephone("123456789");
violationMessages = ValidationUtil.validateAndGetViolations(validator, globalUser);
assertEquals("Telefone deve ter 11 caracteres", violationMessages.get("telephone"));
}

@Test
public void testInvalidPassword() {
// Teste 1: Senha em branco
globalUser.setPassword("");
globalUser.setPassword(" ");
Map<String, String> violationMessages = ValidationUtil.validateAndGetViolations(validator, globalUser);
assertEquals("Senha deve ter no mínimo 6 e no máximo 255 caracteres", violationMessages.get("password"));
assertEquals("Senha não pode estar em branco", violationMessages.get("password"));

// Teste 2: Senha com menos de 6 caracteres
globalUser.setPassword("12345");
Expand Down

0 comments on commit 5086135

Please sign in to comment.