org.fest.assertions
Class ImageAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<ImageAssert,BufferedImage>
          extended by org.fest.assertions.ImageAssert

public class ImageAssert
extends GenericAssert<ImageAssert,BufferedImage>

Assertions for BufferedImages.

To create a new instance of this class invoke Assertions.assertThat(BufferedImage).

Author:
Yvonne Wang, Alex Ruiz, Ansgar Konermann

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual, myself
 
Constructor Summary
protected ImageAssert(BufferedImage actual)
          Creates a new ImageAssert.
 
Method Summary
 ImageAssert hasSize(Dimension expected)
          Verifies that the size of the actual image is equal to the given one.
 ImageAssert isEqualTo(BufferedImage expected)
          Verifies that the actual image is equal to the given one.
 ImageAssert isEqualTo(BufferedImage expected, Threshold threshold)
          Verifies that the actual image is equal to the given one.
 ImageAssert isNotEqualTo(BufferedImage image)
          Verifies that the actual image is not equal to the given one.
static BufferedImage read(String imageFilePath)
          Reads the image in the specified path.
 
Methods inherited from class org.fest.assertions.GenericAssert
as, as, describedAs, describedAs, doesNotSatisfy, is, isIn, isIn, isNot, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs, overridingErrorMessage, satisfies
 
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageAssert

protected ImageAssert(BufferedImage actual)
Creates a new ImageAssert.

Parameters:
actual - the target to verify.
Method Detail

read

public static BufferedImage read(String imageFilePath)
                          throws IOException
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 is null.
IllegalArgumentException - if the given path does not belong to a file.
IOException - if any I/O error occurred while reading the image.

isEqualTo

public ImageAssert isEqualTo(BufferedImage expected)
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.

Overrides:
isEqualTo in class GenericAssert<ImageAssert,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

public ImageAssert isEqualTo(BufferedImage expected,
                             Threshold threshold)
Verifies that the actual image is equal to the given one. Two images are equal if:
  1. they have the same size
  2. 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

isNotEqualTo

public ImageAssert isNotEqualTo(BufferedImage image)
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.

Overrides:
isNotEqualTo in class GenericAssert<ImageAssert,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.

hasSize

public ImageAssert hasSize(Dimension expected)
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 is null.
NullPointerException - if the given size is null.
AssertionError - if the size of the actual image is not equal to the given one.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.