@Test public void testDoSomethingWithValidPerson() { try { Person person = new Person(10, new Address("Sokolovska", "Praha")); myService.doSomethingWithPerson(person); } catch(IllegalArgumentException e) { fail("IllegalArgumentException must not be thrown if the supplied object is valid"); } }
public void doSomethingWithPerson(Person person){ Set<ConstraintViolation<Person>> resultOfValidation = validator.validate(person); for (ConstraintViolation<Person> constraintViolation : resultOfValidation) { throw new IllegalArgumentException(constraintViolation.getMessage()); } }
MyService { public void doSomethingWithPerson(Person person){ Set<ConstraintViolation<Person>> resultOfValidation = validator.validate(person); for (ConstraintViolation<Person> constraintViolation : resultOfValidation) { throw new IllegalArgumentException(constraintViolation.getMessage()); } } }
MyService { public void doSomethingWithPerson(Person person){ Set<ConstraintViolation<Person>> resultOfValidation = validator.validate(person); for (ConstraintViolation<Person> constraintViolation : resultOfValidation) { throw new IllegalArgumentException(constraintViolation.getMessage()); } }  }
MyService { public void doSomethingWithPerson(Person person){ Set<ConstraintViolation<Person>> resultOfValidation = validator.validate(person); for (ConstraintViolation<Person> constraintViolation : resultOfValidation) { throw new IllegalArgumentException(constraintViolation.getMessage()); } }  void doSomethingWithPerson(Person person); }
MyService { public void doSomethingWithPerson(Person person){ Set<ConstraintViolation<Person>> resultOfValidation = validator.validate(person); for (ConstraintViolation<Person> constraintViolation : resultOfValidation) { throw new IllegalArgumentException(constraintViolation.getMessage()); } }  void doSomethingWithPerson(Person person);  }