public class Files
extends java.lang.Object
File
s.Modifier and Type | Field and Description |
---|---|
private static java.util.function.Predicate<java.io.File> |
ANY |
(package private) BinaryDiff |
binaryDiff |
(package private) Diff |
diff |
(package private) Failures |
failures |
private static Files |
INSTANCE |
(package private) NioFilesWrapper |
nioFilesWrapper |
private static java.lang.String |
UNABLE_TO_COMPARE_FILE_CONTENTS |
Constructor and Description |
---|
Files() |
Modifier and Type | Method and Description |
---|---|
void |
assertCanRead(AssertionInfo info,
java.io.File actual)
Asserts that the given file can be read by the application.
|
void |
assertCanWrite(AssertionInfo info,
java.io.File actual)
Asserts that the given file can be modified by the application.
|
void |
assertDoesNotExist(AssertionInfo info,
java.io.File actual)
Asserts that the given file does not exist.
|
void |
assertExists(AssertionInfo info,
java.io.File actual)
Asserts that the given file exists, regardless it's a file or directory.
|
void |
assertHasBinaryContent(AssertionInfo info,
java.io.File actual,
byte[] expected)
Asserts that the given file has the given binary content.
|
void |
assertHasContent(AssertionInfo info,
java.io.File actual,
java.lang.String expected,
java.nio.charset.Charset charset)
Asserts that the given file has the given text content.
|
void |
assertHasDigest(AssertionInfo info,
java.io.File actual,
java.security.MessageDigest digest,
byte[] expected) |
void |
assertHasDigest(AssertionInfo info,
java.io.File actual,
java.security.MessageDigest digest,
java.lang.String expected) |
void |
assertHasDigest(AssertionInfo info,
java.io.File actual,
java.lang.String algorithm,
byte[] expected) |
void |
assertHasDigest(AssertionInfo info,
java.io.File actual,
java.lang.String algorithm,
java.lang.String expected) |
void |
assertHasExtension(AssertionInfo info,
java.io.File actual,
java.lang.String expected)
Asserts that the given
File has the given extension. |
void |
assertHasName(AssertionInfo info,
java.io.File actual,
java.lang.String expected)
Asserts that the given
File has the given name. |
void |
assertHasNoParent(AssertionInfo info,
java.io.File actual)
Asserts that the given
File does not have a parent. |
void |
assertHasParent(AssertionInfo info,
java.io.File actual,
java.io.File expected)
Asserts that the given
File has the given parent. |
void |
assertIsAbsolute(AssertionInfo info,
java.io.File actual)
Asserts that the given file is an absolute path.
|
void |
assertIsDirectory(AssertionInfo info,
java.io.File actual)
Asserts that the given file is an existing directory.
|
void |
assertIsDirectoryContaining(AssertionInfo info,
java.io.File actual,
java.util.function.Predicate<java.io.File> filter) |
private void |
assertIsDirectoryContaining(AssertionInfo info,
java.io.File actual,
java.util.function.Predicate<java.io.File> filter,
java.lang.String filterPresentation) |
void |
assertIsDirectoryContaining(AssertionInfo info,
java.io.File actual,
java.lang.String syntaxAndPattern) |
void |
assertIsDirectoryNotContaining(AssertionInfo info,
java.io.File actual,
java.util.function.Predicate<java.io.File> filter) |
private void |
assertIsDirectoryNotContaining(AssertionInfo info,
java.io.File actual,
java.util.function.Predicate<java.io.File> filter,
java.lang.String filterPresentation) |
void |
assertIsDirectoryNotContaining(AssertionInfo info,
java.io.File actual,
java.lang.String syntaxAndPattern) |
void |
assertIsEmptyDirectory(AssertionInfo info,
java.io.File actual) |
void |
assertIsFile(AssertionInfo info,
java.io.File actual)
Asserts that the given file is an existing file.
|
void |
assertIsNotEmptyDirectory(AssertionInfo info,
java.io.File actual) |
void |
assertIsRelative(AssertionInfo info,
java.io.File actual)
Asserts that the given file is a relative path.
|
private static void |
assertNotNull(AssertionInfo info,
java.io.File actual) |
void |
assertSameContentAs(AssertionInfo info,
java.io.File actual,
java.nio.charset.Charset actualCharset,
java.io.File expected,
java.nio.charset.Charset expectedCharset)
Asserts that the given files have same content.
|
private java.util.List<java.io.File> |
directoryContent(AssertionInfo info,
java.io.File actual) |
private java.util.List<java.lang.String> |
directoryContentDescription(AssertionInfo info,
java.io.File actual) |
private java.util.List<java.io.File> |
filterDirectory(AssertionInfo info,
java.io.File actual,
java.util.function.Predicate<java.io.File> filter) |
private java.lang.String |
getFileExtension(java.io.File file) |
static Files |
instance()
Returns the singleton instance of this class.
|
private boolean |
isAbsolutePath(AssertionInfo info,
java.io.File actual) |
private java.util.function.Predicate<java.io.File> |
pathMatcher(AssertionInfo info,
java.io.File actual,
java.lang.String syntaxAndPattern) |
static java.util.List<java.lang.String> |
toFileNames(java.util.List<java.io.File> files) |
private void |
verifyIsFile(java.io.File expected) |
private static final java.lang.String UNABLE_TO_COMPARE_FILE_CONTENTS
private static final Files INSTANCE
private static final java.util.function.Predicate<java.io.File> ANY
Diff diff
BinaryDiff binaryDiff
Failures failures
NioFilesWrapper nioFilesWrapper
public static Files instance()
public void assertSameContentAs(AssertionInfo info, java.io.File actual, java.nio.charset.Charset actualCharset, java.io.File expected, java.nio.charset.Charset expectedCharset)
info
- contains information about the assertion.actual
- the "actual" file.actualCharset
- Charset
of the "actual" file.expected
- the "expected" file.expectedCharset
- Charset
of the "actual" file.java.lang.NullPointerException
- if expected
is null
.java.lang.IllegalArgumentException
- if expected
is not an existing file.java.lang.AssertionError
- if actual
is null
.java.lang.AssertionError
- if actual
is not an existing file.java.io.UncheckedIOException
- if an I/O error occurs.java.lang.AssertionError
- if the given files do not have same content.public void assertHasBinaryContent(AssertionInfo info, java.io.File actual, byte[] expected)
info
- contains information about the assertion.actual
- the "actual" file.expected
- the "expected" binary content.java.lang.NullPointerException
- if expected
is null
.java.lang.AssertionError
- if actual
is null
.java.lang.AssertionError
- if actual
is not an existing file.java.io.UncheckedIOException
- if an I/O error occurs.java.lang.AssertionError
- if the file does not have the binary content.public void assertHasContent(AssertionInfo info, java.io.File actual, java.lang.String expected, java.nio.charset.Charset charset)
info
- contains information about the assertion.actual
- the "actual" file.expected
- the "expected" text content.charset
- the charset to use to read the file.java.lang.NullPointerException
- if expected
is null
.java.lang.AssertionError
- if actual
is null
.java.lang.AssertionError
- if actual
is not an existing file.java.io.UncheckedIOException
- if an I/O error occurs.java.lang.AssertionError
- if the file does not have the text content.public void assertIsFile(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file is not an existing file.public void assertIsDirectory(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file is not an existing directory.public void assertIsAbsolute(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file is not an absolute path.public void assertIsRelative(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file is not a relative path.public void assertExists(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file does not exist.public void assertDoesNotExist(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file exists.public void assertCanWrite(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file can not be modified.public void assertCanRead(AssertionInfo info, java.io.File actual)
info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the given file is null
.java.lang.AssertionError
- if the given file can not be modified.public void assertHasParent(AssertionInfo info, java.io.File actual, java.io.File expected)
File
has the given parent.info
- contains information about the assertion.actual
- the given file.expected
- the expected parent File
.java.lang.NullPointerException
- if the expected parent File
is null
.java.io.UncheckedIOException
- if an I/O error occurs.java.lang.AssertionError
- if the given File
is null
.java.lang.AssertionError
- if the given File
does not have a parent.java.lang.AssertionError
- if the given File
parent is not equal to the expected one.public void assertHasExtension(AssertionInfo info, java.io.File actual, java.lang.String expected)
File
has the given extension.info
- contains information about the assertion.actual
- the given file.expected
- the expected extension, it does not contains the '.'
java.lang.NullPointerException
- if the expected extension is null
.java.lang.AssertionError
- if the actual File
is null
.java.lang.AssertionError
- if the actual File
is not a file (ie a directory).java.lang.AssertionError
- if the actual File
does not have the expected extension.public void assertHasName(AssertionInfo info, java.io.File actual, java.lang.String expected)
File
has the given name.info
- contains information about the assertion.actual
- the given file.expected
- the expected file name.java.lang.NullPointerException
- if the expected name is null
.java.lang.AssertionError
- if the actual File
is null
.java.lang.AssertionError
- if the actual File
does not have the expected name.public void assertHasNoParent(AssertionInfo info, java.io.File actual)
File
does not have a parent.info
- contains information about the assertion.actual
- the given file.java.lang.AssertionError
- if the actual File
is null
.java.lang.AssertionError
- if the actual File
has a parent.public void assertHasDigest(AssertionInfo info, java.io.File actual, java.security.MessageDigest digest, byte[] expected)
public void assertHasDigest(AssertionInfo info, java.io.File actual, java.security.MessageDigest digest, java.lang.String expected)
public void assertHasDigest(AssertionInfo info, java.io.File actual, java.lang.String algorithm, byte[] expected)
public void assertHasDigest(AssertionInfo info, java.io.File actual, java.lang.String algorithm, java.lang.String expected)
public void assertIsEmptyDirectory(AssertionInfo info, java.io.File actual)
public void assertIsNotEmptyDirectory(AssertionInfo info, java.io.File actual)
public void assertIsDirectoryContaining(AssertionInfo info, java.io.File actual, java.util.function.Predicate<java.io.File> filter)
public void assertIsDirectoryContaining(AssertionInfo info, java.io.File actual, java.lang.String syntaxAndPattern)
public void assertIsDirectoryNotContaining(AssertionInfo info, java.io.File actual, java.util.function.Predicate<java.io.File> filter)
public void assertIsDirectoryNotContaining(AssertionInfo info, java.io.File actual, java.lang.String syntaxAndPattern)
public static java.util.List<java.lang.String> toFileNames(java.util.List<java.io.File> files)
private java.util.List<java.io.File> filterDirectory(AssertionInfo info, java.io.File actual, java.util.function.Predicate<java.io.File> filter)
private java.util.List<java.io.File> directoryContent(AssertionInfo info, java.io.File actual)
private void assertIsDirectoryContaining(AssertionInfo info, java.io.File actual, java.util.function.Predicate<java.io.File> filter, java.lang.String filterPresentation)
private void assertIsDirectoryNotContaining(AssertionInfo info, java.io.File actual, java.util.function.Predicate<java.io.File> filter, java.lang.String filterPresentation)
private java.util.List<java.lang.String> directoryContentDescription(AssertionInfo info, java.io.File actual)
private java.util.function.Predicate<java.io.File> pathMatcher(AssertionInfo info, java.io.File actual, java.lang.String syntaxAndPattern)
private static void assertNotNull(AssertionInfo info, java.io.File actual)
private java.lang.String getFileExtension(java.io.File file)
private void verifyIsFile(java.io.File expected)
private boolean isAbsolutePath(AssertionInfo info, java.io.File actual)