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
methods printedAs(PrintFormat) or printedBy(Function) to customize that. By
default, the value's toString method will be called.
E.g. approve(result).printAs(multiLineString()).byFile(); prints the given object
using the given MultiLineStringPrintFormat.
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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ApprovalBuilder<T> approve(T value) Creates a new builder for the given value.voidby(Function<String, ApprovalResult> approver) Approves thevalueby the given approver.voidbyFile()Approves the receivedValue by a file, using anextToTest PathProvider, and theused PrintFormat's filenameExtension.voidApproves the receivedValue by aApproverwith anPathProviders.approvedPath(Path)with the given pathStringto the approved file.voidApproves the receivedValue by a file with anPathProviders.approvedPath(Path)with the givenPathto the approved file.voidbyFile(PathProvider pathProvider) Approves the receivedValue by a file defined by the givenPathProvider.voidApproves the value by the given previouslyApproved value.Sets a name for the current approval.printed()printedAs(PrintFormat<? super T> printFormat) reviewedBy(String script) Creates aFileReviewerScriptfrom the given scriptStringto trigger if the received value is not equal to the previously approved.reviewedBy(FileReviewer fileReviewer) 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 currentvalue.
-
Method Details
-
approve
Creates a new builder for the given value.- Type Parameters:
T- the type of the value to approve- Parameters:
value- 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:
- a copy of this with the given
name
-
printedBy
-
printedAs
- Parameters:
printFormat- the printer used to convert the value to aString- Returns:
- a copy of this with the printed
value
-
printed
- Returns:
- a copy of this with the printed
value - See Also:
-
scrubbedOf
Applies the given scrubber to the currentvalue.- Parameters:
scrubber- theUnaryOperatororScrubber- Returns:
- a copy of this with the scrubbed
value
-
reviewedBy
Sets the givenFileReviewerto trigger if the received value is not equal to the previously approved.- Parameters:
fileReviewer- theFileReviewerto be used- Returns:
- a copy of this with the given
fileReviewer - See Also:
-
reviewedBy
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:
- a copy of this with the given script as
fileReviewer - See Also:
-
by
Approves thevalueby the given approver.If necessary the
valueis printed using theConfiguration.defaultPrintFormat().- Parameters:
approver- aFunctionor anApproverimplementation- Throws:
ApprovalError- if the approval fails
-
byValue
Approves the value by the given previouslyApproved value.- Parameters:
previouslyApproved- the approved value
-
byFile
Approves the receivedValue by a file defined by the givenPathProvider.- Parameters:
pathProvider- 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 a file, using anextToTest PathProvider, and theused PrintFormat's filenameExtension.- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by a file with anPathProviders.approvedPath(Path)with the givenPathto the approved file.Note: the
PrintFormat's filenameExtension is ignored.- Parameters:
approvedPath- thePathto the approved file- Throws:
ApprovalError- if the approval fails
-
byFile
Approves the receivedValue by aApproverwith anPathProviders.approvedPath(Path)with the given pathStringto the approved file.Note: the
PrintFormat's filenameExtension is ignored.- Parameters:
approvedPath- the path to the approved file- Throws:
ApprovalError- if the approval fails
-