@Test public void testDoSomethingWithNonValidPerson() { Person person = new Person(-1, null); try { myService.doSomethingWithPerson(person); fail("IllegalArgumentException is expected if the supplied object is not valid"); } catch(IllegalArgumentException e) { } }
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);  }