S
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.public abstract class AbstractFileAssert<S extends AbstractFileAssert<S>> extends AbstractAssert<S,File>
File
s.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractFileAssert(File actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
canRead()
Verifies that the actual
File can be read by the application. |
S |
canWrite()
Verifies that the actual
File can be modified by the application. |
S |
doesNotExist()
Verifies that the actual
File does not exist. |
S |
exists()
Verifies that the actual
File exists, regardless it's a file or directory. |
S |
hasBinaryContent(byte[] expected)
Verifies that the binary content of the actual
File is exactly equal to the given one. |
S |
hasContent(String expected)
Verifies that the text content of the actual
File is exactly equal to the given one.The charset to use when reading the file should 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. |
S |
hasContentEqualTo(File expected)
Deprecated.
use hasSameContentAs
|
S |
hasExtension(String expected)
Verifies that the actual
File has given extension. |
S |
hasName(String expected)
Verifies that the actual
File has given name. |
S |
hasNoParent()
Verifies that the actual
File does not have a parent. |
S |
hasParent(File expected)
Verifies that the actual
File has given parent. |
S |
hasParent(String expected)
|
S |
hasSameContentAs(File expected)
Verifies that the content of the actual
File is equal to the content of the given one. |
S |
isAbsolute()
Verifies that the actual
File is an absolute path. |
S |
isDirectory()
Verifies that the actual
File is an existing directory. |
S |
isFile()
Verifies that the actual
File is an existing file. |
S |
isRelative()
Verifies that the actual
File is a relative path. |
S |
usingCharset(Charset charset)
Specifies the charset to use for text-based assertions on the file's contents.
|
S |
usingCharset(String charsetName)
Specifies the name of the charset to use for text-based assertions on the file's contents.
|
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failure, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, usingComparator, usingDefaultComparator, withThreadDumpOnError
public S exists()
File
exists, regardless it's a file or directory.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
does not exist.public S doesNotExist()
File
does not exist.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
exists.public S isFile()
File
is an existing file.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an existing file.public S isDirectory()
File
is an existing directory.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an existing file.public S isAbsolute()
File
is an absolute path.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an absolute path.public S isRelative()
File
is a relative path.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not a relative path.@Deprecated public S hasContentEqualTo(File expected)
File
is equal to the content of the given one.expected
- the given File
to compare the actual File
to.this
assertion object.NullPointerException
- if the given File
is null
.IllegalArgumentException
- if the given File
is not an existing file.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an existing file.RuntimeIOException
- if an I/O error occurs.AssertionError
- if the content of the actual File
is not equal to the content of the given one.public S hasSameContentAs(File expected)
File
is equal to the content of the given one.expected
- the given File
to compare the actual File
to.this
assertion object.NullPointerException
- if the given File
is null
.IllegalArgumentException
- if the given File
is not an existing file.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an existing file.RuntimeIOException
- if an I/O error occurs.AssertionError
- if the content of the actual File
is not equal to the content of the given one.public S hasBinaryContent(byte[] expected)
File
is exactly equal to the given one.expected
- the expected binary content to compare the actual File
's content to.this
assertion object.NullPointerException
- if the given content is null
.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an existing file.RuntimeIOException
- if an I/O error occurs.AssertionError
- if the content of the actual File
is not equal to the given binary content.public S usingCharset(String charsetName)
charsetName
- the name of the charset to use.this
assertion object.IllegalArgumentException
- if the given encoding is not supported on this platform.public S usingCharset(Charset charset)
charset
- the charset to use.this
assertion object.NullPointerException
- if the given charset is null
.public S hasContent(String expected)
File
is exactly equal to the given one.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.expected
- the expected text content to compare the actual File
's content to.this
assertion object.NullPointerException
- if the given content is null
.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not an existing file.RuntimeIOException
- if an I/O error occurs.AssertionError
- if the content of the actual File
is not equal to the given content.public S canWrite()
File
can be modified by the application.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
can not be modified by the application.public S canRead()
File
can be read by the application.this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
can not be read by the application.public S hasParent(File expected)
File
has given parent.
Example:
File xFile = new File("mulder/xFile");
// assertion will pass
assertThat(xFile).hasParent(new File("mulder"));
// assertion will fail
assertThat(xFile).hasParent(new File("scully"));
expected
- the expected parent File
.this
assertion object.NullPointerException
- if the expected parent File
is null
.RuntimeIOException
- if an I/O error occurs.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
parent is not equal to the expected one.parent definition.
public S hasParent(String expected)
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 S hasExtension(String expected)
File
has given extension.
Example:
File xFile = new File("xFile.java");
// assertion will pass
assertThat(xFile).hasExtension("java");
// assertion will fail
assertThat(xFile).hasExtension("png");
expected
- the expected extension, it does not contains the '.'
this
assertion object.NullPointerException
- if the expected extension is null
.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
is not a file (ie a directory).AssertionError
- if the actual File
does not have the expected extension.public S hasName(String expected)
File
has given name.
Example:
File xFile = new File("somewhere/xFile.java");
File xDirectory = new File("somewhere/xDirectory");
// assertion will pass
assertThat(xFile).hasName("xFile.java");
assertThat(xDirectory).hasName("xDirectory");
// assertion will fail
assertThat(xFile).hasName("xFile");
assertThat(xDirectory).hasName("somewhere");
expected
- the expected File
name.this
assertion object.NullPointerException
- if the expected name is null
.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
does not have the expected name.name definition.
public S hasNoParent()
File
does not have a parent.
Example:
File xFile = new File("somewhere/xFile.java");
File xDirectory = new File("xDirectory");
// assertion will pass
assertThat(xDirectory).hasNoParent();
// assertion will fail
assertThat(xFile).hasNoParent();
this
assertion object.AssertionError
- if the actual File
is null
.AssertionError
- if the actual File
has a parent.Copyright © 2014-2015 AssertJ. All Rights Reserved.