Skip to content

Commit

Permalink
docs: document how to extend
Browse files Browse the repository at this point in the history
  • Loading branch information
goatfryed committed Sep 29, 2024
1 parent fd28e34 commit 1eea055
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 20 additions & 1 deletion docs/extend-assert-baseline.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# Extend with another baseline format
[TODO]

You can extend [AbstractBaselineAssertion](../src/main/java/io/github/goatfryed/assert_baseline/core/AbstractBaselineAssertion.java)
to implement your own format.

Compare [JsonBaselineAssertion](../src/main/java/io/github/goatfryed/assert_baseline/json/JsonBaselineAssertion.java)

(!) This internal API is considered unstable.

## Extending from AbstractBaselineAssertion

### 1. implement write
Implement `AbstractBaselineAssertion::saveActual(BaselineContext)`.
Serialize your subject and write it to `BaselineContext::getActualOutputStream`

### 2. implement verification
Implement `verifyIsEqualToBaseline(BaselineContext context)`.
Usually, you'll want to read from `BaselineContext::getBaselineAsString(), deserialize the baseline,
and then compare the java beans.

### implement further conventional methods
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ public final SELF usingStorage(Configurer<StorageFactory> configurer) {
return myself;
}

/**
* Expects you to write your subject in serialized form to {@link BaselineContext#getActualOutputStream()}
*/
abstract protected void saveActual(BaselineContext context);

/**
* Usually, you'll want to read {@link BaselineContext#getBaselineAsString()}, deserialize the baseline and compare the models.
*/
abstract protected void verifyIsEqualToBaseline(BaselineContext context);

private BaselineContextFactory getContextFactory() {
Expand Down

0 comments on commit 1eea055

Please sign in to comment.