Class ApprovalBuilder<T>
- Type Parameters:
T- the type of the value to approve
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 ( 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.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ApprovalBuilder<T> approve(T originalValue) Creates a new builder for the given value.voidApproves thereceivedValueby the given approver.voidbyFile()Approves the receivedValue by aFileApprover, aNextToTestPathProvider, and thePrinter.filenameExtension().voidApproves the receivedValue by aFileApproverwith anApprovedPathProviderand the given path to the approved file.voidApproves the receivedValue by aFileApproverwith anApprovedPathProviderand the givenPathto the approved file.voidbyFile(PathProvider pathProvider) Approves the receivedValue by aFileApproverwith the givenPathProvider.voidApproves the value by anInplaceApproverwith the given previouslyApproved value.scrubbedOf(UnaryOperator<T> scrubber) Applies the given scrubber to the currentreceivedValue.
-
Field Details
-
DEFAULT_PRINTER
The defaultPrinterused to print the value.
-
-
Method Details
-
approve
Creates a new builder for the given value.- Type Parameters:
T- the type of the value to approve- Parameters:
originalValue- the value to approve- Returns:
- a new
ApprovalBuilderfor the given value
-
printWith
-
printWith
- Parameters:
printer- the printer used to convert the value to aString- Returns:
- this
-
scrubbedOf
Applies the given scrubber to the currentreceivedValue.- Parameters:
scrubber- theUnaryOperatororScrubber- Returns:
- this
-
by
Approves thereceivedValueby the given approver.If necessary the
receivedValueis printed using theDEFAULT_PRINTER.- Parameters:
approver- aConsumeror anApproverimplementation- Throws:
ApprovalError- if the approval fails
-
byValue
Approves the value by anInplaceApproverwith the given previouslyApproved value.- Parameters:
previouslyApproved- the approved value
-
byFile
public void byFile()Approves the receivedValue by aFileApprover, aNextToTestPathProvider, and thePrinter.filenameExtension().- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by aFileApproverwith the givenPathProvider.- Parameters:
pathProvider- the provider for the paths of the approved and received files- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by aFileApproverwith anApprovedPathProviderand the givenPathto the approved file.- Parameters:
approvedPath- thePathto the approved file- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by aFileApproverwith anApprovedPathProviderand the given path to the approved file.- Parameters:
approvedPath- the path to the approved file- Throws:
ApprovalError- if the approval fails
-