Fake File System
A fully in-memory file system useful for testing. It includes features to support writing better tests.
Use openPaths to see which paths have been opened for read or write, but not yet closed. Tests should call checkNoOpenFiles in tearDown()
to confirm that no file streams were leaked.
Strict By Default
-----------------These actions are not allowed and throw an IOException if attempted:
Moving a file that is currently open for reading or writing.
Deleting a file that is currently open for reading or writing.
Moving a file to a path that currently resolves to an empty directory.
Reading and writing the same file at the same time.
Opening a file for writing that is already open for writing.
Programs that do not attempt any of the above operations should work fine on both UNIX and Windows systems. Relax these constraints individually or call emulateWindows or emulateUnix; to apply the constraints of a particular operating system.
Properties
True to allow the target of an atomicMove operation to be an empty directory. Windows file systems typically allow files to replace empty directories; UNIX file systems do not.
True to allow files to be deleted even if they're currently open for read or write. UNIX file systems typically allow open files to be deleted; Windows file systems do not.
True to allow files to be moved even if they're currently open for read or write. UNIX file systems typically allow open files to be moved; Windows file systems do not.
True to allow symlinks to be created. UNIX file systems typically allow symlinks; Windows file systems do not. Setting this to false after creating a symlink does not prevent that symlink from being returned or used.
True to permit a file to have multiple sinks open at the same time. Both Windows and UNIX file systems permit this but the result may be undefined.
An absolute path with this file system's current working directory. Relative paths will be resolved against this directory when they are used.
Functions
Confirm that all files that have been opened on this file system (with source, sink, and appendingSink) have since been closed. Call this in your test's tearDown()
function to confirm that your program hasn't leaked any open files.
Configure this file system to use a UNIX-like working directory (/
, unless the working directory is already UNIX-like) and to follow a UNIX-like policy on what operations are permitted.
Configure this file system to use a Windows-like working directory (F:\
, unless the working directory is already Windows-like) and to follow a Windows-like policy on what operations are permitted.