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

public abstract Class AbstractFileAssert<SELF extends AbstractFileAssert<SELF>>

extends AbstractAssert<SELF extends AbstractFileAssert<SELF>, File>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.FileAssert
Type Parameters
<SELF>
the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
Static Imports
java.lang.String.format, java.nio.file.Files.readAllBytes, java.util.Objects.requireNonNull, org.assertj.core.util.Preconditions.checkArgument

Base class for all implementations of assertions for Files.
Authors
David DIDIER, Yvonne Wang, Alex Ruiz, Olivier Michallat, Olivier Demeijer, Mikhail Mazursky, Jean-Christophe Gay, Valeriy Vyrva, Nikolaos Georgiou, Rostyslav Ivankiv

Field Summary

Modifier and TypeField and Description
pack-priv Charset
pack-priv Files
Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractFileAssert(File actual, Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
public AbstractByteArrayAssert<?>

Returns:

a AbstractByteArrayAssert object with the binary content of the file.
binaryContent
()

Returns ByteArray assertions on the content of the actual File read.

public SELF

Returns:

this assertion object.
canRead
()

Verifies that the actual File can be read by the application.

public SELF

Returns:

this assertion object.
canWrite
()

Verifies that the actual File can be modified by the application.

public AbstractStringAssert<?>

Returns:

a StringAssert object with the content of the actual File read with the default Charset.
content
()

Returns String assertions on the content of the actual File read with the default charset.

public AbstractStringAssert<?>

Returns:

a StringAssert object with the content of the actual File read with the default Charset.
content
(Charset
the Charset to use to read the actual File.
charset
)

Returns String assertions on the content of the actual File read with the given Charset.

public SELF

Returns:

this assertion object.
doesNotExist
()

Verifies that the actual File does not exist.

public SELF

Returns:

this assertion object.
exists
()

Verifies that the actual File exists, regardless it's a file or directory.

public SELF

Returns:

this assertion object.
hasBinaryContent
(byte[]
the expected binary content to compare the actual File's content to.
expected
)

Verifies that the binary content of the actual File is exactly equal to the given one.

public SELF

Returns:

this assertion object.
hasContent
(String
the expected text content to compare the actual File's content to.
expected
)

Verifies that the text content of the actual File is exactly equal to the given one except for newlines wich are ignored.

public SELF

Returns:

this assertion object.
hasContentEqualTo
(File
the given File to compare the actual File to.
expected
)

Deprecated use hasSameTextualContentAs(File) instead
Verifies that the content of the actual File is equal to the content of the given one.
public SELF

Returns:

this assertion object.
hasDigest
(MessageDigest
the MessageDigest used to calculate the digests.
digest
,
byte[]
the expected binary content to compare the actual File's content to.
expected
)

Verifies that the tested File digest (calculated with the specified MessageDigest) is equal to the given one.

public SELF

Returns:

this assertion object.
hasDigest
(MessageDigest
the MessageDigest used to calculate the digests.
digest
,
String
the expected binary content to compare the actual File's content to.
expected
)

Verifies that the tested File digest (calculated with the specified MessageDigest) is equal to the given one.

public SELF

Returns:

this assertion object.
hasDigest
(String
the algorithm used to calculate the digests.
algorithm
,
byte[]
the expected digest to compare the actual File's digest to.
expected
)

Verifies that the tested File digest (calculated with the specified algorithm) is equal to the given one.

public SELF

Returns:

this assertion object.
hasDigest
(String
the algorithm used to calculate the digests.
algorithm
,
String
the expected digest to compare the actual File's digest to.
expected
)

Verifies that the tested File digest (calculated with the specified algorithm) is equal to the given one.

public SELF

Returns:

this assertion object.
hasExtension
(String
the expected extension, it does not contain the '.'
expected
)

Verifies that the actual File has given extension.

public SELF

Returns:

this assertion object.
hasFileName
(String
the expected File name.
expected
)

Verifies that the actual File has given name (alias of hasName(String)).

public SELF

Returns:

this assertion object.
hasName
(String
the expected File name.
expected
)

Verifies that the actual File has given name.

public SELF

Returns:

this assertion object.
hasNoExtension
()

Verifies that the actual File has no extension.

public SELF

Returns:

this assertion object.
hasNoParent
()

Verifies that the actual File does not have a parent.

public SELF

Returns:

this assertion object.
hasParent
(File
the expected parent File.
expected
)

Verifies that the actual File has given parent.

public SELF

Returns:

this assertion object.
hasParent
(String
the expected parent file path.
expected
)

Same as hasParent(java.io.File) but takes care of converting given String as File for you

Example:

 File xFile = new File("mulder/xFile");

// assertion will pass
assertThat(xFile).hasParent("mulder");

// assertion will fail
assertThat(xFile).hasParent("scully");
public SELF

Returns:

this assertion object.
hasSameBinaryContentAs
(File
the given File to compare the actual File to.
expected
)

Verifies that the content of the actual File is equal to the content of the given one, the comparison is done at the binary level.

public SELF

Returns:

this assertion object.
hasSameContentAs
(File
the given File to compare the actual File to.
expected
)

Deprecated use hasSameTextualContentAs(File) instead.
public SELF

Returns:

this assertion object.
hasSameContentAs
(File
the given File to compare the actual File to.
expected
,
Charset
the Charset used to read the content of the expected file.
expectedCharset
)

Verifies that the content of the actual File is the same as the expected one, the expected File being read with the given charset while the charset used to read the actual path can be provided with usingCharset(Charset) or usingCharset(String) prior to calling this method; if not, the platform's default charset (as returned by Charset#defaultCharset()) will be used.
public SELF

Returns:

this assertion object.
hasSameTextualContentAs
(File
the given File to compare the actual File to.
expected
)

Verifies that the content of the actual File is equal to the content of the given one.

public SELF

Returns:

this assertion object.
hasSameTextualContentAs
(File
the given File to compare the actual File to.
expected
,
Charset
the Charset used to read the content of the expected file.
expectedCharset
)

Verifies that the content of the actual File is the same as the expected one, the expected File being read with the given charset while the charset used to read the actual path can be provided with usingCharset(Charset) or usingCharset(String) prior to calling this method; if not, the platform's default charset (as returned by Charset#defaultCharset()) will be used.

public SELF

Returns:

this assertion object.
hasSize
(long
the expected File's size in bytes.
expectedSizeInBytes
)

Verifies that the size of the File under test is exactly equal to the given size in bytes.

private AbstractStringAssert<?>
public SELF

Returns:

this assertion object.
isAbsolute
()

Verifies that the actual File is an absolute path.

public SELF

Returns:

this assertion object.
isDirectory
()

Verifies that the actual File is an existing directory.

public SELF

Returns:

this assertion object.
isDirectoryContaining
(Predicate<File>
the filter for files located inside actual's directory.
filter
)

Verify that the actual File is a directory containing at least one file matching the given Predicate<File>.

public SELF

Returns:

this assertion object.
isDirectoryContaining
(String
the syntax and pattern for java.nio.file.PathMatcher as described in FileSystem#getPathMatcher(String).
syntaxAndPattern
)

Verify that the actual File is a directory containing at least one file matching the given String interpreted as a path matcher (as per FileSystem#getPathMatcher(String)).

public SELF

Returns:

this assertion object.
isDirectoryNotContaining
(Predicate<File>
the filter for files located inside actual's directory.
filter
)

Verify that the actual File is a directory that does not contain any files matching the given Predicate<File>.

public SELF

Returns:

this assertion object.
isDirectoryNotContaining
(String
the syntax and pattern for java.nio.file.PathMatcher as described in FileSystem#getPathMatcher(String).
syntaxAndPattern
)

Verify that the actual File is a directory that does not contain any files matching the given String interpreted as a path matcher (as per FileSystem#getPathMatcher(String)).

public SELF

Returns:

this assertion object.
isDirectoryRecursivelyContaining
(String
the syntax and pattern for java.nio.file.PathMatcher as described in FileSystem#getPathMatcher(String).
syntaxAndPattern
)

Verify that the actual File directory or any of its subdirectories (recursively) contains at least one file matching the given String interpreted as a path matcher (as per FileSystem#getPathMatcher(String)).

public SELF

Returns:

this assertion object.
isDirectoryRecursivelyContaining
(Predicate<File>
the filter for files located inside actual's directory.
filter
)

Verify that the actual File directory or any of its subdirectories (recursively) contains at least one file matching the given Predicate<File>.

public SELF

Returns:

this assertion object.
isEmpty
()

Verify that the actual File is empty (i.e. the file size = 0).

public SELF

Returns:

this assertion object.
isEmptyDirectory
()

Verify that the actual File is an empty directory.

public SELF

Returns:

this assertion object.
isExecutable
()

Verifies that the actual File is executable.

public SELF

Returns:

this assertion object.
isFile
()

Verifies that the actual File is an existing file.

public SELF

Returns:

this assertion object.
isNotEmpty
()

Verify that the actual File is not empty (i.e. the file size > 0).

public SELF

Returns:

this assertion object.
isNotEmptyDirectory
()

Verify that the actual File is a non-empty directory.

public SELF

Returns:

this assertion object.
isReadable
()

Verifies that the actual File can be read by the application (alias of canRead())

Example:

 File tmpFile = File.createTempFile("tmp", "txt");
File tmpDir = Files.createTempDirectory("tmp").toFile();

// assertions will pass
assertThat(tmpFile).isReadable();
assertThat(tmpDir).isReadable();

tmpFile.setReadable(false);
tmpDir.setReadable(false);

// assertions will fail
assertThat(tmpFile).isReadable();
assertThat(tmpDir).isReadable();
public SELF

Returns:

this assertion object.
isRelative
()

Verifies that the actual File is a relative path.

public SELF

Returns:

this assertion object.
isWritable
()

Verifies that the actual File can be modified by the application (alias of canWrite()).

private byte[]
private String
readFile(Charset charset)

public AbstractFileSizeAssert<SELF>

Returns:

AbstractFileSizeAssert built with the File's size.
size
()

Returns an Assert object that allows performing assertions on the size of the File under test.

public SELF

Returns:

this assertion object.
usingCharset
(String
the name of the charset to use.
charsetName
)

Specifies the name of the charset to use for text-based assertions on the file's contents.

public SELF

Returns:

this assertion object.
usingCharset
(Charset
the charset to use.
charset
)

Specifies the charset to use for text-based assertions on the file's contents.

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingComparatorusingComparatorusingDefaultComparatorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError