public final class XhtmlMatchers extends Object
For example:
MatcherAssert.assertThat(
"<root><a>hello</a></root>",
XhtmlMatchers.hasXPath("/root/a[.='hello']")
);| Modifier and Type | Method and Description |
|---|---|
static <T> Matcher<T> |
hasXPath(String query)
Matches content against XPath query.
|
static <T> Matcher<T> |
hasXPath(String query,
NamespaceContext ctx)
Matches content against XPath query, with custom context.
|
static <T> Matcher<T> |
hasXPath(String query,
Object... namespaces)
Matches content against XPath query, with custom namespaces.
|
static <T> Matcher<T> |
hasXPaths(String... xpaths)
Matches content against list of XPaths.
|
static <T> Source |
xhtml(T xhtml)
Makes XHTML source presentable for testing.
|
public static <T> Source xhtml(T xhtml)
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, a Source 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.
T - Type of sourcexhtml - The source of datapublic static <T> Matcher<T> hasXPath(String query)
T - Type of XML content providedquery - The querypublic static <T> Matcher<T> hasXPath(String query, Object... namespaces)
Every namespace from the namespaces list will be assigned to
its own prefix, in order of appearance. Start with 1.
For example:
MatcherAssert.assert(
"<foo xmlns='my-namespace'></foo>",
XhtmlMatchers.hasXPath("/ns1:foo", "my-namespace")
);T - Type of XML content providedquery - The querynamespaces - List of namespacespublic static <T> Matcher<T> hasXPath(String query, NamespaceContext ctx)
T - Type of XML content providedquery - The queryctx - The contextCopyright © 2012–2017 jcabi.com. All rights reserved.