Package org.fest.assertions
Class ImageAssert
Understands assertion methods for images. To create a new instance of this class use the method
Assertions.assertThat(BufferedImage)
.-
Field Summary
FieldsFields inherited from class org.fest.assertions.GenericAssert
actual
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ImageAssert
(BufferedImage actual) Creates a newImageAssert
. -
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
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)
doesNotSatisfy
(Condition<BufferedImage> condition) Verifies that the actual image does not satisfy the given condition.private void
failIfNotEqual
(Dimension a, Dimension e) private void
failIfNotEqual
(RGBColor a, RGBColor e, Threshold threshold, int x, int y) private void
failIfNotEqualColor
(BufferedImage expected, Threshold threshold) private void
failIfNull
(BufferedImage expected) private boolean
hasEqualColor
(BufferedImage expected) Verifies that the size of the actual image is equal to the given one.(package private) static void
imageReader
(ImageReader newImageReader) is
(Condition<BufferedImage> condition) Alias for
.satisfies(Condition)
isEqualTo
(BufferedImage expected) Verifies that the actual image is equal to the given one.isEqualTo
(BufferedImage expected, Threshold threshold) Verifies that the actual image is equal to the given one.isNot
(Condition<BufferedImage> condition) Alias for
.doesNotSatisfy(Condition)
isNotEqualTo
(BufferedImage image) Verifies that the actual image is not equal to the given one.Verifies that the actual image is notnull
.isNotSameAs
(BufferedImage expected) Verifies that the actual image is not the same as the given one.isSameAs
(BufferedImage expected) Verifies that the actual image is the same as the given one.overridingErrorMessage
(String message) Replaces the default message displayed in case of a failure with the given one.static BufferedImage
Reads the image in the specified path.satisfies
(Condition<BufferedImage> condition) Verifies that the actual image satisfies the given condition.private static Dimension
sizeOf
(BufferedImage image) 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
-
ZERO_THRESHOLD
-
imageReader
-
-
Constructor Details
-
ImageAssert
Creates a newImageAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Details
-
read
Reads the image in the specified path.- Parameters:
imageFilePath
- the path of the image to read.- Returns:
- the read image.
- Throws:
NullPointerException
- if the given path isnull
.IllegalArgumentException
- if the given path does not belong to a file.IOException
- if any I/O error occurred while reading the image.
-
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<BufferedImage>
- 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<BufferedImage>
- 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<BufferedImage>
- 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<BufferedImage>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
satisfies
Verifies that the actual image satisfies the given condition.- Specified by:
satisfies
in classGenericAssert<BufferedImage>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual image does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actual image does not satisfy the given condition.- Specified by:
doesNotSatisfy
in classGenericAssert<BufferedImage>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual image satisfies the given condition.- See Also:
-
is
Alias for
.satisfies(Condition)
- Specified by:
is
in classGenericAssert<BufferedImage>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual image does not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for
.doesNotSatisfy(Condition)
- Specified by:
isNot
in classGenericAssert<BufferedImage>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual image satisfies the given condition.- Since:
- 1.2
-
isEqualTo
Verifies that the actual image is equal to the given one. Two images are equal if they have the same size and the pixels at the same coordinates have the same color.- Specified by:
isEqualTo
in classGenericAssert<BufferedImage>
- Parameters:
expected
- the given image to compare the actual image to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image is not equal to the given one.
-
isEqualTo
Verifies that the actual image is equal to the given one. Two images are equal if:- they have the same size
- the difference between the RGB values of the color of each pixel is less than or equal to the given threshold
- Parameters:
expected
- the given image to compare the actual image to.threshold
- the threshold to use to decide if the color of two pixels are similar: two pixels that are identical to the human eye may still have slightly different color values. For example, by using a threshold of 1 we can indicate that a blue value of 60 is similar to a blue value of 61.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image is not equal to the given one.- Since:
- 1.1
-
failIfNull
-
failIfNotEqual
-
failIfNotEqualColor
-
failIfNotEqual
-
isNotEqualTo
Verifies that the actual image is not equal to the given one. Two images are equal if they have the same size and the pixels at the same coordinates have the same color.- Specified by:
isNotEqualTo
in classGenericAssert<BufferedImage>
- Parameters:
image
- the given image to compare the actual image to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image is equal to the given one.
-
sizeOf
-
hasEqualColor
-
isNotNull
Verifies that the actual image is notnull
.- Specified by:
isNotNull
in classGenericAssert<BufferedImage>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image isnull
.
-
isNotSameAs
Verifies that the actual image is not the same as the given one.- Specified by:
isNotSameAs
in classGenericAssert<BufferedImage>
- Parameters:
expected
- the given image to compare the actual image to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image is the same as the given one.
-
isSameAs
Verifies that the actual image is the same as the given one.- Specified by:
isSameAs
in classGenericAssert<BufferedImage>
- Parameters:
expected
- the given image to compare the actual image to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image is not the same as the given one.
-
hasSize
Verifies that the size of the actual image is equal to the given one.- Parameters:
expected
- the expected size of the actual image.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual image isnull
.NullPointerException
- if the given size isnull
.AssertionError
- if the size of the actual image is not equal to the given one.
-
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<BufferedImage>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-
imageReader
-