ConformsToSchema extends TypeSafeDiagnosingMatcher<Source> { @Factory public static Matcher<Source> conformsTo(Schema schema) { return new ConformsToSchema(schema); } ConformsToSchema(Schema schema); void describeTo(Description description); @Factory static Matcher<Source> conformsTo(Schema schema);  }
@Test public void aValidXmlStringAdheresToTheSchema() throws SAXException { String xml = "<person private=\"true\"><name>Dave</name></person>"; assertThat(the(xml), conformsTo(schema)); }
@Test public void anInvalidAttributeDoesNotAdhereToTheSchema() throws SAXException { String xml = "<person private=\"2\"><name>Dave</name></person>"; assertThat(the(xml), not(conformsTo(schema))); }
@Test public void anInvalidElementDoesNotAdhereToTheSchema() throws SAXException { String xml = "<person private=\"1\"><age/></person>"; assertThat(the(xml), not(conformsTo(schema))); }
@Test(expected = Exception.class) public void malformedXmlCausesAnExceptionToBeThrown() throws SAXException { String xml = "<person private=\"1\">"; assertThat(the(xml), not(conformsTo(schema))); }