org.fest.assertions.api
Class MapAssert

java.lang.Object
  extended by org.fest.assertions.api.AbstractAssert<MapAssert,Map<?,?>>
      extended by org.fest.assertions.api.MapAssert
All Implemented Interfaces:
Assert<MapAssert,Map<?,?>>, Descriptable<MapAssert>, EnumerableAssert<MapAssert,MapEntry>, ExtensionPoints<MapAssert,Map<?,?>>

public class MapAssert
extends AbstractAssert<MapAssert,Map<?,?>>
implements EnumerableAssert<MapAssert,MapEntry>

Assertions for Maps.

To create a new instance of this class, invoke Assertions.assertThat(Map).

Author:
David DIDIER, Yvonne Wang, Alex Ruiz, Mikhail Mazursky

Field Summary
 
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
 
Constructor Summary
protected MapAssert(Map<?,?> actual)
           
 
Method Summary
 MapAssert contains(MapEntry... entries)
          Verifies that the actual map contains the given entries, in any order.
 MapAssert doesNotContain(MapEntry... entries)
          Verifies that the actual map does not contain the given entries.
 MapAssert 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.
 MapAssert isNotEmpty()
          Verifies that the actual group of values is not empty.
 void isNullOrEmpty()
          Verifies that the actual group of values is null or empty.
 MapAssert usingDefaultElementComparator()
          Revert to standard comparison for incoming assertion group element checks.
 MapAssert usingElementComparator(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.
 
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, equals, has, hashCode, is, isEqualTo, isIn, isIn, isNot, isNotEqualTo, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs, usingComparator, usingDefaultComparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapAssert

protected MapAssert(Map<?,?> actual)
Method Detail

isNullOrEmpty

public void isNullOrEmpty()
Verifies that the actual group of values is null or empty.

Specified by:
isNullOrEmpty in interface EnumerableAssert<MapAssert,MapEntry>

isEmpty

public void isEmpty()
Verifies that the actual group of values is empty.

Specified by:
isEmpty in interface EnumerableAssert<MapAssert,MapEntry>

isNotEmpty

public MapAssert isNotEmpty()
Verifies that the actual group of values is not empty.

Specified by:
isNotEmpty in interface EnumerableAssert<MapAssert,MapEntry>
Returns:
this assertion object.

hasSize

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

contains

public MapAssert 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:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
NullPointerException - if any of the entries in the given array is null.
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given entries.

doesNotContain

public MapAssert doesNotContain(MapEntry... entries)
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 is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual map is null.
AssertionError - if the actual map contains any of the given entries.

usingElementComparator

public MapAssert usingElementComparator(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<MapAssert,MapEntry>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.

usingDefaultElementComparator

public MapAssert 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 interface EnumerableAssert<MapAssert,MapEntry>
Returns:
this assertion object.


Copyright © 2007-2012 FEST (Fixtures for Easy Software Testing). All Rights Reserved.