Package net.officefloor.frame.test
Class FileTestSupport
java.lang.Object
net.officefloor.frame.test.FileTestSupport
- All Implemented Interfaces:
TestSupport
- Author:
- Daniel Sagenschneider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearDirectory(File directory) Creates the input directory.voidcopyDirectory(File source, File target) Copies the contents of thesourcedirectory to thetargetdirectory.voidcreateFile(File target, InputStream content) Creates the target file with the content.voiddeleteDirectory(File directory) Deletes the input directory.findDirectoryRecursive(File root, String name) Recursively searchesrootfor the first directory whose name equalsname.Obtains the file by the input file name located in the package of the input class.Obtains the file at the relative path.findInputStream(Class<?> packageClass, String fileName) Obtains the input stream to the file by the input file name located in the package of the input class.getFileContents(File file) Obtains the contents of the output file.getFileLocation(Class<?> packageClass, String fileName) Obtains the file location of the input file located in the package of the input class.getPackageRelativePath(Class<?> packageClass) Obtains the relative path of the package of the class.voidinit(org.junit.jupiter.api.extension.ExtensionContext context) Intialise.
-
Constructor Details
-
FileTestSupport
public FileTestSupport()Default constructor.
-
-
Method Details
-
init
Description copied from interface:TestSupportIntialise.- Specified by:
initin interfaceTestSupport- Parameters:
context-ExtensionContext.- Throws:
Exception- If fails to init.
-
findFile
Obtains the file at the relative path.- Parameters:
relativePath- Relative path to the file.- Returns:
File.- Throws:
FileNotFoundException- If file could not be found.
-
findFile
Obtains the file by the input file name located in the package of the input class.- Parameters:
packageClass- Class to obtain the relative path from for its package.fileName- Name of file within the package directory.- Returns:
- File within the package directory.
- Throws:
FileNotFoundException- Should the file not be found.
-
getFileLocation
Obtains the file location of the input file located in the package of the input class.- Parameters:
packageClass- Class to obtain the relative path from for its package.fileName- Name of the file within the package directory.- Returns:
- Path to the file.
-
findDirectoryRecursive
Recursively searchesrootfor the first directory whose name equalsname.- Parameters:
root- Directory to search within.name- Directory name to find.- Returns:
- Matching
Filedirectory, ornullif not found.
-
clearDirectory
Creates the input directory.- Parameters:
directory- Directory to be cleared.
-
deleteDirectory
Deletes the input directory.- Parameters:
directory- Directory to be deleted.
-
copyDirectory
Copies the contents of thesourcedirectory to thetargetdirectory.- Parameters:
source- Source directory.target- Target directory.- Throws:
IOException- If fails to copy the directory.
-
findInputStream
public InputStream findInputStream(Class<?> packageClass, String fileName) throws FileNotFoundException Obtains the input stream to the file by the input file name located in the package of the input class.
Note: this also searches the class path for the file.
- Parameters:
packageClass- Class to obtain the relative path from for its package.fileName- Name of file within the package directory.- Returns:
- File within the package directory.
- Throws:
FileNotFoundException- Should the file not be found.
-
getPackageRelativePath
Obtains the relative path of the package of the class.- Parameters:
packageClass- Class to obtain the relative path from for its package.- Returns:
- Relative path of class's package.
-
getFileContents
Obtains the contents of the output file.- Parameters:
file- File to obtain contents from.- Returns:
- Contents of the output file.
- Throws:
FileNotFoundException- Should output file not yet be created.IOException- Should fail to read from output file.
-
createFile
Creates the target file with the content.- Parameters:
content- Content for the file.target- Target file.- Throws:
IOException- If fails to create.
-