Package com.jcabi.matchers
Class XhtmlMatchers
- java.lang.Object
-
- com.jcabi.matchers.XhtmlMatchers
-
public final class XhtmlMatchers extends Object
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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> org.hamcrest.Matcher<T>hasXPath(String query)Matches content against XPath query.static <T> org.hamcrest.Matcher<T>hasXPath(String query, Object... namespaces)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>hasXPaths(String... xpaths)Matches content against list of XPaths.static <T> Sourcexhtml(T xhtml)Makes XHTML source presentable for testing.
-
-
-
Method Detail
-
xhtml
public static <T> Source xhtml(T 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
InputStreamwill be read as a UTF-8 document,Readerwill be read as a document, aSourcewill be used "as is",Nodewill 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
public static <T> org.hamcrest.Matcher<T> hasXPath(String query)
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
public static <T> org.hamcrest.Matcher<T> hasXPath(String query, Object... namespaces)
Matches content against XPath query, with custom namespaces.Every namespace from the
namespaceslist 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
public static <T> org.hamcrest.Matcher<T> hasXPath(String query, NamespaceContext ctx)
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
public static <T> org.hamcrest.Matcher<T> hasXPaths(String... xpaths)
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
-
-