XmlRecordValidator implements RecordValidator<P> { @Override public Record<P> processRecord(Record<P> record) throws Exception { P payload = record.getPayload(); JAXBContext context = JAXBContext.newInstance(payload.getClass()); JAXBSource source = new JAXBSource(context, payload); validator.validate(source); return record; } XmlRecordValidator(final Path xsd);  XmlRecordValidator(final Path xsd, final ErrorHandler errorHandler); @Override Record<P> processRecord(Record<P> record);  }
@Test public void whenRecordIsValid_thenShouldReturnTheSameRecord() throws Exception { Foo Foo = new Foo("foo"); when(record.getPayload()).thenReturn(Foo); Record<Foo> fooRecord = xmlRecordValidator.processRecord(record); assertThat(fooRecord).isEqualTo(record); }
@Test(expected = SAXParseException.class) public void whenRecordIsNotValid_thenShouldReturnThrowAnException() throws Exception { Foo Foo = new Foo("foobar"); when(record.getPayload()).thenReturn(Foo); xmlRecordValidator.processRecord(record); }