Filter irrelevant nodes in StaxHandler tests
This commit is contained in:
parent
3635c9dbfe
commit
78b6ba0569
|
|
@ -20,9 +20,11 @@ import org.junit.Assume;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
import org.xmlunit.util.Predicate;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
|
@ -58,6 +60,9 @@ public abstract class AbstractStaxHandlerTestCase {
|
|||
|
||||
private XMLReader xmlReader;
|
||||
|
||||
private Predicate<Node> nodeFilter = n -> n.getNodeType() != Node.COMMENT_NODE
|
||||
&& n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
|
||||
|
||||
@Before
|
||||
public void createXMLReader() throws Exception {
|
||||
xmlReader = XMLReaderFactory.createXMLReader();
|
||||
|
|
@ -77,7 +82,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
|||
|
||||
xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
|
||||
|
||||
assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML));
|
||||
assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML).withNodeFilter(nodeFilter));
|
||||
}
|
||||
|
||||
private static boolean wwwSpringframeworkOrgIsAccessible() {
|
||||
|
|
@ -104,7 +109,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
|||
|
||||
xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
|
||||
|
||||
assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML));
|
||||
assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML).withNodeFilter(nodeFilter));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -126,7 +131,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
|||
|
||||
xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML)));
|
||||
|
||||
assertThat(result, isSimilarTo(expected));
|
||||
assertThat(result, isSimilarTo(expected).withNodeFilter(nodeFilter));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -148,7 +153,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
|||
|
||||
xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML)));
|
||||
|
||||
assertThat(expected, isSimilarTo(result));
|
||||
assertThat(expected, isSimilarTo(result).withNodeFilter(nodeFilter));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue