Package org.assertj.core.api
Interface EnumerableAssert<SELF extends EnumerableAssert<SELF,ELEMENT>,ELEMENT>
-
- Type Parameters:
SELF
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.ELEMENT
- the type of elements of the "actual" value.
- All Known Subinterfaces:
IndexedObjectEnumerableAssert<SELF,ELEMENT>
,ObjectEnumerableAssert<SELF,ELEMENT>
- All Known Implementing Classes:
AbstractArrayAssert
,AbstractBooleanArrayAssert
,AbstractByteArrayAssert
,AbstractCharArrayAssert
,AbstractCharSequenceAssert
,AbstractDoubleArrayAssert
,AbstractEnumerableAssert
,AbstractFloatArrayAssert
,AbstractIntArrayAssert
,AbstractIterableAssert
,AbstractListAssert
,AbstractLongArrayAssert
,AbstractMapAssert
,AbstractObjectArrayAssert
,AbstractShortArrayAssert
,AtomicIntegerArrayAssert
,AtomicLongArrayAssert
,AtomicReferenceArrayAssert
,BooleanArrayAssert
,ByteArrayAssert
,CharArrayAssert
,CharSequenceAssert
,ClassBasedNavigableIterableAssert
,ClassBasedNavigableListAssert
,DoubleArrayAssert
,FactoryBasedNavigableIterableAssert
,FactoryBasedNavigableListAssert
,FloatArrayAssert
,IntArrayAssert
,IterableAssert
,ListAssert
,LongArrayAssert
,MapAssert
,ObjectArrayAssert
,ShortArrayAssert
,SoftAssertionIterableAssert
,SoftAssertionListAssert
,SoftAssertionMapAssert
,StringAssert
public interface EnumerableAssert<SELF extends EnumerableAssert<SELF,ELEMENT>,ELEMENT>
Assertions applicable to groups of values that can be enumerated (e.g. arrays, collections or strings.)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description SELF
hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.SELF
hasSameSizeAs(java.lang.Object array)
Verifies that the actual group has the same size as given array.SELF
hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.void
isEmpty()
Verifies that the actual group of values is empty.SELF
isNotEmpty()
Verifies that the actual group of values is not empty.void
isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.SELF
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.SELF
usingElementComparator(java.util.Comparator<? super ELEMENT> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.
-
-
-
Method Detail
-
isNullOrEmpty
void isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.Example:
// assertions will pass List<String> strings = new ArrayList<>(); assertThat(strings).isNullOrEmpty(); assertThat(new int[] { }).isNullOrEmpty(); // assertions will fail assertThat(new String[] { "a", "b"}).isNullOrEmpty(); assertThat(Arrays.asList(1, 2, 3)).isNullOrEmpty();
- Throws:
java.lang.AssertionError
- if the actual group of values is notnull
or not empty.
-
isEmpty
void isEmpty()
Verifies that the actual group of values is empty.Example:
// assertions will pass assertThat(new ArrayList()).isEmpty(); assertThat(new int[] { }).isEmpty(); // assertions will fail assertThat(new String[] { "a", "b" }).isEmpty(); assertThat(Arrays.asList(1, 2, 3)).isEmpty();
- Throws:
java.lang.AssertionError
- if the actual group of values is not empty.
-
isNotEmpty
SELF isNotEmpty()
Verifies that the actual group of values is not empty.Example:
// assertions will pass assertThat(new String[] { "a", "b" }).isNotEmpty(); assertThat(Arrays.asList(1, 2, 3)).isNotEmpty(); // assertions will fail assertThat(new ArrayList()).isNotEmpty(); assertThat(new int[] { }).isNotEmpty();
- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual group of values is empty.
-
hasSize
SELF hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.Example:
// assertions will pass assertThat(new String[] { "a", "b" }).hasSize(2); assertThat(Arrays.asList(1, 2, 3)).hasSize(3); // assertions will fail assertThat(new ArrayList()).hasSize(1); assertThat(new int[] { 1, 2, 3 }).hasSize(2);
- Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the number of values of the actual group is not equal to the given one.
-
hasSameSizeAs
SELF hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.Example:
Iterable<String> abc = newArrayList("a", "b", "c"); Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass assertThat(elvesRings).hasSameSizeAs(abc); // assertions will fail assertThat(elvesRings).hasSameSizeAs(Arrays.asList(1, 2)); assertThat(elvesRings).hasSameSizeAs(Arrays.asList(1, 2, 3, 4));
- Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual group isnull
.java.lang.AssertionError
- if the otherIterable
isnull
.java.lang.AssertionError
- if actual group and givenIterable
don't have the same size.
-
hasSameSizeAs
SELF hasSameSizeAs(java.lang.Object array)
Verifies that the actual group has the same size as given array.Parameter is declared as Object to accept both Object[] and primitive arrays (e.g. int[]).
Example:
int[] oneTwoThree = {1, 2, 3}; Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass assertThat(elvesRings).hasSameSizeAs(oneTwoThree); // assertions will fail assertThat(elvesRings).hasSameSizeAs(new int[] { 1, 2}); assertThat(elvesRings).hasSameSizeAs(new int[] { 1, 2, 3, 4});
- Parameters:
array
- the array to compare size with actual group.- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual group isnull
.java.lang.AssertionError
- if the array parameter isnull
or is not a true array.java.lang.AssertionError
- if actual group and given array don't have the same size.
-
usingElementComparator
SELF usingElementComparator(java.util.Comparator<? super ELEMENT> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements 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.
Examples :
// 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 falls back to standard comparison strategy // based on Invoice's equal method to compare invoiceList elements to lowestInvoice. assertThat(invoiceList).contains(lowestInvoice); // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ... assertThat(fellowshipOfTheRing).contains(gandalf) .doesNotContain(sauron); // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator) .contains(sauron);
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.- Throws:
java.lang.NullPointerException
- if the given comparator isnull
.
-
usingDefaultElementComparator
SELF usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.This method should be used to disable a custom comparison strategy set by calling
usingElementComparator(Comparator)
.- Returns:
this
assertion object.
-
-