org.fest.assertions.core
Interface Assert<S,A>

Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
A - the type of the "actual" value.
All Superinterfaces:
Descriptable<S>, ExtensionPoints<S,A>
All Known Implementing Classes:
AbstractAssert, AbstractComparableAssert, AbstractIterableAssert, AbstractUnevenComparableAssert, BigDecimalAssert, BooleanArrayAssert, BooleanAssert, ByteArrayAssert, ByteAssert, CharacterAssert, CharArrayAssert, DateAssert, DoubleArrayAssert, DoubleAssert, FileAssert, FloatArrayAssert, FloatAssert, ImageAssert, InputStreamAssert, IntArrayAssert, IntegerAssert, IterableAssert, ListAssert, LongArrayAssert, LongAssert, MapAssert, ObjectArrayAssert, ObjectAssert, ShortArrayAssert, ShortAssert, StringAssert, ThrowableAssert

public interface Assert<S,A>
extends Descriptable<S>, ExtensionPoints<S,A>

Base contract of all assertion objects: the minimum functionality that any assertion object should provide.

Author:
Yvonne Wang, Alex Ruiz

Method Summary
 boolean equals(Object obj)
          Throws UnsupportedOperationException if called.
 S isEqualTo(A expected)
          Verifies that the actual value is equal to the given one.
 S isIn(A... values)
          Verifies that the actual value is present in the given array of values.
 S isIn(Collection<?> values)
          Verifies that the actual value is present in the given collection of values.
 S isNotEqualTo(A other)
          Verifies that the actual value is not equal to the given one.
 S isNotIn(A... values)
          Verifies that the actual value is not present in the given array of values.
 S isNotIn(Collection<?> values)
          Verifies that the actual value is not present in the given collection of values.
 S isNotNull()
          Verifies that the actual value is not null.
 S isNotSameAs(A other)
          Verifies that the actual value is not the same as the given one.
 void isNull()
          Verifies that the actual value is null.
 S isSameAs(A expected)
          Verifies that the actual value is the same as the given one.
 S usingComparator(Comparator<?> customComparator)
          Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
 S usingDefaultComparator()
          Revert to standard comparison for incoming assertion checks.
 
Methods inherited from interface org.fest.assertions.core.Descriptable
as, as, describedAs, describedAs
 
Methods inherited from interface org.fest.assertions.core.ExtensionPoints
doesNotHave, has, is, isNot
 

Method Detail

isEqualTo

S isEqualTo(A expected)
Verifies that the actual value is equal to the given one.

Parameters:
expected - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is not equal to the given one.

isNotEqualTo

S isNotEqualTo(A other)
Verifies that the actual value is not equal to the given one.

Parameters:
other - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is equal to the given one.

isNull

void isNull()
Verifies that the actual value is null.

Throws:
AssertionError - if the actual value is not null.

isNotNull

S isNotNull()
Verifies that the actual value is not null.

Returns:
this assertion object.
Throws:
AssertionError - if the actual value is null.

isSameAs

S isSameAs(A expected)
Verifies that the actual value is the same as the given one.

Parameters:
expected - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is not the same as the given one.

isNotSameAs

S isNotSameAs(A other)
Verifies that the actual value is not the same as the given one.

Parameters:
other - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is the same as the given one.

isIn

S isIn(A... values)
Verifies that the actual value is present in the given array of values.

Parameters:
values - the given array to search the actual value in.
Returns:
this assertion object.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
AssertionError - if the actual value is not present in the given array.

isNotIn

S isNotIn(A... values)
Verifies that the actual value is not present in the given array of values.

Parameters:
values - the given array to search the actual value in.
Returns:
this assertion object.
Throws:
NullPointerException - if the given array is null.
IllegalArgumentException - if the given array is empty.
AssertionError - if the actual value is present in the given array.

isIn

S isIn(Collection<?> values)
Verifies that the actual value is present in the given collection of values.

Parameters:
values - the given collection to search the actual value in.
Returns:
this assertion object.
Throws:
NullPointerException - if the given collection is null.
IllegalArgumentException - if the given collection is empty.
AssertionError - if the actual value is not present in the given collection.

isNotIn

S isNotIn(Collection<?> values)
Verifies that the actual value is not present in the given collection of values.

Parameters:
values - the given collection to search the actual value in.
Returns:
this assertion object.
Throws:
NullPointerException - if the given collection is null.
IllegalArgumentException - if the given collection is empty.
AssertionError - if the actual value is present in the given collection.

usingComparator

S usingComparator(Comparator<?> customComparator)
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>. 
 

Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.
Throws:
NullPointerException - if the given comparator is null.

usingDefaultComparator

S usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
This method should be used to disable a custom comparison strategy set by calling usingComparator(Comparator).

Returns:
this assertion object.

equals

boolean equals(Object obj)
Throws UnsupportedOperationException if called. It is easy to accidentally call equals(Object) instead of isEqualTo.

Overrides:
equals in class Object
Throws:
UnsupportedOperationException - if this method is called.


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