|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.public interface Assert<S,A>
Base contract of all assertion objects: the minimum functionality that any assertion object should provide.
Method Summary | |
---|---|
boolean |
equals(Object obj)
Throws 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(Iterable<? extends A> values)
Verifies that the actual value is present in the given 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(Iterable<? extends A> values)
Verifies that the actual value is not present in the given 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 |
---|
S isEqualTo(A expected)
expected
- the given value to compare the actual value to.
this
assertion object.
AssertionError
- if the actual value is not equal to the given one.S isNotEqualTo(A other)
other
- the given value to compare the actual value to.
this
assertion object.
AssertionError
- if the actual value is equal to the given one.void isNull()
null
.
AssertionError
- if the actual value is not null
.S isNotNull()
null
.
this
assertion object.
AssertionError
- if the actual value is null
.S isSameAs(A expected)
expected
- the given value to compare the actual value to.
this
assertion object.
AssertionError
- if the actual value is not the same as the given one.S isNotSameAs(A other)
other
- the given value to compare the actual value to.
this
assertion object.
AssertionError
- if the actual value is the same as the given one.S isIn(A... values)
values
- the given array to search the actual value in.
this
assertion object.
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.S isNotIn(A... values)
values
- the given array to search the actual value in.
this
assertion object.
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.S isIn(Iterable<? extends A> values)
values
- the given iterable to search the actual value in.
this
assertion object.
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.S isNotIn(Iterable<? extends A> values)
values
- the given iterable to search the actual value in.
this
assertion object.
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.S usingComparator(Comparator<?> customComparator)
// 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>.
customComparator
- the comparator to use for incoming assertion checks.
this
assertion object.
NullPointerException
- if the given comparator is null
.S usingDefaultComparator()
usingComparator(Comparator)
.
this
assertion object.boolean equals(Object obj)
UnsupportedOperationException
if called. It is easy to accidentally call
equals(Object)
instead of isEqualTo
.
equals
in class Object
UnsupportedOperationException
- if this method is called.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |