Class AbstractIterableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>,​T>

    • Constructor Detail

      • AbstractIterableAssert

        protected AbstractIterableAssert​(A actual,
                                         java.lang.Class<?> selfType)
    • Method Detail

      • hasSize

        public S hasSize​(int expected)
        Verifies that the number of values in the actual group is equal to the given one.
        Specified by:
        hasSize in interface EnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        expected - the expected number of values in the actual group.
        Returns:
        this assertion object.
      • hasSameSizeAs

        public S hasSameSizeAs​(java.lang.Object[] other)
        Verifies that the actual group has the same size as given array.
        Specified by:
        hasSameSizeAs in interface EnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        other - the array to compare size with actual group.
        Returns:
        this assertion object.
      • hasSameSizeAs

        public S hasSameSizeAs​(java.lang.Iterable<?> other)
        Verifies that the actual group has the same size as given Iterable.
        Specified by:
        hasSameSizeAs in interface EnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        other - the Iterable to compare size with actual group.
        Returns:
        this assertion object.
      • contains

        public S contains​(T... values)
        Verifies that the actual group contains the given values, in any order.
        Specified by:
        contains in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        values - the given values.
        Returns:
        this assertion object.
      • containsOnly

        public S containsOnly​(T... values)
        Verifies that the actual group contains only the given values and nothing else, in any order.
        Specified by:
        containsOnly in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        values - the given values.
        Returns:
        this assertion object.
      • containsExactly

        public S containsExactly​(T... values)
        Verifies that the actual group contains only the given values and nothing else, in order.
        This assertion should only be used with Iterable that have a consistent iteration order (i.e. don't use it with HashSet, prefer ObjectEnumerableAssert.containsOnly(Object...) in that case).

        Example :

         Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
         
         // assertion will pass
         assertThat(elvesRings).containsExactly(vilya, nenya, narya);
         
         // assertion will fail as actual and expected orders differ.
         assertThat(elvesRings).containsExactly(nenya, vilya, narya);
         
        Specified by:
        containsExactly in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        values - the given values.
        Returns:
        this assertion object.
      • isSubsetOf

        public S isSubsetOf​(java.lang.Iterable<? extends T> values)
        Verifies that all the elements of the actual Iterable are present in the given Iterable.
        Parameters:
        values - the Iterable that should contain all actual elements.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual Iterable is null.
        java.lang.NullPointerException - if the given Iterable is null.
        java.lang.AssertionError - if the actual Iterable is not subset of set Iterable.
      • containsSequence

        public S containsSequence​(T... sequence)
        Verifies that the actual group contains the given sequence, without any other values between them.
        Specified by:
        containsSequence in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        sequence - the sequence of objects to look for.
        Returns:
        this assertion object.
      • doesNotContain

        public S doesNotContain​(T... values)
        Verifies that the actual group does not contain the given values.
        Specified by:
        doesNotContain in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        values - the given values.
        Returns:
        this assertion object.
      • startsWith

        public S startsWith​(T... sequence)
        Verifies that the actual group starts with the given sequence of objects, without any other objects between them. Similar to ObjectEnumerableAssert.containsSequence(Object...), but it also verifies that the first element in the sequence is also first element of the actual group.
        Specified by:
        startsWith in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        sequence - the sequence of objects to look for.
        Returns:
        this assertion object.
      • endsWith

        public S endsWith​(T... sequence)
        Verifies that the actual group ends with the given sequence of objects, without any other objects between them. Similar to ObjectEnumerableAssert.containsSequence(Object...), but it also verifies that the last element in the sequence is also last element of the actual group.
        Specified by:
        endsWith in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        sequence - the sequence of objects to look for.
        Returns:
        this assertion object.
      • are

        public S are​(Condition<? super T> condition)
        Verifies that each element value satisfies the given condition
        Specified by:
        are in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        condition - the given condition.
        Returns:
        this object.
      • areNot

        public S areNot​(Condition<? super T> condition)
        Verifies that each element value not satisfies the given condition
        Specified by:
        areNot in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        condition - the given condition.
        Returns:
        this object.
      • have

        public S have​(Condition<? super T> condition)
        Verifies that each element value satisfies the given condition
        Specified by:
        have in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        condition - the given condition.
        Returns:
        this object.
      • areAtLeast

        public S areAtLeast​(int times,
                            Condition<? super T> condition)
        Verifies that there is at least n elements in the actual group satisfying the given condition.
        Specified by:
        areAtLeast in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        times - the minimum number of times the condition should be verified.
        condition - the given condition.
        Returns:
        this object.
      • areNotAtLeast

        public S areNotAtLeast​(int times,
                               Condition<? super T> condition)
        Verifies that there is at least n elements in the actual group not satisfying the given condition.
        Specified by:
        areNotAtLeast in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        times - the number of times the condition should not be verified at least.
        condition - the given condition.
        Returns:
        this object.
      • areAtMost

        public S areAtMost​(int times,
                           Condition<? super T> condition)
        Verifies that there is at most n elements in the actual group satisfying the given condition.
        Specified by:
        areAtMost in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        times - the number of times the condition should be at most verified.
        condition - the given condition.
        Returns:
        this object.
      • areNotAtMost

        public S areNotAtMost​(int times,
                              Condition<? super T> condition)
        Verifies that there is at most n elements in the actual group not satisfying the given condition.
        Specified by:
        areNotAtMost in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        times - the number of times the condition should not be verified at most.
        condition - the given condition.
        Returns:
        this object.
      • areExactly

        public S areExactly​(int times,
                            Condition<? super T> condition)
        Verifies that there is exactly n elements in the actual group satisfying the given condition.
        Specified by:
        areExactly in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        times - the exact number of times the condition should be verified.
        condition - the given condition.
        Returns:
        this object.
      • areNotExactly

        public S areNotExactly​(int times,
                               Condition<? super T> condition)
        Verifies that there is exactly n elements in the actual group not satisfying the given condition.
        Specified by:
        areNotExactly in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        times - the exact number of times the condition should not be verified.
        condition - the given condition.
        Returns:
        this object.
      • containsAll

        public S containsAll​(java.lang.Iterable<? extends T> iterable)
        Verifies that the actual group contains all the elements of given Iterable, in any order.
        Specified by:
        containsAll in interface ObjectEnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        iterable - the given Iterable we will get elements from.
        Returns:
        this assertion object.
      • usingElementComparator

        public S usingElementComparator​(java.util.Comparator<? super T> customComparator)
        Use given custom comparator instead of relying on actual type A equals 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);
         
        Specified by:
        usingElementComparator in interface EnumerableAssert<S extends AbstractIterableAssert<S,​A,​T>,​A extends java.lang.Iterable<T>>
        Parameters:
        customComparator - the comparator to use for incoming assertion checks.
        Returns:
        this assertion object.