Class MapAssert<K,​V>

    • Constructor Detail

      • MapAssert

        protected MapAssert​(java.util.Map<K,​V> actual)
    • Method Detail

      • isNullOrEmpty

        public void isNullOrEmpty()
        Verifies that the actual group of values is null or empty.
        Specified by:
        isNullOrEmpty in interface EnumerableAssert<K,​V>
      • isEmpty

        public void isEmpty()
        Verifies that the actual group of values is empty.
        Specified by:
        isEmpty in interface EnumerableAssert<K,​V>
      • isNotEmpty

        public MapAssert<K,​V> isNotEmpty()
        Verifies that the actual group of values is not empty.
        Specified by:
        isNotEmpty in interface EnumerableAssert<K,​V>
        Returns:
        this assertion object.
      • hasSize

        public MapAssert<K,​V> 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<K,​V>
        Parameters:
        expected - the expected number of values in the actual group.
        Returns:
        this assertion object.
      • hasSameSizeAs

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

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

        public MapAssert<K,​V> contains​(MapEntry... entries)
        Verifies that the actual map contains the given entries, in any order.
        Parameters:
        entries - the given entries.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given argument is null.
        java.lang.IllegalArgumentException - if the given argument is an empty array.
        java.lang.NullPointerException - if any of the entries in the given array is null.
        java.lang.AssertionError - if the actual map is null.
        java.lang.AssertionError - if the actual map does not contain the given entries.
      • doesNotContain

        public MapAssert<K,​V> doesNotContain​(MapEntry... entries)
        Verifies that the actual map does not contain the given entries.
        Parameters:
        entries - the given entries.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given argument is null.
        java.lang.IllegalArgumentException - if the given argument is an empty array.
        java.lang.AssertionError - if the actual map is null.
        java.lang.AssertionError - if the actual map contains any of the given entries.
      • containsKey

        public MapAssert<K,​V> containsKey​(K key)
        Verifies that the actual map contains the given key.
        Parameters:
        key - the given key
        Throws:
        java.lang.AssertionError - if the actual map is null.
        java.lang.AssertionError - if the actual map does not contain the given key.
      • doesNotContainKey

        public MapAssert<K,​V> doesNotContainKey​(K key)
        Verifies that the actual map does not contain the given key.
        Parameters:
        key - the given key
        Throws:
        java.lang.AssertionError - if the actual map is null.
        java.lang.AssertionError - if the actual map contains the given key.
      • containsValue

        public MapAssert<K,​V> containsValue​(V value)
        Verifies that the actual map contains the given value.
        Parameters:
        value - the value to look for.
        Throws:
        java.lang.AssertionError - if the actual map is null.
        java.lang.AssertionError - if the actual map does not contain the given value.
      • doesNotContainValue

        public MapAssert<K,​V> doesNotContainValue​(V value)
        Verifies that the actual map does not contain the given value.
        Parameters:
        value - the value that should not be in actual map.
        Throws:
        java.lang.AssertionError - if the actual map is null.
        java.lang.AssertionError - if the actual map contains the given value.
      • usingElementComparator

        public MapAssert<K,​V> usingElementComparator​(java.util.Comparator<? super MapEntry> 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<K,​V>
        Parameters:
        customComparator - the comparator to use for incoming assertion checks.
        Returns:
        this assertion object.