@Test public void failsWithMessages() throws Exception { Try<User> validate = underTest.validate(new User(null, null)); assertThat(validate.isSuccess(), is(false)); assertThat(validate.getFailure().getMessage(), containsString("name may not be null")); assertThat(validate.getFailure().getMessage(), containsString("age may not be null")); }
public <T> Try<T> validate(T underTest) { Set<ConstraintViolation<T>> violations = validator.validate(underTest); if (violations.isEmpty()) { return Try.success(underTest); } else { Exception failure = createFailure(violations, underTest); return Try.failure(failure); } }
RequestValidator { public <T> Try<T> validate(T underTest) { Set<ConstraintViolation<T>> violations = validator.validate(underTest); if (violations.isEmpty()) { return Try.success(underTest); } else { Exception failure = createFailure(violations, underTest); return Try.failure(failure); } } }
RequestValidator { public <T> Try<T> validate(T underTest) { Set<ConstraintViolation<T>> violations = validator.validate(underTest); if (violations.isEmpty()) { return Try.success(underTest); } else { Exception failure = createFailure(violations, underTest); return Try.failure(failure); } } RequestValidator(Validator validator, ObjectMapper mapper); }
RequestValidator { public <T> Try<T> validate(T underTest) { Set<ConstraintViolation<T>> violations = validator.validate(underTest); if (violations.isEmpty()) { return Try.success(underTest); } else { Exception failure = createFailure(violations, underTest); return Try.failure(failure); } } RequestValidator(Validator validator, ObjectMapper mapper); Try<T> validate(T underTest); }
RequestValidator { public <T> Try<T> validate(T underTest) { Set<ConstraintViolation<T>> violations = validator.validate(underTest); if (violations.isEmpty()) { return Try.success(underTest); } else { Exception failure = createFailure(violations, underTest); return Try.failure(failure); } } RequestValidator(Validator validator, ObjectMapper mapper); Try<T> validate(T underTest);  }