Commit b858f151 by Antonio Rueda

Test de creación de usuarios inválidos

parent e8f6ca7f
......@@ -3,9 +3,12 @@ package es.ujaen.dae.reservahoteles.servicios;
import es.ujaen.dae.reservahoteles.entidades.Cliente;
import es.ujaen.dae.reservahoteles.entidades.Hotel;
import es.ujaen.dae.reservahoteles.excepciones.ClienteYaRegistrado;
import jakarta.validation.ConstraintViolationException;
import java.time.LocalDate;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -24,6 +27,20 @@ public class TestServicioReservas {
@Test
@DirtiesContext
void testNuevoClienteInvalido() {
// Test con teléfono e email inválidos
var cliente = new Cliente("Pedro", "Jaén Jaén", "611225", "pjaengmail.com", "miClAvE");
assertThatThrownBy(() -> servicio.nuevoCliente(cliente)).isInstanceOf(ConstraintViolationException.class);
// Test de intento de creación repetido
var cliente2 = new Cliente("Pedro", "Jaén Jaén", "611301114", "pjaen@gmail.com", "miClAvE");
servicio.nuevoCliente(cliente2);
assertThatThrownBy(() -> servicio.nuevoCliente(cliente2)).isInstanceOf(ClienteYaRegistrado.class);
}
@Test
@DirtiesContext
void testLoginCliente() {
var cliente = new Cliente("Pedro", "Jaén Jaén", "611203025", "pjaen@gmail.com", "miClAvE");
servicio.nuevoCliente(cliente);
......@@ -60,8 +77,8 @@ public class TestServicioReservas {
servicio.nuevoHotel(hotel3);
List<Hotel> hoteles = servicio.buscarHotelesDisponiblesPorLocalidad("almeria",
LocalDate.now().plusWeeks(2),
LocalDate.now().plusWeeks(2).plusDays(2),
LocalDate.now().plusDays(7),
LocalDate.now().plusDays(9),
0, 2);
assertThat(hoteles).hasSize(2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment