Package org.assertj.guava.api
Class MultimapAssert<K,V>
java.lang.Object
org.assertj.core.api.AbstractAssert<MultimapAssert<K,V>,Multimap<K,V>>
org.assertj.guava.api.MultimapAssert<K,V>
- All Implemented Interfaces:
Assert<MultimapAssert<K,,V>, Multimap<K, V>> Descriptable<MultimapAssert<K,,V>> ExtensionPoints<MultimapAssert<K,V>, Multimap<K, V>>
Assertions for guava
Multimap.- Author:
- marcelfalliere, miralak, Joel Costigliola
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal MultimapAssert<K, V> Verifies that the actualMultimapcontains the given entries.final MultimapAssert<K, V> containsAllEntriesOf(Multimap<? extends K, ? extends V> other) Verifies that the actualMultimapcontains all entries of the given one (it might contain more entries).containsKeys(K... keys) Verifies that the actualMultimapcontains the given keys.containsValues(V... values) Verifies that the actualMultimapcontains the given values for any key.doesNotContainKey(K key) Verifies that the actual multimap does not contain the given key.doesNotContainKeys(K... keys) Verifies that the actual multimap does not contain any of the given keys.final MultimapAssert<K, V> hasSameEntriesAs(Multimap<? extends K, ? extends V> other) Verifies that the actualMultimaphas 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 likeSetMultimapandListMultimap.hasSize(int expectedSize) Verifies that the number of values in the actualMultimapis equal to the given one.voidisEmpty()Verifies that the actualMultimapis empty.voidVerifies that the actualMultimapis not empty.Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Constructor Details
-
MultimapAssert
-
-
Method Details
-
getActual
-
containsKeys
Verifies that the actualMultimapcontains 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
keysargument is null or empty, anIllegalArgumentExceptionis thrown.- Parameters:
keys- the keys to look for in actualMultimap.- Returns:
- this
MultimapAssertfor assertions chaining. - Throws:
IllegalArgumentException- if no param keys have been set.AssertionError- if the actualMultimapisnull.AssertionError- if the actualMultimapdoes not contain the given keys.
-
contains
Verifies that the actualMultimapcontains 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
entriesargument is null or empty, anIllegalArgumentExceptionis thrown.- Parameters:
entries- the entries to look for in actualMultimap.- Returns:
- this
MultimapAssertfor assertions chaining. - Throws:
IllegalArgumentException- if no param entries have been set.AssertionError- if the actualMultimapisnull.AssertionError- if the actualMultimapdoes not contain the given entries.
-
containsValues
Verifies that the actualMultimapcontains 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
valuesargument is null or empty, anIllegalArgumentExceptionis thrown.- Parameters:
values- the values to look for in actualMultimap.- Returns:
- this
MultimapAssertfor assertions chaining. - Throws:
IllegalArgumentException- if no param values have been set.AssertionError- if the actualMultimapisnull.AssertionError- if the actualMultimapdoes not contain the given values.
-
isEmpty
public void isEmpty()Verifies that the actualMultimapis empty.Example :
Multimap<String, String> actual = ArrayListMultimap.create(); assertThat(actual).isEmpty();- Throws:
AssertionError- if the actualMultimapisnull.AssertionError- if the actualMultimapis not empty.
-
isNotEmpty
public void isNotEmpty()Verifies that the actualMultimapis 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 actualMultimapisnull.AssertionError- if the actualMultimapis empty.
-
hasSize
Verifies that the number of values in the actualMultimapis 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 actualMultimap.- Returns:
- this
MultimapAssertfor assertions chaining. - Throws:
AssertionError- if the actualMultimapisnull.AssertionError- if the number of values of the actualMultimapis not equal to the given one.
-
hasSameEntriesAs
Verifies that the actualMultimaphas 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 likeSetMultimapandListMultimap.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-Multimapto compare actual's entries with.- Returns:
- this
MultimapAssertfor assertions chaining. - Throws:
AssertionError- if the actualMultimapisnull.IllegalArgumentException- if the otherMultimapisnull.AssertionError- if actualMultimapdoes not have the same entries as the otherMultimap.
-
containsAllEntriesOf
Verifies that the actualMultimapcontains 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-Multimapto compare actual's entries with.- Returns:
- this
MultimapAssertfor assertions chaining. - Throws:
AssertionError- if the actualMultimapisnull.IllegalArgumentException- if the otherMultimapisnull.AssertionError- if actualMultimapdoes not have contain all the givenMultimapentries.
-
doesNotContainKey
Verifies that the actual multimap does not contain the given key.Examples:
Multimap<Ring, TolkienCharacter> elvesRingBearers = HashMultimap.create(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will pass assertThat(elvesRingBearers).doesNotContainKey(oneRing); // assertion will fail assertThat(elvesRingBearers).doesNotContainKey(vilya);- Parameters:
key- the given key- Returns:
thisassertions object- Throws:
AssertionError- if the actual map isnull.AssertionError- if the actual map contains the given key.- Since:
- 3.26.0
-
doesNotContainKeys
Verifies that the actual multimap does not contain any of the given keys.Examples:
Multimap<Ring, TolkienCharacter> elvesRingBearers = HashMultimap.create(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will pass assertThat(elvesRingBearers).doesNotContainKeys(oneRing, someManRing); // assertions will fail assertThat(elvesRingBearers).doesNotContainKeys(vilya, nenya); assertThat(elvesRingBearers).doesNotContainKeys(vilya, oneRing);- Parameters:
keys- the given keys- Returns:
thisassertions object- Throws:
AssertionError- if the actual map isnull.AssertionError- if the actual map contains the given key.NullPointerException- if the varargs of keys is null- Since:
- 3.26.0
-