Class MultimapAssert<K,​V>

  • All Implemented Interfaces:
    org.assertj.core.api.Assert<MultimapAssert<K,​V>,​com.google.common.collect.Multimap<K,​V>>, org.assertj.core.api.Descriptable<MultimapAssert<K,​V>>, org.assertj.core.api.ExtensionPoints<MultimapAssert<K,​V>,​com.google.common.collect.Multimap<K,​V>>

    public class MultimapAssert<K,​V>
    extends org.assertj.core.api.AbstractAssert<MultimapAssert<K,​V>,​com.google.common.collect.Multimap<K,​V>>
    Assertions for guava Multimap.
    Author:
    marcelfalliere, miralak, Joel Costigliola
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) org.assertj.core.internal.Failures failures  
      • Fields inherited from class org.assertj.core.api.AbstractAssert

        actual, info, myself, objects, throwUnsupportedExceptionOnEquals
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MultimapAssert​(com.google.common.collect.Multimap<K,​V> actual)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MultimapAssert<K,​V> contains​(org.assertj.core.data.MapEntry<K,​V>... entries)
      Verifies that the actual Multimap contains the given entries.
      MultimapAssert<K,​V> containsAllEntriesOf​(com.google.common.collect.Multimap<? extends K,​? extends V> other)
      Verifies that the actual Multimap contains all entries of the given one (it might contain more entries).
      MultimapAssert<K,​V> containsKeys​(K... keys)
      Verifies that the actual Multimap contains the given keys.
      MultimapAssert<K,​V> containsValues​(V... values)
      Verifies that the actual Multimap contains the given values for any key.
      protected com.google.common.collect.Multimap<K,​V> getActual()  
      MultimapAssert<K,​V> hasSameEntriesAs​(com.google.common.collect.Multimap<? extends K,​? extends V> other)
      Verifies that the actual Multimap has the same entries as the given one.
      It allows to compare two multimaps having the same content but who are not equal because being of different types like SetMultimap and ListMultimap.
      MultimapAssert<K,​V> hasSize​(int expectedSize)
      Verifies that the number of values in the actual Multimap is equal to the given one.
      void isEmpty()
      Verifies that the actual Multimap is empty.
      void isNotEmpty()
      Verifies that the actual Multimap is not empty.
      • Methods inherited from class org.assertj.core.api.AbstractAssert

        asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withRepresentation, withThreadDumpOnError
      • Methods inherited from interface org.assertj.core.api.Descriptable

        as, as, describedAs
    • Field Detail

      • failures

        org.assertj.core.internal.Failures failures
    • Constructor Detail

      • MultimapAssert

        protected MultimapAssert​(com.google.common.collect.Multimap<K,​V> actual)
    • Method Detail

      • getActual

        protected com.google.common.collect.Multimap<K,​V> getActual()
      • containsKeys

        public MultimapAssert<K,​V> containsKeys​(K... keys)
        Verifies that the actual Multimap contains the given keys.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
        
         actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
         actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         actual.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         assertThat(actual).containsKeys("Lakers", "Bulls");
        If the keys argument is null or empty, an IllegalArgumentException is thrown.

        Parameters:
        keys - the keys to look for in actual Multimap.
        Returns:
        this MultimapAssert for assertions chaining.
        Throws:
        IllegalArgumentException - if no param keys have been set.
        AssertionError - if the actual Multimap is null.
        AssertionError - if the actual Multimap does not contain the given keys.
      • contains

        @SafeVarargs
        public final MultimapAssert<K,​V> contains​(org.assertj.core.data.MapEntry<K,​V>... entries)
        Verifies that the actual Multimap contains the given entries.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
        
         actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
         actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         actual.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         // entry can be statically imported from org.assertj.guava.api.Assertions or org.assertj.guava.data.MapEntry
         assertThat(actual).contains(entry("Lakers", "Kobe Bryant"), entry("Spurs", "Tim Duncan"));
        If the entries argument is null or empty, an IllegalArgumentException is thrown.

        Parameters:
        entries - the entries to look for in actual Multimap.
        Returns:
        this MultimapAssert for assertions chaining.
        Throws:
        IllegalArgumentException - if no param entries have been set.
        AssertionError - if the actual Multimap is null.
        AssertionError - if the actual Multimap does not contain the given entries.
      • containsValues

        public MultimapAssert<K,​V> containsValues​(V... values)
        Verifies that the actual Multimap contains the given values for any key.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
        
         actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
         actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         actual.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         // note that given values are not linked to same key
         assertThat(actual).containsValues("Kobe Bryant", "Michael Jordan");
        If the values argument is null or empty, an IllegalArgumentException is thrown.

        Parameters:
        values - the values to look for in actual Multimap.
        Returns:
        this MultimapAssert for assertions chaining.
        Throws:
        IllegalArgumentException - if no param values have been set.
        AssertionError - if the actual Multimap is null.
        AssertionError - if the actual Multimap does not contain the given values.
      • isEmpty

        public void isEmpty()
        Verifies that the actual Multimap is empty.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
        
         assertThat(actual).isEmpty();
        Throws:
        AssertionError - if the actual Multimap is null.
        AssertionError - if the actual Multimap is not empty.
      • isNotEmpty

        public void isNotEmpty()
        Verifies that the actual Multimap is not empty.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
         nba.put("Bulls", "Derrick Rose");
         nba.put("Bulls", "Joachim Noah");
        
         assertThat(nba).isNotEmpty();
        Throws:
        AssertionError - if the actual Multimap is null.
        AssertionError - if the actual Multimap is empty.
      • hasSize

        public MultimapAssert<K,​V> hasSize​(int expectedSize)
        Verifies that the number of values in the actual Multimap is equal to the given one.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
        
         actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
         actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         actual.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         assertThat(actual).hasSize(9);
        Parameters:
        expectedSize - the expected size of actual Multimap.
        Returns:
        this MultimapAssert for assertions chaining.
        Throws:
        AssertionError - if the actual Multimap is null.
        AssertionError - if the number of values of the actual Multimap is not equal to the given one.
      • hasSameEntriesAs

        public final MultimapAssert<K,​V> hasSameEntriesAs​(com.google.common.collect.Multimap<? extends K,​? extends V> other)
        Verifies that the actual Multimap has the same entries as the given one.
        It allows to compare two multimaps having the same content but who are not equal because being of different types like SetMultimap and ListMultimap.

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
         listMultimap.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         listMultimap.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         Multimap<String, String> setMultimap = TreeMultimap.create();
         setMultimap.putAll("Spurs", newHashSet("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         setMultimap.putAll("Bulls", newHashSet("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         // assertion will pass as listMultimap and setMultimap have the same content
         assertThat(listMultimap).hasSameEntriesAs(setMultimap);
        
         // this assertion FAILS even though both multimaps have the same content
         assertThat(listMultimap).isEqualTo(setMultimap);
        Parameters:
        other - Multimap to compare actual's entries with.
        Returns:
        this MultimapAssert for assertions chaining.
        Throws:
        AssertionError - if the actual Multimap is null.
        IllegalArgumentException - if the other Multimap is null.
        AssertionError - if actual Multimap does not have the same entries as the other Multimap.
      • containsAllEntriesOf

        public final MultimapAssert<K,​V> containsAllEntriesOf​(com.google.common.collect.Multimap<? extends K,​? extends V> other)
        Verifies that the actual Multimap contains all entries of the given one (it might contain more entries).

        Example :

         Multimap<String, String> actual = ArrayListMultimap.create();
         actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
         actual.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
        
         Multimap<String, String> other = TreeMultimap.create();
         other.putAll("Spurs", newHashSet("Tony Parker", "Tim Duncan"));
         other.putAll("Bulls", newHashSet("Michael Jordan", "Scottie Pippen"));
        
         // assertion will pass as other is a subset of actual.
         assertThat(actual).containsAllEntriesOf(other);
        
         // this assertion FAILS as other does not contain "Spurs -> "Manu Ginobili" and "Bulls" -> "Derrick Rose"
         assertThat(other).containsAllEntriesOf(actual);
        Parameters:
        other - Multimap to compare actual's entries with.
        Returns:
        this MultimapAssert for assertions chaining.
        Throws:
        AssertionError - if the actual Multimap is null.
        IllegalArgumentException - if the other Multimap is null.
        AssertionError - if actual Multimap does not have contain all the given Multimap entries.