Package org.fest.assertions.api
Class FileAssert
- java.lang.Object
-
- org.fest.assertions.api.AbstractAssert<FileAssert,java.io.File>
-
- org.fest.assertions.api.FileAssert
-
- All Implemented Interfaces:
Assert<FileAssert,java.io.File>,Descriptable<FileAssert>,ExtensionPoints<FileAssert,java.io.File>
public class FileAssert extends AbstractAssert<FileAssert,java.io.File>
Assertion methods fors.FileTo create a new instance of this class, invoke
.Assertions.assertThat(File)- Author:
- David DIDIER, Yvonne Wang, Alex Ruiz, Olivier Michallat, Olivier Demeijer
-
-
Field Summary
-
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFileAssert(java.io.File actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileAssertcanRead()Verifies that the actualFilecan be read by the application.FileAssertcanWrite()Verifies that the actualFilecan be modified by the application.FileAssertdoesNotExist()Verifies that the actualFiledoes not exist.FileAssertexists()Verifies that the actualFileexists, regardless it's a file or directory.FileAsserthasBinaryContent(byte[] expected)Verifies that the binary content of the actualFileis exactly equal to the given one.FileAsserthasContent(java.lang.String expected)Verifies that the text content of the actualFileis exactly equal to the given one.
The charset to use when reading the file should be provided withusingCharset(Charset)orusingCharset(String)prior to calling this method; if not, the platform's default charset (as returned byCharset.defaultCharset()) will be used.FileAsserthasContentEqualTo(java.io.File expected)Verifies that the content of the actualFileis equal to the content of the given one.FileAssertisAbsolute()Verifies that the actualFileis an absolute path.FileAssertisDirectory()Verifies that the actualFileis an existing directory.FileAssertisFile()Verifies that the actualFileis an existing file.FileAssertisRelative()Verifies that the actualFileis a relative path.FileAssertusingCharset(java.lang.String charsetName)Specifies the name of the charset to use for text-based assertions on the file's contents.FileAssertusingCharset(java.nio.charset.Charset charset)Specifies the charset to use for text-based assertions on the file's contents.-
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
-
-
-
-
Method Detail
-
exists
public FileAssert exists()
Verifies that the actualFileexists, regardless it's a file or directory.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFiledoes not exist.
-
doesNotExist
public FileAssert doesNotExist()
Verifies that the actualFiledoes not exist.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileexists.
-
isFile
public FileAssert isFile()
Verifies that the actualFileis an existing file.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not an existing file.
-
isDirectory
public FileAssert isDirectory()
Verifies that the actualFileis an existing directory.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not an existing file.
-
isAbsolute
public FileAssert isAbsolute()
Verifies that the actualFileis an absolute path.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not an absolute path.
-
isRelative
public FileAssert isRelative()
Verifies that the actualFileis a relative path.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not a relative path.
-
hasContentEqualTo
public FileAssert hasContentEqualTo(java.io.File expected)
Verifies that the content of the actualFileis equal to the content of the given one.- Parameters:
expected- the givenFileto compare the actualFileto.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the givenFileisnull.java.lang.IllegalArgumentException- if the givenFileis not an existing file.java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not an existing file.org.fest.util.FilesException- if an I/O error occurs.java.lang.AssertionError- if the content of the actualFileis not equal to the content of the given one.
-
hasBinaryContent
public FileAssert hasBinaryContent(byte[] expected)
Verifies that the binary content of the actualFileis exactly equal to the given one.- Parameters:
expected- the expected binary content to compare the actualFile's content to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given content isnull.java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not an existing file.org.fest.util.FilesException- if an I/O error occurs.java.lang.AssertionError- if the content of the actualFileis not equal to the given binary content.
-
usingCharset
public FileAssert usingCharset(java.lang.String charsetName)
Specifies the name of the charset to use for text-based assertions on the file's contents.- Parameters:
charsetName- the name of the charset to use.- Returns:
thisassertion object.- Throws:
java.lang.IllegalArgumentException- if the given encoding is not supported on this platform.
-
usingCharset
public FileAssert usingCharset(java.nio.charset.Charset charset)
Specifies the charset to use for text-based assertions on the file's contents.- Parameters:
charset- the charset to use.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given charset isnull.
-
hasContent
public FileAssert hasContent(java.lang.String expected)
Verifies that the text content of the actualFileis exactly equal to the given one.
The charset to use when reading the file should be provided withusingCharset(Charset)orusingCharset(String)prior to calling this method; if not, the platform's default charset (as returned byCharset.defaultCharset()) will be used.- Parameters:
expected- the expected text content to compare the actualFile's content to.- Returns:
thisassertion object.- Throws:
java.lang.NullPointerException- if the given content isnull.java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFileis not an existing file.org.fest.util.FilesException- if an I/O error occurs.java.lang.AssertionError- if the content of the actualFileis not equal to the given binary content.
-
canWrite
public FileAssert canWrite()
Verifies that the actualFilecan be modified by the application.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFilecan not be modified by the application.
-
canRead
public FileAssert canRead()
Verifies that the actualFilecan be read by the application.- Returns:
thisassertion object.- Throws:
java.lang.AssertionError- if the actualFileisnull.java.lang.AssertionError- if the actualFilecan not be read by the application.
-
-