Interface EnumerableAssert<S extends EnumerableAssert<S,​T>,​T>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      S hasSameSizeAs​(java.lang.Iterable<?> other)
      Verifies that the actual group has the same size as given Iterable.
      S hasSameSizeAs​(java.lang.Object[] other)
      Verifies that the actual group has the same size as given array.
      S 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.
      S isNotEmpty()
      Verifies that the actual group of values is not empty.
      void isNullOrEmpty()
      Verifies that the actual group of values is null or empty.
      S usingDefaultElementComparator()
      Revert to standard comparison for incoming assertion group element checks.
      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.
    • Method Detail

      • isNullOrEmpty

        void isNullOrEmpty()
        Verifies that the actual group of values is null or empty.
        Throws:
        java.lang.AssertionError - if the actual group of values is not null or not empty.
      • isEmpty

        void isEmpty()
        Verifies that the actual group of values is empty.
        Throws:
        java.lang.AssertionError - if the actual group of values is not empty.
      • isNotEmpty

        S isNotEmpty()
        Verifies that the actual group of values is not empty.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual group of values is empty.
      • hasSize

        S hasSize​(int expected)
        Verifies that the number of values in the actual group is equal to the given one.
        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

        S hasSameSizeAs​(java.lang.Iterable<?> other)
        Verifies that the actual group has the same size as given Iterable.
        Parameters:
        other - the Iterable to compare size with actual group.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual group is null.
        java.lang.AssertionError - if the other Iterable is null.
        java.lang.AssertionError - if actual group and given Iterable don't have the same size.
      • hasSameSizeAs

        S hasSameSizeAs​(java.lang.Object[] other)
        Verifies that the actual group has the same size as given array.
        Parameters:
        other - the array to compare size with actual group.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual group is null.
        java.lang.AssertionError - if the other array is null.
        java.lang.AssertionError - if actual group and given array don't have the same size.
      • usingElementComparator

        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);
         
        Parameters:
        customComparator - the comparator to use for incoming assertion checks.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given comparator is null.
      • usingDefaultElementComparator

        S 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.