org.fest.assertions
Class MapAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<T>
          extended by org.fest.assertions.GroupAssert<Map<?,?>>
              extended by org.fest.assertions.MapAssert

public class MapAssert
extends GroupAssert<Map<?,?>>

Understands assertions for Maps. To create a new instance of this class use the method Assertions.assertThat(Map).

Author:
David DIDIER, Yvonne Wang, Alex Ruiz

Nested Class Summary
static class MapAssert.Entry
          Understands an entry in a Map.
 
Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected MapAssert(Map<?,?> actual)
          Creates a new MapAssert.
 
Method Summary
protected  int actualGroupSize()
          Returns the number of elements in the actual Map.
 MapAssert as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 MapAssert as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 MapAssert describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
 MapAssert describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
 MapAssert doesNotSatisfy(Condition<Map<?,?>> condition)
          Verifies that the actual Map does not satisfy the given condition.
static MapAssert.Entry entry(Object key, Object value)
          Creates a new map entry.
 MapAssert excludes(MapAssert.Entry... entries)
          Verifies that the actual Map does not contain the given entries.
 MapAssert hasSize(int expected)
          Verifies that the number of elements in the actual Map is equal to the given one.
 MapAssert includes(MapAssert.Entry... entries)
          Verifies that the actual Map contains the given entries.
 MapAssert is(Condition<Map<?,?>> condition)
          Alias for satisfies(Condition).
 void isEmpty()
          Verifies that the actual Map is empty.
 MapAssert isEqualTo(Map<?,?> expected)
          Verifies that the actual Map is equal to the given one.
 MapAssert isNot(Condition<Map<?,?>> condition)
          Alias for doesNotSatisfy(Condition).
 MapAssert isNotEmpty()
          Verifies that the actual Map contains at least on element.
 MapAssert isNotEqualTo(Map<?,?> other)
          Verifies that the actual Map is not equal to the given one.
 MapAssert isNotNull()
          Verifies that the actual Map is not null.
 MapAssert isNotSameAs(Map<?,?> other)
          Verifies that the actual Map is not the same as the given one.
 void isNullOrEmpty()
          Verifies that the actual Map is null or empty.
 MapAssert isSameAs(Map<?,?> expected)
          Verifies that the actual Map is the same as the given one.
 MapAssert overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 MapAssert satisfies(Condition<Map<?,?>> condition)
          Verifies that the actual Map satisfies the given condition.
 
Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNull
 
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapAssert

protected MapAssert(Map<?,?> actual)
Creates a new MapAssert.

Parameters:
actual - the target to verify.
Method Detail

as

public MapAssert as(String description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as("name").isEqualTo("Frodo");
 

Specified by:
as in class GenericAssert<Map<?,?>>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public MapAssert describedAs(String description)
Alias for GenericAssert.as(String), since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).describedAs("name").isEqualTo("Frodo");
 

Specified by:
describedAs in class GenericAssert<Map<?,?>>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

