Package com.jcabi.matchers
Class XhtmlMatchers
java.lang.Object
com.jcabi.matchers.XhtmlMatchers
Convenient set of matchers for XHTML/XML content.
For example:
MatcherAssert.assertThat( "<root><a>hello</a></root>", XhtmlMatchers.hasXPath("/root/a[.='hello']") );
- Since:
- 0.2.6
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> org.hamcrest.Matcher<T>
Matches content against XPath query.static <T> org.hamcrest.Matcher<T>
Matches content against XPath query, with custom namespaces.static <T> org.hamcrest.Matcher<T>
hasXPath
(String query, NamespaceContext ctx) Matches content against XPath query, with custom context.static <T> org.hamcrest.Matcher<T>
Matches content against list of XPaths.static <T> org.hamcrest.Matcher<T>
Matches content against list of XPaths.static <T> Source
xhtml
(T xhtml) Makes XHTML source presentable for testing.
-
Method Details
-
xhtml
Makes XHTML source presentable for testing.Useful method for assertions in unit tests. For example:
MatcherAssert.assertThat( XhtmlMatchers.xhtml(dom_xml_element), XhtmlMatchers.hasXPath("/root/data") );
The method understands different input types differently. For example, an
InputStream
will be read as a UTF-8 document,Reader
will be read as a document, aSource
will be used "as is",Node
will be printed as a text, etc. The goal is to make any input type presentable as an XML document, as much as it is possible.- Type Parameters:
T
- Type of source- Parameters:
xhtml
- The source of data- Returns:
- Renderable source
- Since:
- 0.4.10
-
hasXPath
Matches content against XPath query.- Type Parameters:
T
- Type of XML content provided- Parameters:
query
- The query- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
hasXPath
Matches content against XPath query, with custom namespaces.Every namespace from the
namespaces
list will be assigned to its own prefix, in order of appearance. Start with1
. For example:MatcherAssert.assert( "<foo xmlns='my-namespace'></foo>", XhtmlMatchers.hasXPath("/ns1:foo", "my-namespace") );
- Type Parameters:
T
- Type of XML content provided- Parameters:
query
- The querynamespaces
- List of namespaces- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
hasXPath
Matches content against XPath query, with custom context.- Type Parameters:
T
- Type of XML content provided- Parameters:
query
- The queryctx
- The context- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
hasXPaths
Matches content against list of XPaths.- Type Parameters:
T
- Type of XML content provided- Parameters:
xpaths
- The query- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
hasXPaths
Matches content against list of XPaths.- Type Parameters:
T
- Type of XML content provided- Parameters:
xpaths
- The query- Returns:
- Matcher suitable for JUnit/Hamcrest matching
- Since:
- 1.8.0
-