Skip to content

jcabi/jcabi-matchers

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

EO principles respected here Managed by Zerocracy DevOps By Rultor.com

mvn PDD status Javadoc Maven Central codecov

More details are here: matchers.jcabi.com. Also, read this blog post: XML/XPath Matchers for Hamcrest.

The library contains a collection of convenient Hamcrest matchers. For example:

import com.jcabi.matchers.XhtmlMatchers;
import org.hamcrest.MatcherAssert;

MatcherAssert.assertThat(
  "<test><name>Jeff</name></test>",
  XhtmlMatchers.hasXPath("/test/name[.='Jeff']")
);

To match XHTML documents you need to specify namespaces in your XPath expressions:

MatcherAssert.assertThat(
  "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><body>Hello, world!</body></html>",
  XhtmlMatchers.hasXPath("/xhtml:html/xhtml:body[.='Hello, world!']")
);

Here, we use xhtml predefined namespace. There are also xsl, xs, xsi, and svg namespaces provided off-the-shelf. However, you can define your own too, for example:

MatcherAssert.assertThat(
  "<foo xmlns='my-own-namespace'><bar/></foo>",
  XhtmlMatchers.hasXPath("/ns1:foo/ns1:bar", "my-own-namespace")
);

Here, my-own-namespace is called ns1 inside the XPath expression.

How to contribute?

Fork the repository, make changes, submit a pull request. We promise to review your changes same day and apply to the master branch, if they look correct.

Please run Maven build before submitting a pull request:

$ mvn clean install -Pqulice