BeanValidationRecordValidator implements RecordValidator<P> { @Override public Record<P> processRecord(Record<P> record) throws Exception { Set<ConstraintViolation<Object>> constraintViolationSet = validator.validate(record.getPayload()); if (!constraintViolationSet.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); for (ConstraintViolation<Object> constraintViolation : constraintViolationSet) { stringBuilder .append("Invalid value '").append(constraintViolation.getInvalidValue()).append("' ") .append("for property '").append(constraintViolation.getPropertyPath()).append("' : ") .append(constraintViolation.getMessage()) .append(Utils.LINE_SEPARATOR); } throw new Exception(stringBuilder.toString()); } return record; } BeanValidationRecordValidator(); @Override Record<P> processRecord(Record<P> record);  }
@Test(expected = Exception.class) public void nonValidBeanShouldBeRejected() throws Exception { Foo foo = new Foo(-1, null); when(record.getPayload()).thenReturn(foo); validator.processRecord(record); }
@Test public void validBeanShouldBeAccepted() throws Exception { Foo foo = new Foo(1, "bar"); when(record.getPayload()).thenReturn(foo); Record actual = validator.processRecord(record); assertThat(actual).isEqualTo(record); }