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

public abstract Class AbstractPathAssert<SELF extends AbstractPathAssert<SELF>>

extends AbstractComparableAssert<SELF extends AbstractPathAssert<SELF>, Path>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.PathAssert
Type Parameters
<SELF>
self type
Static Imports
java.lang.String.format, java.nio.file.Files.readAllBytes, java.util.Objects.requireNonNull, org.assertj.core.util.Preconditions.checkArgument

Assertions for Path objects

Note that some assertions have two versions: a normal one and a "raw" one (for instance, hasParent() and hasParentRaw(). The difference is that normal assertions will canonicalize or normalize the tested path and, where applicable, the path argument, before performing the actual test. Canonicalization includes normalization.

Canonicalization may lead to an I/O error if a path does not exist, in which case the given assertions will fail with a PathsException. Also note that symbolic links will be followed if the filesystem supports them. Finally, if a path is not absolute, canonicalization will resolve the path against the process' current working directory.

These assertions are filesystem independent. You may use them on Path instances issued from the default filesystem (ie, instances you get when using java.nio.file.Paths#get(String, String...)) or from other filesystems. For more information, see the javadoc for FileSystem.

Furthermore:

Author
Valeriy Vyrva
See Also
Path, java.nio.file.Paths#get(String, String...), FileSystem, FileSystem#getPath(String, String...), java.nio.file.FileSystems#getDefault(), Files

Field Summary

Modifier and TypeField and Description
pack-priv Charset
protected Paths
Inherited from org.assertj.core.api.AbstractComparableAssert:
comparables

Constructor Summary

AccessConstructor and Description
protected
AbstractPathAssert(final Path actual, final Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
public AbstractByteArrayAssert<?>

Returns:

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

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

public AbstractStringAssert<?>

Returns:

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

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

public AbstractStringAssert<?>

Returns:

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

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

public SELF

Returns:

self
doesNotExist
()

Assert that the tested Path does not exist.

public SELF

Returns:

self
endsWith
(final Path
the other path
other
)

Assert that the tested Path ends with the given path.

public SELF

Returns:

self
endsWithRaw
(final Path
the other path
other
)

Assert that the tested Path ends with the given path.

public SELF

Returns:

self
exists
()

Assert that the tested Path exists according to Files#exists(Path))

Note that this assertion will follow symbolic links before asserting the path's existence.

public SELF

Returns:

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

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

public SELF

Returns:

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

Verifies that the text content of the actual Path (which must be a readable file) is exactly equal to the given one except for newlines wich are ignored.

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 Path's content to.
expected
)

Verifies that the tested Path 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 Path's content to.
expected
)

Verifies that the tested Path 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 to compare.
algorithm
,
byte[]
the expected binary content to compare the actual Path's content to.
expected
)

Verifies that the tested Path 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 Path's digest to.
expected
)

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

public SELF

Returns:

this assertion object.
hasExtension
(String
the expected extension, without the '.'.
expectedExtension
)

Verifies that the actual Path has given extension.

public SELF

Returns:

self
hasFileName
(final String
the expected filename
fileName
)

Assert that the tested Path last element String representation is equal to the given filename.

public SELF

Returns:

this assertion object.
hasFileSystem
(FileSystem
the given FileSystem to compare the actual Path file system to.
expected
)

Verifies that the path has the given file system.

public SELF

Returns:

this assertion object.
hasNoExtension
()

Verifies that the actual Path has no extension.

public SELF

Returns:

self
hasNoParent
()

Assert that the tested Path has no parent.

public SELF

Returns:

self
hasNoParentRaw
()

Assert that the tested Path has no parent.

public SELF

Returns:

self
hasParent
(final Path
the expected parent path
expected
)

Assert that the tested Path has the expected parent path.

public SELF

Returns:

self
hasParentRaw
(final Path
the expected parent path
expected
)

Assert that the tested Path has the expected parent path.

public SELF

Returns:

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

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

public SELF

Returns:

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

Deprecated use hasSameTextualContentAs(Path) instead

Verifies that the content of the actual Path is the same as the given one (both paths must be a readable files).

public SELF

Returns:

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

Deprecated use hasSameTextualContentAs(Path, Charset) instead

Verifies that the content of the actual Path is the same as the expected one, the expected Path 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.
hasSameFileSystemAs
(Path
the given Path to compare the actual Path file system to.
expected
)

Verifies that the path file system is the same as the given path file system.

public SELF

Returns:

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

Verifies that the content of the actual Path is the same as the given one (both paths must be a readable files).

public SELF

Returns:

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

Verifies that the content of the actual Path is the same as the expected one, the expected Path 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 Path file size in bytes
expectedSize
)

Assert that the tested Path has the given size in bytes.

private AbstractStringAssert<?>
public SELF

Returns:

self
isAbsolute
()

Assert that the tested Path is absolute (the path does not have to exist).

public SELF

Returns:

self
isCanonical
()

Assert that the tested Path is canonical by comparing it to its real path.

public SELF

Returns:

self
isDirectory
()

Assert that the tested Path is a directory.

public SELF

Returns:

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

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

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 Path 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<Path>
the filter for files located inside actual's directory.
filter
)

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

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 Path 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 Path 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<Path>
the filter for files located inside actual's directory.
filter
)

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

public SELF

Returns:

this assertion object.
isEmptyDirectory
()

Verify that the actual Path is an empty directory.

public SELF

Returns:

this assertion object.
isEmptyFile
()

Verify that the actual Path is an empty regular file.

public SELF

Returns:

self
isExecutable
()

Assert that the tested Path is an executable file, it checks that the file exists (according to Files#exists(Path, LinkOption...)) and that it is executable(according to Files#isExecutable(Path) ).

public SELF

Returns:

self
isNormalized
()

Assert that the tested Path is normalized.

public SELF

Returns:

this assertion object.
isNotEmptyDirectory
()

Verify that the actual Path is a non empty directory.

public SELF

Returns:

this assertion object.
isNotEmptyFile
()

Verify that the actual Path is a non-empty regular file.

public SELF

Returns:

self
isReadable
()

Assert that the tested Path is a readable file, it checks that the file exists (according to Files#exists(Path, LinkOption...)) and that it is readable(according to Files#isReadable(Path)).

public SELF

Returns:

self
isRegularFile
()

Assert that the tested Path is a regular file.

public SELF

Returns:

self
isRelative
()

Assert that the tested Path is relative (opposite to Path#isAbsolute()).

public SELF

Returns:

self
isWritable
()

Assert that the tested Path is a writable file, it checks that the file exists (according to Files#exists(Path, LinkOption...)) and that it is writable(according to Files#isWritable(Path)).

private byte[]
private String
readPath(Charset charset)

public SELF

Returns:

self
startsWith
(final Path
the other path
other
)

Assert that the tested Path starts with the given path.

public SELF

Returns:

self
startsWithRaw
(final Path
the other path
other
)

Assert that the tested Path starts with the given path.

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 path's contents (path must be a readable file).

public SELF

Returns:

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

Specifies the charset to use for text-based assertions on the path's contents (path must be a readable file).

Inherited from org.assertj.core.api.AbstractComparableAssert:
inBinaryinHexadecimalisBetweenisEqualByComparingToisGreaterThanisGreaterThanOrEqualToisLessThanisLessThanOrEqualToisNotEqualByComparingToisStrictlyBetweenusingComparatorusingComparatorusingDefaultComparator