Spring Integration

org.springframework.integration.test.matcher
Class MapContentMatchers<T,V>

java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.springframework.integration.test.matcher.MapContentMatchers<T,V>
All Implemented Interfaces:
org.hamcrest.Matcher<Map<? super T,? super V>>, org.hamcrest.SelfDescribing

public class MapContentMatchers<T,V>
extends org.hamcrest.BaseMatcher<T>

Matchers that examine the contents of a Map.

It is possible to match a single entry by value or matcher like this:

 assertThat(map, hasEntry(SOME_KEY, is(SOME_VALUE)));
 assertThat(map, hasEntry(SOME_KEY, is(String.class)));
 assertThat(map, hasEntry(SOME_KEY, notNullValue()));
 

It's also possible to match multiple entries in a map:

 Map<String, Object> expectedInMap = new HashMap<String, Object>();
 expectedInMap.put(SOME_KEY, SOME_VALUE);
 expectedInMap.put(OTHER_KEY, is(OTHER_VALUE));
 assertThat(map, hasAllEntries(expectedInMap));
 

If you only need to verify the existence of a key:

 assertThat(map, hasKey(SOME_KEY));
 

Author:
Alex Peters, Iwein Fuld

Method Summary
 void describeTo(org.hamcrest.Description description)
          
static
<T,V> org.hamcrest.Matcher<Map<? super T,? super V>>
hasAllEntries(Map<T,V> entries)
           
static
<T,V> org.hamcrest.Matcher<Map<? super T,? super V>>
hasEntry(T key, org.hamcrest.Matcher<V> valueMatcher)
           
static
<T,V> org.hamcrest.Matcher<Map<? super T,? super V>>
hasEntry(T key, V value)
           
static
<T,V> org.hamcrest.Matcher<Map<? super T,? super V>>
hasKey(T key)
           
 boolean matches(Object item)
          Method made final to prevent accidental override.
 boolean matchesSafely(Map<? super T,? super V> item)
          Subclasses should implement this.
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

matchesSafely

public boolean matchesSafely(Map<? super T,? super V> item)
Subclasses should implement this. The item will already have been checked for the specific type and will never be null.


describeTo

public void describeTo(org.hamcrest.Description description)


hasEntry

public static <T,V> org.hamcrest.Matcher<Map<? super T,? super V>> hasEntry(T key,
                                                                            V value)

hasEntry

public static <T,V> org.hamcrest.Matcher<Map<? super T,? super V>> hasEntry(T key,
                                                                            org.hamcrest.Matcher<V> valueMatcher)

hasKey

public static <T,V> org.hamcrest.Matcher<Map<? super T,? super V>> hasKey(T key)

hasAllEntries

public static <T,V> org.hamcrest.Matcher<Map<? super T,? super V>> hasAllEntries(Map<T,V> entries)

matches

public final boolean matches(Object item)
Method made final to prevent accidental override. If you need to override this, there's no point on extending TypeSafeMatcher. Instead, extend the BaseMatcher.


Spring Integration

Copyright © 2010. All Rights Reserved.