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.void
by
(Function<String, ApprovalResult> approver) Approves thereceivedValue
by the given approver.void
byFile()
Approves the receivedValue by aFileApprover
, using anextToTest PathProviderBuilder
, and theused Printer's filenameExtension
.void
Approves the receivedValue by aFileApprover
with anPathProviderBuilder.approvedPath(Path)
with the given path to the approved file.void
Approves the receivedValue by aFileApprover
with anPathProviderBuilder.approvedPath(Path)
with the givenPath
to the approved file.void
byFile
(PathProvider pathProvider) Approves the receivedValue by aFileApprover
with the givenPathProvider
.void
byFile
(PathProviderBuilder pathProviderBuilder) Approves the receivedValue by aFileApprover
with the givenPathProviderBuilder
.void
Approves the value by anInplaceApprover
with the given previouslyApproved value.print()
reviewWith
(String script) Creates aFileReviewerScript
from the given scriptString
to trigger if the received value is not equal to the previously approved.reviewWith
(FileReviewer reviewer) Sets the givenFileReviewer
to 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
ApprovalBuilder
for the given value
-
printWith
- Parameters:
printer
- theFunction
used to convert thereceivedValue
to aString
- Returns:
- a new
ApprovalBuilder
with the printed value
-
printWith
- Parameters:
printer
- the printer used to convert the value to aString
- Returns:
- a new
ApprovalBuilder
with the printed value
-
print
- Returns:
- a new
ApprovalBuilder
with the printed value - See Also:
-
scrubbedOf
Applies the given scrubber to the currentreceivedValue
.- Parameters:
scrubber
- theUnaryOperator
orScrubber
- Returns:
- this
-
reviewWith
Sets the givenFileReviewer
to trigger if the received value is not equal to the previously approved.- Parameters:
reviewer
- theFileReviewer
to be used- Returns:
- this
- See Also:
-
reviewWith
Creates aFileReviewerScript
from the given scriptString
to trigger if the received value is not equal to the previously approved.- Parameters:
script
- the scriptString
to be used as aFileReviewerScript
- Returns:
- this
- See Also:
-
by
Approves thereceivedValue
by the given approver.If necessary the
receivedValue
is printed using theConfiguration.defaultPrinter()
.- Parameters:
approver
- aFunction
or anApprover
implementation- Throws:
ApprovalError
- if the approval fails
-
byValue
Approves the value by anInplaceApprover
with the given previouslyApproved value.- Parameters:
previouslyApproved
- the approved value
-
byFile
Approves the receivedValue by aFileApprover
with 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 aFileApprover
with 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 aFileApprover
with anPathProviderBuilder.approvedPath(Path)
with the givenPath
to the approved file.Note: the
Printer
's filenameExtension is ignored.- Parameters:
approvedPath
- thePath
to the approved file- Throws:
ApprovalError
- if the approval fails
-
byFile
Approves the receivedValue by aFileApprover
with 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
-