diff --git a/javaxval/src/main/java/org/baeldung/javaxval/methodvalidation/constraints/ConsistentDateParameterValidator.java b/javaxval/src/main/java/org/baeldung/javaxval/methodvalidation/constraints/ConsistentDateParameterValidator.java index b28abcba45..0ee1b6eda1 100644 --- a/javaxval/src/main/java/org/baeldung/javaxval/methodvalidation/constraints/ConsistentDateParameterValidator.java +++ b/javaxval/src/main/java/org/baeldung/javaxval/methodvalidation/constraints/ConsistentDateParameterValidator.java @@ -15,9 +15,6 @@ public class ConsistentDateParameterValidator implements ConstraintValidator getAllCustomers() { @@ -37,13 +42,8 @@ public class ReservationManagement { return null; } - public void createNewCustomer(@Valid Customer customer) { - - // ... - } - @Valid - public Customer getCustomerById() { + public Reservation getReservationById(int id) { return null; } diff --git a/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ContainerValidationIntegrationTest.java b/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ContainerValidationIntegrationTest.java index 53133edd48..2363bf8f5d 100644 --- a/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ContainerValidationIntegrationTest.java +++ b/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ContainerValidationIntegrationTest.java @@ -1,6 +1,7 @@ package org.baeldung.javaxval.methodvalidation; import org.baeldung.javaxval.methodvalidation.model.Customer; +import org.baeldung.javaxval.methodvalidation.model.Reservation; import org.baeldung.javaxval.methodvalidation.model.ReservationManagement; import org.junit.Rule; import org.junit.Test; @@ -69,9 +70,14 @@ public class ContainerValidationIntegrationTest { Customer customer = new Customer(); customer.setFirstName("John"); customer.setLastName("Doe"); + Reservation reservation = new Reservation(LocalDate.now() + .plusDays(1), + LocalDate.now() + .plusDays(2), + customer, 1); exception.expect(ConstraintViolationException.class); - reservationManagement.createNewCustomer(customer); + reservationManagement.createReservation(reservation); } @Test @@ -80,7 +86,12 @@ public class ContainerValidationIntegrationTest { Customer customer = new Customer(); customer.setFirstName("William"); customer.setLastName("Smith"); + Reservation reservation = new Reservation(LocalDate.now() + .plusDays(1), + LocalDate.now() + .plusDays(2), + customer, 1); - reservationManagement.createNewCustomer(customer); + reservationManagement.createReservation(reservation); } } diff --git a/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ValidationIntegrationTest.java b/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ValidationIntegrationTest.java index 6a750698c6..6b53d3a107 100644 --- a/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ValidationIntegrationTest.java +++ b/javaxval/src/test/java/org/baeldung/javaxval/methodvalidation/ValidationIntegrationTest.java @@ -172,11 +172,16 @@ public class ValidationIntegrationTest { public void whenValidationWithInvalidCascadedValue_thenCorrectNumberOfVoilations() throws NoSuchMethodException { ReservationManagement object = new ReservationManagement(); - Method method = ReservationManagement.class.getMethod("createNewCustomer", Customer.class); + Method method = ReservationManagement.class.getMethod("createReservation", Reservation.class); Customer customer = new Customer(); customer.setFirstName("John"); customer.setLastName("Doe"); - Object[] parameterValues = { customer }; + Reservation reservation = new Reservation(LocalDate.now() + .plusDays(1), + LocalDate.now() + .plusDays(2), + customer, 1); + Object[] parameterValues = { reservation }; Set> violations = executableValidator.validateParameters(object, method, parameterValues); assertEquals(2, violations.size()); @@ -186,11 +191,16 @@ public class ValidationIntegrationTest { public void whenValidationWithValidCascadedValue_thenCorrectNumberOfVoilations() throws NoSuchMethodException { ReservationManagement object = new ReservationManagement(); - Method method = ReservationManagement.class.getMethod("createNewCustomer", Customer.class); + Method method = ReservationManagement.class.getMethod("createReservation", Reservation.class); Customer customer = new Customer(); customer.setFirstName("William"); customer.setLastName("Smith"); - Object[] parameterValues = { customer }; + Reservation reservation = new Reservation(LocalDate.now() + .plusDays(1), + LocalDate.now() + .plusDays(2), + customer, 1); + Object[] parameterValues = { reservation }; Set> violations = executableValidator.validateParameters(object, method, parameterValues); assertEquals(0, violations.size());