skuzzle / snapshot-tests

Convenient snapshot testing for Java
https://skuzzle.github.io/snapshot-tests/reference/latest/
MIT License
12 stars 0 forks source link

Remove JSONAssert from public interface #16

Closed skuzzle closed 1 year ago

skuzzle commented 2 years ago

JSONAssert brings some nice options to customize how two objects are being compared. However, the API is a bit awkward and doesn't fit into our fluent/builder style DSL. As such, we should remove the public visibility of the JSONComparator class in JsonSnapshot and provide a nice fluent wrapper around it.

skuzzle commented 2 years ago

A better API has been implemented in 1.2.0. It can be used like this:

snapshot.assertThat(myself)
                .as(JsonSnapshot.withDefaultObjectMapper()
                        .withComparisonRules(rules -> rules
                                .pathAt("address.city").ignore()
                                .pathAt("birthdate").mustMatch(Pattern.compile("\\d{4}-\\d{2}-\\d{2}"))))
                .matchesSnapshotStructure();

Leaving this ticket open for now to remove the old method in next minor version.