Skip to content

clean-code-rocks/hamcrest-java-record

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hamcrest - Record

Maven Central Javadoc Codecov License: GPL v3 Fossa

Java Hamcrest matchers for record.

Requirement

Java 16+

Installation

Maven

<dependency>
    <groupId>rocks.cleancode</groupId>
    <artifactId>hamcrest-record</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

Requirement

Java 16 or higher.

Usage

Two matchers are provided for record: hasField(fieldName) and field(fieldName, matcher).

hasField(fieldName)

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"));

field(fieldName, matcher)

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"))));