Package org.approvej

Class ApprovalBuilder<T>

java.lang.Object
org.approvej.ApprovalBuilder<T>
Type Parameters:
T - the type of the value to approve

@NullMarked public class ApprovalBuilder<T> extends Object
A builder to configure an approval for a given value.

E.g. approve(result).byFile(); will approve the result with the content of a file next to the test.

Printing

Before approval, the value needs to be printed (turned into a String). You can use the method printWith(Printer) to customize that. By default, the value's toString method will be called.

E.g. approve(result).printWith(objectPrinter()).byFile(); prints the given object using the given ObjectPrinter.

Scrubbing

The value can also be scrubbed of dynamic data (like timestamps or ID's).

E.g. approve(result).scrubbedOf(uuids()).byFile(); will replace all UUID's in the result before approval.

Approving

The builder is concluded by specifying an approver to approve the value by(Function) by} ( byFile() and byValue(String)).

E.g. approve(result).byFile(); approves the result with the content of a file next to the test, while approve(result).byValue(approved); approves the result with the given approved value.