Class MapMatcher

java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeMatcher<Map<?,?>>
org.elasticsearch.test.MapMatcher
All Implemented Interfaces:
org.hamcrest.Matcher<Map<?,?>>, org.hamcrest.SelfDescribing

public class MapMatcher extends org.hamcrest.TypeSafeMatcher<Map<?,?>>
Matcher for Maps that reports all errors at once.
  • Method Details

    • matchesMap

      public static MapMatcher matchesMap()
      Create a MapMatcher that matches empty Maps.
    • matchesMap

      public static MapMatcher matchesMap(Map<?,?> map)
      Create a MapMatcher that matches a Map.

      The description and mismatch message are sorted as Map.entrySet() because error messages with a consistent order are easier to debug. So you should care about this order and provide LinkedHashMap or a TreeMap or some other Map that has a nice order. Or build an empty matcher with matchesMap() and fill it in the order you like by calling entry.

    • assertMap

      public static <T> void assertMap(T actual, org.hamcrest.Matcher<? super T> matcher)
      Assert match. Shorter output on failure than MatcherAssert.assertThat(Object, Matcher) that looks better for MapMatcher and ListMatcher.
    • assertMap

      public static <T> void assertMap(String reason, T actual, org.hamcrest.Matcher<? super T> matcher)
      Assert match. Shorter output on failure than MatcherAssert.assertThat(Object, Matcher) that looks better for MapMatcher and ListMatcher.
    • extraOk

      public MapMatcher extraOk()
      Ignore extra entries.
      Returns:
      a new MapMatcher that will not fail if it encounters extra entries
    • entry

      public MapMatcher entry(Object key, Object value)
      Expect a value.

      Passing a Matcher to this method will function as though you passed it directly to entry(Object, Matcher).

      Returns:
      a new MapMatcher that expects another entry
    • entry

      public MapMatcher entry(Object key, org.hamcrest.Matcher<?> valueMatcher)
      Expect a Matcher.
      Returns:
      a new MapMatcher that expects another entry
    • matchesSafely

      protected boolean matchesSafely(Map<?,?> item)
      Specified by:
      matchesSafely in class org.hamcrest.TypeSafeMatcher<Map<?,?>>
    • describeMismatchSafely

      protected void describeMismatchSafely(Map<?,?> item, org.hamcrest.Description description)
      Overrides:
      describeMismatchSafely in class org.hamcrest.TypeSafeMatcher<Map<?,?>>