org.fest.assertions.api
Class ImageAssert

java.lang.Object
  extended by org.fest.assertions.api.AbstractAssert<ImageAssert,BufferedImage>
      extended by org.fest.assertions.api.ImageAssert
All Implemented Interfaces:
Assert<ImageAssert,BufferedImage>, Descriptable<ImageAssert>, ExtensionPoints<ImageAssert,BufferedImage>

public class ImageAssert
extends AbstractAssert<ImageAssert,BufferedImage>

Assertion methods for images.

To create an instance of this class, invoke Assertions.assertThat(BufferedImage).

Author:
Yvonne Wang, Alex Ruiz, Ansgar Konermann, Joel Costigliola

Field Summary
 
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
 
Constructor Summary
protected ImageAssert(BufferedImage actual)
           
 
Method Summary
 ImageAssert hasSize(Dimension expected)
          Verifies that the actual image has the given size.
 ImageAssert isEqualTo(BufferedImage expected)
          Verifies that the actual image is equal to the given one.
 ImageAssert isEqualTo(BufferedImage expected, Offset<Integer> offset)
          Verifies that the actual image is equal to the given one.
 ImageAssert isNotEqualTo(BufferedImage other)
          Verifies that the actual value is not equal to the given one.
 ImageAssert usingComparator(Comparator<?> customComparator)
          Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
 ImageAssert usingDefaultComparator()
          Revert to standard comparison for incoming assertion checks.
 
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, equals, has, hashCode, is, isIn, isIn, isNot, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageAssert

protected ImageAssert(BufferedImage actual)
Method Detail

isEqualTo

public ImageAssert isEqualTo(BufferedImage expected)
Verifies that the actual image is equal to the given one. Two images are equal if:
  1. they have equal size
  2. the the RGB values of the color at each pixel are equal

Specified by:
isEqualTo in interface Assert<ImageAssert,BufferedImage>
Overrides:
isEqualTo in class AbstractAssert<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,
                             Offset<Integer> offset)
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 at each pixel is less than or equal to the given offset

Parameters:
expected - the given image to compare the actual image to.
offset - helps 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 an offset of 1 we can indicate that a blue value of 60 is similar to a blue value of 61.
Returns:
this assertion object.
Throws:
NullPointerException - if the given offset is null.
AssertionError - if the actual image is not equal to the given one.

isNotEqualTo

public ImageAssert isNotEqualTo(BufferedImage other)
Verifies that the actual value is not equal to the given one.

Specified by:
isNotEqualTo in interface Assert<ImageAssert,BufferedImage>
Overrides:
isNotEqualTo in class AbstractAssert<ImageAssert,BufferedImage>
Parameters:
other - the given value to compare the actual value to.
Returns:
this assertion object.

hasSize

public ImageAssert hasSize(Dimension expected)
Verifies that the actual image has the given size.

Parameters:
expected - the expected size of the actual image.
Returns:
this assertion object.
Throws:
NullPointerException - if the given size is null.
AssertionError - if the size of the actual image is not equal to the given size.

usingComparator

public ImageAssert usingComparator(Comparator<?> customComparator)
Description copied from class: AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.

Example :
 // compares invoices by payee 
 assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList).
 
 // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
 assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice)
 
 // as assertThat(invoiceList) creates a new assertion, it uses standard comparison strategy (Invoice's equal method) to compare invoiceList elements to lowestInvoice.                                                      
 assertThat(invoiceList).contains(lowestInvoice).
 
Custom comparator is not parameterized with actual type A (ie. Comparator<A>) because if it was, we could not write the following code :
 // frodo and sam are instances of Character (a Character having a Race)
 // raceComparator implements Comparator<Character> 
 // assertThat(frodo) returns an ObjectAssert and not a custom CharacterAssert implementing Assert<CharacterAssert, Character>  
 assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam); // won't compile !
 
 The code does not compile because assertThat(frodo) returns an ObjectAssert, thus usingComparator expects a Comparator<Object> 
 and Comparator<Character> is not a Comparator<Object> as generics are not reified.
 
 Note that, it would have worked if assertThat(frodo) returned a CharacterAssert implementing Assert<CharacterAssert, Character>. 
 

Specified by:
usingComparator in interface Assert<ImageAssert,BufferedImage>
Overrides:
usingComparator in class AbstractAssert<ImageAssert,BufferedImage>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.

usingDefaultComparator

public ImageAssert usingDefaultComparator()
Description copied from class: AbstractAssert
Revert to standard comparison for incoming assertion checks.
This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator).

Specified by:
usingDefaultComparator in interface Assert<ImageAssert,BufferedImage>
Overrides:
usingDefaultComparator in class AbstractAssert<ImageAssert,BufferedImage>
Returns:
this assertion object.


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