Top Description Fields Constructors Methods
org.assertj.core.internal

public Class Files

extends Object
Class Inheritance
Static Imports
java.lang.String.format, java.nio.file.Files.readAllBytes, java.util.Comparator.comparing, .Objects.requireNonNull, java.util.stream.Collectors.toList, org.assertj.core.error.ShouldBeAbsolutePath.shouldBeAbsolutePath, .ShouldBeDirectory.shouldBeDirectory, .ShouldBeEmpty.shouldBeEmpty, .ShouldBeEmptyDirectory.shouldBeEmptyDirectory, .ShouldBeExecutable.shouldBeExecutable, .ShouldBeFile.shouldBeFile, .ShouldBeReadable.shouldBeReadable, .ShouldBeRelativePath.shouldBeRelativePath, .ShouldBeWritable.shouldBeWritable, .ShouldContain.directoryShouldContain, .ShouldContainRecursively.directoryShouldContainRecursively, .ShouldExist.shouldExist, .ShouldHaveBinaryContent.shouldHaveBinaryContent, .ShouldHaveContent.shouldHaveContent, .ShouldHaveDigest.shouldHaveDigest, .ShouldHaveExtension.shouldHaveExtension, .ShouldHaveName.shouldHaveName, .ShouldHaveNoExtension.shouldHaveNoExtension, .ShouldHaveNoParent.shouldHaveNoParent, .ShouldHaveParent.shouldHaveParent, .ShouldHaveSameContent.shouldHaveSameContent, .ShouldHaveSize.shouldHaveSize, .ShouldNotBeEmpty.shouldNotBeEmpty, .ShouldNotContain.directoryShouldNotContain, .ShouldNotExist.shouldNotExist, org.assertj.core.internal.Digests.digestDiff, org.assertj.core.util.Files.getFileNameExtension, .Lists.list, .Preconditions.checkArgument

Reusable assertions for Files.
Authors
David DIDIER, Yvonne Wang, Alex Ruiz, Olivier Demeijer, Valeriy Vyrva, Rostyslav Ivankiv

Field Summary

