Useful matchers which are not part of the official Hamcrest.
The HasPropertyPath
matcher is an extension on the regular HasProperty
matcher to test deeper nesting. This is for example useful to test Neo4j deserialization:
@Test
public void shouldLoadItemClientAndPetForPetNamedPete() {
Item item = repository.loadItemClientAndPet(...);
assertThat(item, hasPropertyPath("client.pet.name", is("Pete"));
}
In some cases, it is enough to know the path exists, no matter what value the property has:
@Test
public void shouldHavePathToPetName() {
assertThat(item, hasPropertyPath("client.pet.name")); // is the same as
assertThat(item, hasPropertyPath("client.pet.name", is(anything()));
}
Add to your project using Maven dependency:
<groupId>io.bitzl</groupId>
<artifactId>hamcrest-extras</artifactId>
<version>1.0.0-RELEASE</version>
<scope>test</scope>