Skip to content

Commit 7013362

Browse files
author
joeretro
committed
Renamed mapWithKey() -> hasKey(), mapWithValue() -> hasValue(), mapContaining() -> hasEntry()
1 parent 3a3dd1c commit 7013362

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/library/org/hamcrest/collection/IsMapContaining.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,32 @@ public void describeTo(Description description) {
3939
}
4040

4141
@Factory
42-
public static <K,V> Matcher<Map<K,V>> mapContaining(Matcher<K> keyMatcher, Matcher<V> valueMatcher) {
42+
public static <K,V> Matcher<Map<K,V>> hasEntry(Matcher<K> keyMatcher, Matcher<V> valueMatcher) {
4343
return new IsMapContaining<K,V>(keyMatcher, valueMatcher);
4444
}
4545

4646
@Factory
47-
public static <K,V> Matcher<Map<K,V>> mapContaining(K key, V value) {
48-
return mapContaining(equalTo(key), equalTo(value));
47+
public static <K,V> Matcher<Map<K,V>> hasEntry(K key, V value) {
48+
return hasEntry(equalTo(key), equalTo(value));
4949
}
5050

5151
@Factory
52-
public static <K,V> Matcher<Map<K,V>> mapWithKey(Matcher<K> keyMatcher) {
53-
return mapContaining(keyMatcher, IsAnything.<V>anything());
52+
public static <K,V> Matcher<Map<K,V>> hasKey(Matcher<K> keyMatcher) {
53+
return hasEntry(keyMatcher, IsAnything.<V>anything());
5454
}
5555

5656
@Factory
57-
public static <K,V> Matcher<Map<K,V>> mapWithKey(K key) {
58-
return mapWithKey(equalTo(key));
57+
public static <K,V> Matcher<Map<K,V>> hasKey(K key) {
58+
return hasKey(equalTo(key));
5959
}
6060

6161
@Factory
62-
public static <K,V> Matcher<Map<K,V>> mapWithValue(Matcher<V> valueMatcher) {
63-
return mapContaining(IsAnything.<K>anything(), valueMatcher);
62+
public static <K,V> Matcher<Map<K,V>> hasValue(Matcher<V> valueMatcher) {
63+
return hasEntry(IsAnything.<K>anything(), valueMatcher);
6464
}
6565

6666
@Factory
67-
public static <K,V> Matcher<Map<K,V>> mapWithValue(V value) {
68-
return mapWithValue(equalTo(value));
67+
public static <K,V> Matcher<Map<K,V>> hasValue(V value) {
68+
return hasValue(equalTo(value));
6969
}
7070
}

src/unit-test/org/hamcrest/collection/IsMapContainingTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.hamcrest.AbstractMatcherTest;
44
import org.hamcrest.Matcher;
5-
import static org.hamcrest.collection.IsMapContaining.mapContaining;
5+
import static org.hamcrest.collection.IsMapContaining.hasEntry;
66
import static org.hamcrest.core.IsAnything.anything;
77
import static org.hamcrest.core.IsEqual.equalTo;
88

@@ -12,27 +12,27 @@
1212
public class IsMapContainingTest extends AbstractMatcherTest {
1313

1414
protected Matcher<?> createMatcher() {
15-
return mapContaining("irrelevant", "irrelevant");
15+
return IsMapContaining.hasEntry("irrelevant", "irrelevant");
1616
}
1717

1818
public void testMatchesMapContainingMatchingKeyAndValue() {
1919
Map<String,Integer> map = new HashMap<String,Integer>();
2020
map.put("a", 1);
2121
map.put("b", 2);
2222

23-
assertMatches("matcherA", mapContaining(equalTo("a"), equalTo(1)), map);
24-
assertMatches("matcherB", mapContaining(equalTo("b"), equalTo(2)), map);
25-
assertDoesNotMatch("matcherC", mapContaining(equalTo("c"), equalTo(3)), map);
23+
assertMatches("matcherA", hasEntry(equalTo("a"), equalTo(1)), map);
24+
assertMatches("matcherB", hasEntry(equalTo("b"), equalTo(2)), map);
25+
assertDoesNotMatch("matcherC", hasEntry(equalTo("c"), equalTo(3)), map);
2626
}
2727

2828
public void testDoesNotMatchNull() {
2929
assertDoesNotMatch("should not matches null",
30-
mapContaining(anything(), anything()), null);
30+
hasEntry(anything(), anything()), null);
3131
}
3232

3333
public void testHasReadableDescription() {
3434
assertDescription("map containing [\"a\"-><2>]",
35-
mapContaining(equalTo("a"), (equalTo(2))));
35+
hasEntry(equalTo("a"), (equalTo(2))));
3636
}
3737

3838
// Remaining code no longer compiles, thanks to generics. I think that's a good thing, but

0 commit comments

Comments
 (0)