https://github.com/jcabi/jcabi-matchers
A few convenient Hamcrest matchers, mostly for XPath vs XHTML and fields in JAXB
https://github.com/jcabi/jcabi-matchers
hamcrest hamcrest-matchers java jaxb xml xpath
Last synced: about 2 months ago
JSON representation
A few convenient Hamcrest matchers, mostly for XPath vs XHTML and fields in JAXB
- Host: GitHub
- URL: https://github.com/jcabi/jcabi-matchers
- Owner: jcabi
- License: other
- Created: 2014-04-27T02:57:50.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2025-02-25T17:15:19.000Z (about 2 months ago)
- Last Synced: 2025-02-25T18:26:28.969Z (about 2 months ago)
- Topics: hamcrest, hamcrest-matchers, java, jaxb, xml, xpath
- Language: Java
- Homepage: https://matchers.jcabi.com
- Size: 1.32 MB
- Stars: 15
- Watchers: 6
- Forks: 16
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-java - Jcabi-Matchers
README
# A Few Matchers for Hamcrest
[](https://www.elegantobjects.org)
[](http://www.rultor.com/p/jcabi/jcabi-matchers)[](https://github.com/jcabi/jcabi-matchers/actions/workflows/mvn.yml)
[](http://www.0pdd.com/p?name=jcabi/jcabi-matchers)
[](http://www.javadoc.io/doc/com.jcabi/jcabi-matchers)
[](https://maven-badges.herokuapp.com/maven-central/com.jcabi/jcabi-matchers)
[](https://codecov.io/gh/jcabi/jcabi-matchers)More details are here:
[matchers.jcabi.com](http://matchers.jcabi.com/index.html).
Also, read this blog post: [XML/XPath Matchers for Hamcrest][blog].First, you add this to your `pom.xml`:
```xml
com.jcabi
jcabi-matchers
1.8.0```
The library contains a collection of convenient Hamcrest matchers:
```java
import com.jcabi.matchers.XhtmlMatchers;
import org.hamcrest.MatcherAssert;MatcherAssert.assertThat(
"Jeff",
XhtmlMatchers.hasXPath("/test/name[.='Jeff']")
);
```To match XHTML documents you need to specify namespaces in your
XPath expressions:```java
MatcherAssert.assertThat(
"Hello, world!",
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:```java
MatcherAssert.assertThat(
"",
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:
```bash
mvn clean install -Pqulice
```[blog]: http://www.yegor256.com/2014/04/28/xml-xpath-hamcrest-matchers.html