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
ConstructorsModifierConstructorDescriptionprotected
FileAssert
(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 any
thrown when an assertion fails.AssertionError
as
(Description description) Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
private FileAssert
assertExists
(File file) private void
cannotCompareToExpectedFile
(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 actualFile
does not exist.doesNotSatisfy
(Condition<File> condition) Verifies that the actualFile
does not satisfy the given condition.exists()
Verifies that the actualFile
does exist.private void
fail
(File expected, FileContentComparator.LineDiff[] diffs) hasSameContentAs
(File expected) Verifies that the content of the actualFile
is equal to the content of the given one.hasSize
(long expected) Verifies that the size of the actualFile
is equal to the given one.Verifies that the actualFile
satisfies the given condition.Verifies that the actualFile
is an absolute path.Verifies that the actualFile
is a directory.Verifies that the actualFile
is equal to the given one.isFile()
Verifies that the actualFile
is a regular file.Verifies that the actualFile
does not satisfy the given condition.isNotEqualTo
(File other) Verifies that the actualFile
is not equal to the given one.Verifies that the actualFile
is notnull
.isNotSameAs
(File other) Verifies that the actualFile
is not the same as the given one.Verifies that the actualFile
is a relative path.Verifies that the actualFile
is 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 actualFile
satisfies the given condition.Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNull
Methods 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 any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as("name").isEqualTo("Frodo");
- Specified by:
as
in 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:
describedAs
in 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 any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
as
in 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:
describedAs
in classGenericAssert<File>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
doesNotExist
Verifies that the actualFile
does not exist.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the the actualFile
isnull
.AssertionError
- if the actualFile
exists.
-
exists
Verifies that the actualFile
does exist.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the the actualFile
isnull
.AssertionError
- if the actualFile
does not exist.
-
hasSize
Verifies that the size of the actualFile
is equal to the given one.- Parameters:
expected
- the expected size of the actualFile
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the the actualFile
isnull
.AssertionError
- if the size of the actualFile
is not equal to the given one.
-
isDirectory
Verifies that the actualFile
is a directory.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the the actualFile
isnull
.AssertionError
- if the actualFile
is not a directory.
-
isEqualTo
Verifies that the actualFile
is equal to the given one. To verify that the actualFile
has the same content as anotherFile
, use
.hasSameContentAs(File)
- Specified by:
isEqualTo
in classGenericAssert<File>
- Parameters:
expected
- the givenFile
to compare the actualFile
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
is not equal to the given one.
-
isFile
Verifies that the actualFile
is a regular file.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the the actualFile
isnull
.AssertionError
- if the actualFile
is not a regular file.
-
isNotEqualTo
Verifies that the actualFile
is not equal to the given one.- Specified by:
isNotEqualTo
in classGenericAssert<File>
- Parameters:
other
- the givenFile
to compare the actualFile
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
is equal to the given one.
-
isNotNull
Verifies that the actualFile
is notnull
.- Specified by:
isNotNull
in classGenericAssert<File>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
isnull
.
-
isNotSameAs
Verifies that the actualFile
is not the same as the given one.- Specified by:
isNotSameAs
in classGenericAssert<File>
- Parameters:
other
- the givenFile
to compare the actualFile
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
is the same as the given one.
-
isSameAs
Verifies that the actualFile
is the same as the given one.- Specified by:
isSameAs
in classGenericAssert<File>
- Parameters:
expected
- the givenFile
to compare the actualFile
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
is not the same as the given one.
-
satisfies
Verifies that the actualFile
satisfies the given condition.- Specified by:
satisfies
in classGenericAssert<File>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualFile
does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualFile
does not satisfy the given condition.- Specified by:
doesNotSatisfy
in classGenericAssert<File>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
satisfies the given condition.NullPointerException
- if the given condition isnull
.- See Also:
-
is
Verifies that the actualFile
satisfies the given condition.- Specified by:
is
in classGenericAssert<File>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualFile
does not satisfy the given condition.
-
isNot
Verifies that the actualFile
does not satisfy the given condition.- Specified by:
isNot
in classGenericAssert<File>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
satisfies the given condition.NullPointerException
- if the given condition isnull
.
-
hasSameContentAs
Verifies that the content of the actualFile
is equal to the content of the given one. Adapted from FileAssert (from JUnit-addons.)- Parameters:
expected
- the givenFile
to compare the actualFile
to.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the file to compare to isnull
.AssertionError
- if the the actualFile
isnull
.AssertionError
- if the content of the actualFile
is not equal to the content of the given one.
-
fail
-
cannotCompareToExpectedFile
-
assertExists
-
isRelative
Verifies that the actualFile
is a relative path.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
is not a relative path.
-
isAbsolute
Verifies that the actualFile
is an absolute path.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualFile
is 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:
overridingErrorMessage
in classGenericAssert<File>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-