Skip to content

Commit

Permalink
Provide an early upfront example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
runeflobakk committed Mar 11, 2024
1 parent 8ffd1b9 commit 28543c0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@

# Record Matcher Generator

A library and plugin for Maven to generate source code for [Hamcrest Matchers](https://hamcrest.org/JavaHamcrest/) for [Java records](https://openjdk.org/jeps/395). The generated matchers provide an API to incrementally constrain how specific you want to express what your expectations are in test. reflecting the names of both the record itself as well as its components (i.e. fields)
A library and plugin for Maven to generate source code for [Hamcrest Matchers](https://hamcrest.org/JavaHamcrest/) for [Java records](https://openjdk.org/jeps/395). The API of the generated matchers reflect the names of both the record itself as well as its components (i.e. fields), and provide facilities to incrementally constrain how specific you want to express what your expectations are.

This project is currently in its infancy, but should still be usable. You are most welcome to play around with it, and I appreciate any feedback you may have!

## Example

```java
record Book (String title, List<Author> authors, int pageCount, Publisher publisher) { }
```

Given you have defined the record above in your domain, this library can generate a `BookMatcher` which can be used like this:

```java
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static your.domain.BookMatcher.aBook();
...

assertThat(book, is(aBook().withTitle("Effective Java").withAuthors(not(empty()))));

List<Book> effectiveSeries = // resolve Effective Xyz series of books
assertThat(effectiveSeries, everyItem(aBook().withTitle(containsString("Effective"))));
```



## Getting started

Expand Down

0 comments on commit 28543c0

Please sign in to comment.