Let's say I have a Map:
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("foo1","foo1");
map1.put("foo2", Arrays.asList("foo2","bar2"));
Now I'd like to use Hamcrest matchers to verify the Map's values. If this were a Map< String,String > I would do something similar to this:
assertThat(map1, hasEntry("foo1", "foo1"));
However, I'm stuck when trying to use this with Map where the entries in the Map could be a String or a List of values. This works for the first entry:
assertThat(map1, hasEntry("foo1", (Object)"foo1"));
For the second entry I can't figure out how to setup the Matchers.
EDIT:
I also tried this, but it produces a compiler warning.
assertThat(
map1,
hasEntry(
"foo2",
contains(hasProperty("name", is("foo2")),
hasProperty("name", is("bar2")))));
"The method assertThat(T, Matcher) in the type Assert is not applicable for the arguments (Map, Matcher>>>)"
(The above was the solution here: Hamcrest compare collections )