public MapAssert as(Description description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
as in class GenericAssert<Map<?,?>>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public MapAssert describedAs(Description description)
Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
describedAs in class GenericAssert<Map<?,?>>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

includes

public MapAssert includes(MapAssert.Entry... entries)
Verifies that the actual Map contains the given entries.

Example:

 // static import org.fest.assertions.Assertions.*;
 // static import org.fest.assertions.MapAssert.*;

 assertThat(myMap).includes(entry("jedi", yoda), entry("sith", anakin));
 

Parameters:
entries - the given entries.
Returns:
this assertion error.
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual Map does not contain any of the given entries.
NullPointerException - if the given array of entries is null.
NullPointerException - if any of the entries in the given array is null.

excludes

public MapAssert excludes(MapAssert.Entry... entries)
Verifies that the actual Map does not contain the given entries.

Example:

 // static import org.fest.assertions.Assertions.*;
 // static import org.fest.assertions.MapAssert.*;

 assertThat(myMap).excludes(entry("jedi", yoda), entry("sith", anakin));
 

Parameters:
entries - the given entries.
Returns:
this assertion error.
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual Map contains any of the given entries.
NullPointerException - if the given array of entries is null.
NullPointerException - if any of the entries in the given array is null.

entry

public static MapAssert.Entry entry(Object key,
                                    Object value)
Creates a new map entry.

Parameters:
key - the key of the entry.
value - the value of the entry.
Returns:
the created entry.
See Also:
includes(org.fest.assertions.MapAssert.Entry...)

hasSize

public MapAssert hasSize(int expected)
Verifies that the number of elements in the actual Map is equal to the given one.

Specified by:
hasSize in class GroupAssert<Map<?,?>>
Parameters:
expected - the expected number of elements in the actual Map.
Returns:
this assertion object.
Throws:
AssertionError - if the actual map is null.
AssertionError - if the number of elements of the actual Map is not equal to the given one.

isNullOrEmpty

public final void isNullOrEmpty()
Verifies that the actual Map is null or empty.

Specified by:
isNullOrEmpty in class GroupAssert<Map<?,?>>
Throws:
AssertionError - if the actual Map is not null or not empty.

isEmpty

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

Specified by:
isEmpty in class GroupAssert<Map<?,?>>
Throws:
AssertionError - if the actual Map is null or not empty.

isEqualTo

public MapAssert isEqualTo(Map<?,?> expected)
Verifies that the actual Map is equal to the given one.

Specified by:
isEqualTo in class GenericAssert<Map<?,?>>
Parameters:
expected - the given map to compare the actual Map to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Map is not equal to the given one.

isNotEmpty

public MapAssert isNotEmpty()
Verifies that the actual Map contains at least on element.

Specified by:
isNotEmpty in class GroupAssert<Map<?,?>>
Returns:
this assertion object.
Throws:
AssertionError - if the actual Map is empty.

isNotEqualTo

public MapAssert isNotEqualTo(Map<?,?> other)
Verifies that the actual Map is not equal to the given one.

Specified by:
isNotEqualTo in class GenericAssert<Map<?,?>>
Parameters:
other - the given map to compare the actual Map to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Map is equal to the given one.

isNotNull

public MapAssert isNotNull()
Verifies that the actual Map is not null.

Specified by:
isNotNull in class GenericAssert<Map<?,?>>
Returns:
this assertion object.
Throws:
AssertionError - if the actual Map is null.

isNotSameAs

public MapAssert isNotSameAs(Map<?,?> other)
Verifies that the actual Map is not the same as the given one.

Specified by:
isNotSameAs in class GenericAssert<Map<?,?>>
Parameters:
other - the given map to compare the actual Map to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Map is the same as the given one.

isSameAs

public MapAssert isSameAs(Map<?,?> expected)
Verifies that the actual Map is the same as the given one.

Specified by:
isSameAs in class GenericAssert<Map<?,?>>
Parameters:
expected - the given map to compare the actual Map to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Map is not the same as the given one.

satisfies

public MapAssert satisfies(Condition<Map<?,?>> condition)
Verifies that the actual Map satisfies the given condition.

Specified by:
satisfies in class GenericAssert<Map<?,?>>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Map does not satisfy the given condition.
See Also:
is(Condition)

doesNotSatisfy

public MapAssert doesNotSatisfy(Condition<Map<?,?>> condition)
Verifies that the actual Map does not satisfy the given condition.

Specified by:
doesNotSatisfy in class GenericAssert<Map<?,?>>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Map satisfies the given condition.
See Also:
isNot(Condition)

is

public MapAssert is(Condition<Map<?,?>> condition)
Alias for satisfies(Condition).

Specified by:
is in class GenericAssert<Map<?,?>>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Map does not satisfy the given condition.
Since:
1.2

isNot

public MapAssert isNot(Condition<Map<?,?>> condition)
Alias for doesNotSatisfy(Condition).

Specified by:
isNot in class GenericAssert<Map<?,?>>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Map satisfies the given condition.
Since:
1.2

actualGroupSize

protected int actualGroupSize()
Returns the number of elements in the actual Map.

Specified by:
actualGroupSize in class GroupAssert<Map<?,?>>
Returns:
the number of elements in the actual Map.

overridingErrorMessage

public MapAssert overridingErrorMessage(String message)
Replaces the default message displayed in case of a failure with the given one.

For example, the following assertion:

 assertThat("Hello").isEqualTo("Bye");
 
will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."

We can replace this message with our own:

 assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");
 
in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".

Specified by:
overridingErrorMessage in class GenericAssert<Map<?,?>>
Parameters:
message - the given error message, which will replace the default one.
Returns:
this assertion.


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