Java Hamcrest matchers for record.
Java 16+
<dependency>
<groupId>rocks.cleancode</groupId>
<artifactId>hamcrest-record</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
Java 16 or higher.
Two matchers are provided for record: hasField(fieldName)
and field(fieldName, matcher)
.
This matcher matches existing field with not null value.
import static org.hamcrest.MatcherAssert.assertThat;
import static rocks.cleancode.hamcrest.record.HasFieldMatcher.hasField;
Person person = new Person("John", "DOE");
assertThat(person, hasField("firstName"));
This matcher matches the value of the field.
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static rocks.cleancode.hamcrest.record.HasFieldMatcher.field;
Person person = new Person("John", "DOE");
assertThat(person, field("firstName", is(equalTo("John"))));