How to verify Map size using Hamcrest

Viewed 18735
Map<Integer, Map<String, String>> mapMap = new HashMap<Integer,Map<String, String>>();

Currently asserting like this

assertThat(mapMap.size(), is(equalTo(1)));
Or
assertThat(mapMap.values(), hasSize(1));

Are there any other methods like one used with Lists.

assertThat(someListReferenceVariable, hasSize(1));

3 Answers

You can check this using not and any

import static org.hamcrest.Matchers.any;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.not;

not(hasEntry(any(Object.class), any(Object.class)))
Related