Package org.fest.assertions
Class FileAssert
Understands assertion methods for
File. To create a new instance of this class use the method
Assertions.assertThat(File).-
Field Summary
FieldsFields inherited from class org.fest.assertions.GenericAssert
actual -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFileAssert(File actual) Creates a newFileAssert.(package private)FileAssert(File actual, FileContentComparator comparator) -
Method Summary
Modifier and TypeMethodDescriptionSets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErroras(Description description) Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrorprivate FileAssertassertExists(File file) private voidcannotCompareToExpectedFile(File expected, Exception e) describedAs(String description) Alias for, since "as" is a keyword in Groovy.GenericAssert.as(String)describedAs(Description description) Alias for, since "as" is a keyword in Groovy.GenericAssert.as(Description)Verifies that the actualFiledoes not exist.doesNotSatisfy(Condition<File> condition) Verifies that the actualFiledoes not satisfy the given condition.exists()Verifies that the actualFiledoes exist.private voidfail(File expected, FileContentComparator.LineDiff[] diffs) hasSameContentAs(File expected) Verifies that the content of the actualFileis equal to the content of the given one.hasSize(long expected) Verifies that the size of the actualFileis equal to the given one.Verifies that the actualFilesatisfies the given condition.Verifies that the actualFileis an absolute path.Verifies that the actualFileis a directory.Verifies that the actualFileis equal to the given one.isFile()Verifies that the actualFileis a regular file.Verifies that the actualFiledoes not satisfy the given condition.isNotEqualTo(File other) Verifies that the actualFileis not equal to the given one.Verifies that the actualFileis notnull.isNotSameAs(File other) Verifies that the actualFileis not the same as the given one.Verifies that the actualFileis a relative path.Verifies that the actualFileis the same as the given one.overridingErrorMessage(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualFilesatisfies the given condition.Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNullMethods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Field Details
-
comparator
-
-
Constructor Details
-
FileAssert
Creates a newFileAssert.- Parameters:
actual- the target to verify.
-
FileAssert
FileAssert(File actual, FileContentComparator comparator)
-
-
Method Details
-
as
Sets the description of the actual value, to be used in as message of anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as("name").isEqualTo("Frodo");- Specified by:
asin classGenericAssert<File>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(String)For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");- Specified by:
describedAsin classGenericAssert<File>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
as
Sets the description of the actual value, to be used in as message of anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
asin classGenericAssert<File>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(Description)For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
describedAsin classGenericAssert<File>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
doesNotExist
Verifies that the actualFiledoes not exist.- Returns:
- this assertion object.
- Throws:
AssertionError- if the the actualFileisnull.AssertionError- if the actualFileexists.
-
exists
Verifies that the actualFiledoes exist.- Returns:
- this assertion object.
- Throws:
AssertionError- if the the actualFileisnull.AssertionError- if the actualFiledoes not exist.
-
hasSize
Verifies that the size of the actualFileis equal to the given one.- Parameters:
expected- the expected size of the actualFile.- Returns:
- this assertion object.
- Throws:
AssertionError- if the the actualFileisnull.AssertionError- if the size of the actualFileis not equal to the given one.
-
isDirectory
Verifies that the actualFileis a directory.- Returns:
- this assertion object.
- Throws:
AssertionError- if the the actualFileisnull.AssertionError- if the actualFileis not a directory.
-
isEqualTo
Verifies that the actualFileis equal to the given one. To verify that the actualFilehas the same content as anotherFile, use.hasSameContentAs(File)- Specified by:
isEqualToin classGenericAssert<File>- Parameters:
expected- the givenFileto compare the actualFileto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileis not equal to the given one.
-
isFile
Verifies that the actualFileis a regular file.- Returns:
- this assertion object.
- Throws:
AssertionError- if the the actualFileisnull.AssertionError- if the actualFileis not a regular file.
-
isNotEqualTo
Verifies that the actualFileis not equal to the given one.- Specified by:
isNotEqualToin classGenericAssert<File>- Parameters:
other- the givenFileto compare the actualFileto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileis equal to the given one.
-
isNotNull
Verifies that the actualFileis notnull.- Specified by:
isNotNullin classGenericAssert<File>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileisnull.
-
isNotSameAs
Verifies that the actualFileis not the same as the given one.- Specified by:
isNotSameAsin classGenericAssert<File>- Parameters:
other- the givenFileto compare the actualFileto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileis the same as the given one.
-
isSameAs
Verifies that the actualFileis the same as the given one.- Specified by:
isSameAsin classGenericAssert<File>- Parameters:
expected- the givenFileto compare the actualFileto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileis not the same as the given one.
-
satisfies
Verifies that the actualFilesatisfies the given condition.- Specified by:
satisfiesin classGenericAssert<File>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualFiledoes not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualFiledoes not satisfy the given condition.- Specified by:
doesNotSatisfyin classGenericAssert<File>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFilesatisfies the given condition.NullPointerException- if the given condition isnull.- See Also:
-
is
Verifies that the actualFilesatisfies the given condition.- Specified by:
isin classGenericAssert<File>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualFiledoes not satisfy the given condition.
-
isNot
Verifies that the actualFiledoes not satisfy the given condition.- Specified by:
isNotin classGenericAssert<File>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFilesatisfies the given condition.NullPointerException- if the given condition isnull.
-
hasSameContentAs
Verifies that the content of the actualFileis equal to the content of the given one. Adapted from FileAssert (from JUnit-addons.)- Parameters:
expected- the givenFileto compare the actualFileto.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the file to compare to isnull.AssertionError- if the the actualFileisnull.AssertionError- if the content of the actualFileis not equal to the content of the given one.
-
fail
-
cannotCompareToExpectedFile
-
assertExists
-
isRelative
Verifies that the actualFileis a relative path.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileis not a relative path.
-
isAbsolute
Verifies that the actualFileis an absolute path.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualFileis not an absolute path.
-
overridingErrorMessage
Replaces the default message displayed in case of a failure with the given one.For example, the following assertion:
assertThat("Hello").isEqualTo("Bye");will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."We can replace this message with our own:
assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".- Specified by:
overridingErrorMessagein classGenericAssert<File>- Parameters:
message- the given error message, which will replace the default one.- Returns:
- this assertion.
-