public class ApprovalFiles
extends java.lang.Object
Approval Testing relies on 2 specific files for storing the execution results of the Program Under Tests and running comparisons over the output of the program.
Approvals-Java provides various features, including being able to approve single files, but also to validate the output of a program using an approved folder (which can then contain various subfolders and files).
This class allows to store references of the 2 particular entries to consider: the approved and received entries, which are used to store the reference data, and the temporary output of the program for comparison. The class manages both cases provided by the framework: single files, or complete folders.
This class not only will hold the references of the approved and received entries, but it’ll also provide all the necessary methods allowing to compare and validate the files or folders.
| Modifier and Type | Field and Description |
|---|---|
java.nio.file.Path |
approved
Path to an approved entry.
|
java.nio.file.Path |
received
Path to an received entry.
|
| Modifier and Type | Method and Description |
|---|---|
static ApprovalFiles |
build(java.nio.file.Path folder,
java.lang.String methodName,
java.lang.String extension)
Builds a pair of approval entries from the provided folder, method name, and extension.
|
boolean |
equals(java.lang.Object o)
Overriding equals to allow filtering of duplicates.
|
int |
hashCode()
Overriding hashCode to allow filtering of duplicates.
|
boolean |
haveSameContent()
If approved and received are regular files, this method will check if both files have the same content (by reading them and comparing the data afterwards).
|
java.util.stream.Stream<ApprovalFiles> |
listChildrenApprovalFiles()
If approved and received actually are folders (which can be the case while using the folder approval features), this method allows to list all the children approval files from those folders.
|
public final java.nio.file.Path approved
Path to an approved entry.
This entry can contain:
public final java.nio.file.Path received
Path to an received entry.
This entry can contain:
public static ApprovalFiles build(java.nio.file.Path folder, java.lang.String methodName, java.lang.String extension)
Builds a pair of approval entries from the provided folder, method name, and extension. The path for both approved and received files will be computed and used as approval files.
folder - The folder in which the approval files should be locatedmethodName - The name of the method calling the test. It is used to actually name the approval filesextension - The extension to use for the approval file (by default could be either approved or received)ApprovalFiles object, containing the pair of generated approved and received entriespublic boolean haveSameContent()
If approved and received are regular files, this method will check if both files have the same content (by reading them and comparing the data afterwards).
If approved and received actually are folders, this method will simply return false.
public java.util.stream.Stream<ApprovalFiles> listChildrenApprovalFiles()
If approved and received actually are folders (which can be the case while using the folder approval features), this method allows to list all the children approval files from those folders.
It’ll basically read all the files from the approved folder, all the files from the received folder, associate the matching approved and received files for each of those, and of course filter the duplicates. This gives us a complete list of all approval files in the end.
In case that function is called when approved or received are not folders, it’ll simply return an empty stream.
public boolean equals(java.lang.Object o)
Overriding equals to allow filtering of duplicates.
equals in class java.lang.Objecto - The object we want to compare to the current instancepublic int hashCode()
Overriding hashCode to allow filtering of duplicates.
hashCode in class java.lang.ObjectCopyright © 2018 Write Them First!. All rights reserved.