Package org.fest.assertions.api
Class MapAssert<K,V>
java.lang.Object
org.fest.assertions.api.AbstractAssert<MapAssert<K,V>,Map<K,V>>
org.fest.assertions.api.MapAssert<K,V>
- All Implemented Interfaces:
Assert<MapAssert<K,
,V>, Map<K, V>> Descriptable<MapAssert<K,
,V>> EnumerableAssert<MapAssert<K,
,V>, MapEntry> ExtensionPoints<MapAssert<K,
V>, Map<K, V>>
public class MapAssert<K,V>
extends AbstractAssert<MapAssert<K,V>,Map<K,V>>
implements EnumerableAssert<MapAssert<K,V>,MapEntry>
Assertions for
Map
s.
To create a new instance of this class, invoke
.
Assertions.assertThat(Map)
- Author:
- David DIDIER, Yvonne Wang, Alex Ruiz, Mikhail Mazursky, Nicolas François
-
Field Summary
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionVerifies that the actual map contains the given entries, in any order.containsKey
(K key) Verifies that the actual map contains the given key.containsValue
(V value) Verifies that the actual map contains the given value.doesNotContain
(MapEntry... entries) Verifies that the actual map does not contain the given entries.doesNotContainKey
(K key) Verifies that the actual map does not contain the given key.doesNotContainValue
(V value) Verifies that the actual map does not contain the given value.hasSameSizeAs
(Iterable<?> other) Verifies that the actual group has the same size as givenIterable
.hasSameSizeAs
(Object[] other) Verifies that the actual group has the same size as given array.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.Verifies that the actual group of values is not empty.void
Verifies that the actual group of values isnull
or empty.Revert to standard comparison for incoming assertion group element checks.usingElementComparator
(Comparator<? super MapEntry> customComparator) Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
-
Constructor Details
-
MapAssert
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that the actual group of values isnull
or empty.- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<K,
V>
-
isEmpty
public void isEmpty()Verifies that the actual group of values is empty.- Specified by:
isEmpty
in interfaceEnumerableAssert<K,
V>
-
isNotEmpty
Verifies that the actual group of values is not empty.- Specified by:
isNotEmpty
in interfaceEnumerableAssert<K,
V> - Returns:
this
assertion object.
-
hasSize
Verifies that the number of values in the actual group is equal to the given one.- Specified by:
hasSize
in interfaceEnumerableAssert<K,
V> - Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<K,
V> - Parameters:
other
- the array to compare size with actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
Verifies that the actual group has the same size as givenIterable
.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<K,
V> - Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.
-
contains
Verifies that the actual map contains the given entries, in any order.- Parameters:
entries
- the given entries.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.NullPointerException
- if any of the entries in the given array isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given entries.
-
doesNotContain
Verifies that the actual map does not contain the given entries.- Parameters:
entries
- the given entries.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains any of the given entries.
-
containsKey
Verifies that the actual map contains the given key.- Parameters:
key
- the given key- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given key.
-
doesNotContainKey
Verifies that the actual map does not contain the given key.- Parameters:
key
- the given key- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains the given key.
-
containsValue
Verifies that the actual map contains the given value.- Parameters:
value
- the value to look for.- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given value.
-
doesNotContainValue
Verifies that the actual map does not contain the given value.- Parameters:
value
- the value that should not be in actual map.- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains the given value.
-
usingElementComparator
Use given custom comparator instead of relying on actual type Aequals
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 interfaceEnumerableAssert<K,
V> - Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
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
EnumerableAssert.usingElementComparator(Comparator)
.- Specified by:
usingDefaultElementComparator
in interfaceEnumerableAssert<K,
V> - Returns:
this
assertion object.
-