JavaHamcrest
JavaHamcrest copied to clipboard
Add 'hasEntry' matchers for (key, valueMatcher) and (keyMatcher, value)
When I test maps I often need to apply a matcher for the value and check equality for the key. Currently there is no hasEntry matcher that would consume a key, and a matcher for the value so I have to do it somewhat like this:
Map<String, List<Integer>> map = singletonMap("key", asList(1, 2));
assertThat(map, hasEntry(equalTo("key"), contains(1, 2)));
It would be more convenient to do it like this:
assertThat(map, hasEntry("key", contains(1, 2)));
For that reason, I introduced two hasEntry matchers with the following signatures:
hasEntry(K key, Matcher<? super V> valueMatcher)
hasEntry(Matcher<? super K> keyMatcher, V value)
Note: I originally submitted this changes as a part of this PR but since its fork has gone I cannot rebase it anymore. That's why I had to opened this one.
Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch v2.3-candidates.
Still trying to understand how has permissions to perform a release.