• 1.7.0

XHTML Hamcrest Matchers

XhtmlMatchers is a utility class with static methods that create XHTML Hamcrest matchers, to be used in unit tests, for example:

import com.jcabi.matchers.XhtmlMatchers;
import org.hamcrest.MatcherAssert;
public class FooTest {
  @Test
  public void buildsValidXml() {
    MatcherAssert.assertThat(
      "<data><employee id='33'><name>Jeff</name></employee></data>",
      XhtmlMatchers.hasXPath("/data/employee[@id=33]/name")
    );
  }
}

Besides that, there is a convenient static method that converts its input to XML, that correctly renders itself in unit test output:

import com.jcabi.matchers.XhtmlMatchers;
import org.hamcrest.MatcherAssert;
public class FooTest {
  @Test
  public void buildsValidXml() {
    Source source = // ... get it somewhere
    MatcherAssert.assertThat(
      XhtmlMatchers.xhtml(source),
      XhtmlMatchers.hasXPath("/data/employee[@id=33]/name")
    );
  }
}

These dependencies you will need in your pom.xml:

<dependency>
  <groupId>org.hamcrest</groupId>
  <artifactId>hamcrest-library</artifactId>
  <version>1.3</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.hamcrest</groupId>
  <artifactId>hamcrest-core</artifactId>
  <version>1.3</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.jcabi</groupId>
  <artifactId>jcabi-xml</artifactId>
  <version>0.7.8</version>
  <scope>test</scope>
</dependency>