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(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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ApprovalBuilder<T> approve(T originalValue) Creates a new builder for the given value.voidby(Function<String, ApprovalResult> approver) Approves thereceivedValueby the given approver.voidbyFile()Approves the receivedValue by aFileApprover, using anextToTest PathProviderBuilder, and theused Printer's filenameExtension.voidApproves the receivedValue by aFileApproverwith anPathProviderBuilder.approvedPath(Path)with the given path to the approved file.voidApproves the receivedValue by aFileApproverwith anPathProviderBuilder.approvedPath(Path)with the givenPathto the approved file.voidbyFile(PathProvider pathProvider) Approves the receivedValue by aFileApproverwith the givenPathProvider.voidbyFile(PathProviderBuilder pathProviderBuilder) Approves the receivedValue by aFileApproverwith the givenPathProviderBuilder.voidApproves the value by anInplaceApproverwith the given previouslyApproved value.Sets a name for the current approval.print()reviewWith(String script) Creates aFileReviewerScriptfrom the given scriptStringto trigger if the received value is not equal to the previously approved.reviewWith(FileReviewer reviewer) Sets the givenFileReviewerto trigger if the received value is not equal to the previously approved.scrubbedOf(UnaryOperator<T> scrubber) Applies the given scrubber to the currentreceivedValue.
-
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
-
named
Sets a name for the current approval. Generally this should be used when there are multiple values in one test case are being approvedbyFile()as the second approval would otherwise simply overwrite the first one.- Parameters:
name- the name for the current approval- Returns:
- this
-
printWith
- Parameters:
printer- theFunctionused to convert thereceivedValueto aString- Returns:
- a new
ApprovalBuilderwith the printed value
-
printWith
- Parameters:
printer- the printer used to convert the value to aString- Returns:
- a new
ApprovalBuilderwith the printed value
-
print
- Returns:
- a new
ApprovalBuilderwith the printed value - See Also:
-
scrubbedOf
Applies the given scrubber to the currentreceivedValue.- Parameters:
scrubber- theUnaryOperatororScrubber- Returns:
- this
-
reviewWith
Sets the givenFileReviewerto trigger if the received value is not equal to the previously approved.- Parameters:
reviewer- theFileReviewerto be used- Returns:
- this
- See Also:
-
reviewWith
Creates aFileReviewerScriptfrom the given scriptStringto trigger if the received value is not equal to the previously approved.- Parameters:
script- the scriptStringto be used as aFileReviewerScript- Returns:
- this
- See Also:
-
by
Approves thereceivedValueby the given approver.If necessary the
receivedValueis printed using theConfiguration.defaultPrinter().- Parameters:
approver- aFunctionor anApproverimplementation- Throws:
ApprovalError- if the approval fails
-
byValue
Approves the value by anInplaceApproverwith the given previouslyApproved value.- Parameters:
previouslyApproved- the approved value
-
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 the givenPathProviderBuilder.- Parameters:
pathProviderBuilder- the provider for the paths of the approved and received files- Throws:
ApprovalError- if the approval fails
-
byFile
public void byFile()Approves the receivedValue by aFileApprover, using anextToTest PathProviderBuilder, and theused Printer's filenameExtension.- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by aFileApproverwith anPathProviderBuilder.approvedPath(Path)with the givenPathto the approved file.Note: the
Printer's filenameExtension is ignored.- Parameters:
approvedPath- thePathto the approved file- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by aFileApproverwith anPathProviderBuilder.approvedPath(Path)with the given path to the approved file.Note: the
Printer's filenameExtension is ignored.- Parameters:
approvedPath- the path to the approved file- Throws:
ApprovalError- if the approval fails
-