Modifier and TypeField and Description
private static final FileFilter
pack-priv BinaryDiff
pack-priv Diff
pack-priv Failures
private static final Files
pack-priv NioFilesWrapper
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
assertCanRead(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file can be read by the application.

public void
assertCanWrite(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file can be modified by the application.

public void
assertDoesNotExist(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file does not exist.

public void
assertExists(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file exists, regardless it's a file or directory.

public void
assertHasBinaryContent(AssertionInfo
contains information about the assertion.
info
,
File
the "actual" file.
actual
,
byte[]
the "expected" binary content.
expected
)

Asserts that the given file has the given binary content.

public void
assertHasContent(AssertionInfo
contains information about the assertion.
info
,
File
the "actual" file.
actual
,
String
the "expected" text content.
expected
,
Charset
the charset to use to read the file.
charset
)

Asserts that the given file has the given text content.

public void
assertHasDigest(AssertionInfo info, File actual, MessageDigest digest, byte[] expected)

public void
assertHasDigest(AssertionInfo info, File actual, MessageDigest digest, String expected)

public void
assertHasDigest(AssertionInfo info, File actual, String algorithm, byte[] expected)

public void
assertHasDigest(AssertionInfo info, File actual, String algorithm, String expected)

public void
assertHasExtension(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
,
String
the expected extension, it does not contains the '.'
expected
)

Asserts that the given File has the given extension.

public void
assertHasName(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
,
String
the expected file name.
expected
)

Asserts that the given File has the given name.

public void
public void
assertHasNoParent(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given File does not have a parent.

public void
assertHasParent(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
,
File
the expected parent File.
expected
)

Asserts that the given File has the given parent.

public void
assertHasSizeInBytes(AssertionInfo
contains information about the assertion.
info
,
File
the "actual" file.
actual
,
long
the "expected" file size.
expectedSizeInBytes
)

Asserts that the given file has the given size in bytes.

public void
assertIsAbsolute(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file is an absolute path.

public void
assertIsDirectory(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file is an existing directory.

public void
public void
assertIsDirectoryContaining(AssertionInfo info, File actual, String syntaxAndPattern)

private void
assertIsDirectoryContaining(AssertionInfo info, File actual, FileFilter filter, String filterPresentation)

public void
public void
assertIsDirectoryNotContaining(AssertionInfo info, File actual, String syntaxAndPattern)

private void
assertIsDirectoryNotContaining(AssertionInfo info, File actual, FileFilter filter, String filterPresentation)

public void
public void
private void
public void
public void
assertIsEmptyFile(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given File is empty (i.e. size is equal to zero bytes).

public void
assertIsExecutable(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file can be executed by the application.

public void
assertIsFile(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file is an existing file.

public void
public void
assertIsNotEmptyFile(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given File is not empty (i.e. size is greater than zero bytes).

public void
assertIsRelative(AssertionInfo
contains information about the assertion.
info
,
File
the given file.
actual
)

Asserts that the given file is a relative path.

private static void
public void
assertSameBinaryContentAs(AssertionInfo
contains information about the assertion.
info
,
File
the "actual" file.
actual
,
File
the "expected" file.
expected
)

Asserts that the given files have the same binary content.

public void
assertSameContentAs(AssertionInfo
contains information about the assertion.
info
,
File
the "actual" file.
actual
,
Charset
Charset of the "actual" file.
actualCharset
,
File
the "expected" file.
expected
,
Charset
Charset of the "actual" file.
expectedCharset
)

Asserts that the given files have same content.

private List<File>
private static FileFilter
fileFilter(AssertionInfo info, File actual, String syntaxAndPattern)

private List<File>
private Optional<String>
public static Files

Returns:

the singleton instance of this class.
instance
()

Returns the singleton instance of this class.

private boolean
private boolean
private Stream<File>
private List<File>
private void
verifyIsFile(File expected)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANYback to summary
private static final FileFilter ANY
binaryDiffback to summary
pack-priv BinaryDiff binaryDiff
Annotations
@VisibleForTesting
diffback to summary
pack-priv Diff diff
Annotations
@VisibleForTesting
failuresback to summary
pack-priv Failures failures
Annotations
@VisibleForTesting
INSTANCEback to summary
private static final Files INSTANCE
nioFilesWrapperback to summary
pack-priv NioFilesWrapper nioFilesWrapper
Annotations
@VisibleForTesting
UNABLE_TO_COMPARE_FILE_CONTENTSback to summary
private static final String UNABLE_TO_COMPARE_FILE_CONTENTS

Constructor Detail

Filesback to summary
pack-priv Files()
Annotations
@VisibleForTesting

Method Detail

assertCanReadback to summary
public void assertCanRead(AssertionInfo info, File actual)

Asserts that the given file can be read by the application.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file can not be modified.
assertCanWriteback to summary
public void assertCanWrite(AssertionInfo info, File actual)

Asserts that the given file can be modified by the application.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file can not be modified.
assertDoesNotExistback to summary
public void assertDoesNotExist(AssertionInfo info, File actual)

Asserts that the given file does not exist.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file exists.
assertExistsback to summary
public void assertExists(AssertionInfo info, File actual)

Asserts that the given file exists, regardless it's a file or directory.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file does not exist.
assertHasBinaryContentback to summary
public void assertHasBinaryContent(AssertionInfo info, File actual, byte[] expected)

Asserts that the given file has the given binary content.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the "actual" file.

expected:byte[]

the "expected" binary content.

Exceptions
NullPointerException:
if expected is null.
AssertionError:
  • if actual is null.
  • if actual is not an existing file.
  • if the file does not have the binary content.
UncheckedIOException:
if an I/O error occurs.
assertHasContentback to summary
public void assertHasContent(AssertionInfo info, File actual, String expected, Charset charset)

Asserts that the given file has the given text content.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the "actual" file.

expected:String

the "expected" text content.

charset:Charset

the charset to use to read the file.

Exceptions
NullPointerException:
if expected is null.
AssertionError:
  • if actual is null.
  • if actual is not an existing file.
  • if the file does not have the text content.
UncheckedIOException:
if an I/O error occurs.
assertHasDigestback to summary
public void assertHasDigest(AssertionInfo info, File actual, MessageDigest digest, byte[] expected)
assertHasDigestback to summary
public void assertHasDigest(AssertionInfo info, File actual, MessageDigest digest, String expected)
assertHasDigestback to summary
public void assertHasDigest(AssertionInfo info, File actual, String algorithm, byte[] expected)
assertHasDigestback to summary
public void assertHasDigest(AssertionInfo info, File actual, String algorithm, String expected)
assertHasExtensionback to summary
public void assertHasExtension(AssertionInfo info, File actual, String expected)

Asserts that the given File has the given extension.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

expected:String

the expected extension, it does not contains the '.'

Exceptions
NullPointerException:
if the expected extension is null.
AssertionError:
  • if the actual File is null.
  • if the actual File is not a file (ie a directory).
  • if the actual File does not have the expected extension.
assertHasNameback to summary
public void assertHasName(AssertionInfo info, File actual, String expected)

Asserts that the given File has the given name.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

expected:String

the expected file name.

Exceptions
NullPointerException:
if the expected name is null.
AssertionError:
  • if the actual File is null.
  • if the actual File does not have the expected name.
assertHasNoExtensionback to summary
public void assertHasNoExtension(AssertionInfo info, File actual)
assertHasNoParentback to summary
public void assertHasNoParent(AssertionInfo info, File actual)

Asserts that the given File does not have a parent.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the actual File is null.
  • if the actual File has a parent.
assertHasParentback to summary
public void assertHasParent(AssertionInfo info, File actual, File expected)

Asserts that the given File has the given parent.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

expected:File

the expected parent File.

Exceptions
NullPointerException:
if the expected parent File is null.
UncheckedIOException:
if an I/O error occurs.
AssertionError:
  • if the given File is null.
  • if the given File does not have a parent.
  • if the given File parent is not equal to the expected one.
assertHasSizeInBytesback to summary
public void assertHasSizeInBytes(AssertionInfo info, File actual, long expectedSizeInBytes)

Asserts that the given file has the given size in bytes.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the "actual" file.

expectedSizeInBytes:long

the "expected" file size.

Exceptions
AssertionError:
  • if actual is null.
  • if actual is not an existing file.
assertIsAbsoluteback to summary
public void assertIsAbsolute(AssertionInfo info, File actual)

Asserts that the given file is an absolute path.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file is not an absolute path.
assertIsDirectoryback to summary
public void assertIsDirectory(AssertionInfo info, File actual)

Asserts that the given file is an existing directory.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file is not an existing directory.
assertIsDirectoryContainingback to summary
public void assertIsDirectoryContaining(AssertionInfo info, File actual, Predicate<File> filter)
assertIsDirectoryContainingback to summary
public void assertIsDirectoryContaining(AssertionInfo info, File actual, String syntaxAndPattern)
assertIsDirectoryContainingback to summary
private void assertIsDirectoryContaining(AssertionInfo info, File actual, FileFilter filter, String filterPresentation)
assertIsDirectoryNotContainingback to summary
public void assertIsDirectoryNotContaining(AssertionInfo info, File actual, Predicate<File> filter)
assertIsDirectoryNotContainingback to summary
public void assertIsDirectoryNotContaining(AssertionInfo info, File actual, String syntaxAndPattern)
assertIsDirectoryNotContainingback to summary
private void assertIsDirectoryNotContaining(AssertionInfo info, File actual, FileFilter filter, String filterPresentation)
assertIsDirectoryRecursivelyContainingback to summary
public void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File actual, String syntaxAndPattern)
assertIsDirectoryRecursivelyContainingback to summary
public void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File actual, Predicate<File> filter)
assertIsDirectoryRecursivelyContainingback to summary
private void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File actual, Predicate<File> filter, String filterPresentation)
assertIsEmptyDirectoryback to summary
public void assertIsEmptyDirectory(AssertionInfo info, File actual)
assertIsEmptyFileback to summary
public void assertIsEmptyFile(AssertionInfo info, File actual)

Asserts that the given File is empty (i.e. size is equal to zero bytes).

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given File is null.
  • if the given File does not exist.
  • if the given File is not empty.
assertIsExecutableback to summary
public void assertIsExecutable(AssertionInfo info, File actual)

Asserts that the given file can be executed by the application.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file can not be executed.
assertIsFileback to summary
public void assertIsFile(AssertionInfo info, File actual)

Asserts that the given file is an existing file.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file is not an existing file.
assertIsNotEmptyDirectoryback to summary
public void assertIsNotEmptyDirectory(AssertionInfo info, File actual)
assertIsNotEmptyFileback to summary
public void assertIsNotEmptyFile(AssertionInfo info, File actual)

Asserts that the given File is not empty (i.e. size is greater than zero bytes).

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given File is null.
  • if the given File does not exist.
  • if the given File is empty.
assertIsRelativeback to summary
public void assertIsRelative(AssertionInfo info, File actual)

Asserts that the given file is a relative path.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the given file.

Exceptions
AssertionError:
  • if the given file is null.
  • if the given file is not a relative path.
assertNotNullback to summary
private static void assertNotNull(AssertionInfo info, File actual)
assertSameBinaryContentAsback to summary
public void assertSameBinaryContentAs(AssertionInfo info, File actual, File expected)

Asserts that the given files have the same binary content.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the "actual" file.

expected:File

the "expected" file.

Exceptions
NullPointerException:
if expected is null.
IllegalArgumentException:
if expected is not an existing file.
AssertionError:
  • if actual is null.
  • if actual is not an existing file.
  • if the given files do not have same content.
UncheckedIOException:
if an I/O error occurs.
assertSameContentAsback to summary
public void assertSameContentAs(AssertionInfo info, File actual, Charset actualCharset, File expected, Charset expectedCharset)

Asserts that the given files have same content. Adapted from FileAssert (from JUnit-addons.)

Parameters
info:AssertionInfo

contains information about the assertion.

actual:File

the "actual" file.

actualCharset:Charset

Charset of the "actual" file.

expected:File

the "expected" file.

expectedCharset:Charset

Charset of the "actual" file.

Exceptions
NullPointerException:
if expected is null.
IllegalArgumentException:
if expected is not an existing file.
AssertionError:
  • if actual is null.
  • if actual is not an existing file.
  • if the given files do not have same content.
UncheckedIOException:
if an I/O error occurs.
directoryContentback to summary
private List<File> directoryContent(AssertionInfo info, File actual)
fileFilterback to summary
private static FileFilter fileFilter(AssertionInfo info, File actual, String syntaxAndPattern)
filterDirectoryback to summary
private List<File> filterDirectory(AssertionInfo info, File actual, FileFilter filter)
getFileExtensionback to summary
private Optional<String> getFileExtension(File file)
instanceback to summary
public static Files instance()

Returns the singleton instance of this class.

Returns:Files

the singleton instance of this class.

isAbsolutePathback to summary
private boolean isAbsolutePath(AssertionInfo info, File actual)
isDirectoryRecursivelyContainingback to summary
private boolean isDirectoryRecursivelyContaining(AssertionInfo info, File actual, Predicate<File> filter)
recursiveContentOfback to summary
private Stream<File> recursiveContentOf(File directory)
sortedRecursiveContentback to summary
private List<File> sortedRecursiveContent(File directory)
verifyIsFileback to summary
private void verifyIsFile(File expected)