Skip to content

Commit 28aeeb9

Browse files
committed
Factory methods. Map hasEntry
1 parent deca642 commit 28aeeb9

File tree

4 files changed

+12
-44
lines changed

4 files changed

+12
-44
lines changed

hamcrest-library/src/main/java/org/hamcrest/Matchers.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
969969
* @param valueMatcher the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
970970
*/
971971
public static <K, V> Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(org.hamcrest.Matcher<? super K> keyMatcher, org.hamcrest.Matcher<? super V> valueMatcher) {
972-
return org.hamcrest.collection.IsMapContaining.hasEntry(keyMatcher, valueMatcher);
972+
return MatchingMaps.hasEntry(keyMatcher, valueMatcher);
973973
}
974974

975975
/**
@@ -983,7 +983,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
983983
* @param value the value that, in combination with the key, must be describe at least one entry
984984
*/
985985
public static <K, V> Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(K key, V value) {
986-
return org.hamcrest.collection.IsMapContaining.hasEntry(key, value);
986+
return MatchingMaps.hasEntry(key, value);
987987
}
988988

989989
/**
@@ -995,7 +995,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
995995
* @param keyMatcher the matcher that must be satisfied by at least one key
996996
*/
997997
public static <K> org.hamcrest.Matcher<java.util.Map<? extends K, ?>> hasKey(org.hamcrest.Matcher<? super K> keyMatcher) {
998-
return org.hamcrest.collection.IsMapContaining.hasKey(keyMatcher);
998+
return MatchingMaps.hasKey(keyMatcher);
999999
}
10001000

10011001
/**
@@ -1007,7 +1007,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
10071007
* @param key the key that satisfying maps must contain
10081008
*/
10091009
public static <K> org.hamcrest.Matcher<java.util.Map<? extends K, ?>> hasKey(K key) {
1010-
return org.hamcrest.collection.IsMapContaining.hasKey(key);
1010+
return MatchingMaps.hasKey(key);
10111011
}
10121012

10131013
/**
@@ -1019,7 +1019,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
10191019
* @param valueMatcher the matcher that must be satisfied by at least one value
10201020
*/
10211021
public static <V> org.hamcrest.Matcher<java.util.Map<?, ? extends V>> hasValue(org.hamcrest.Matcher<? super V> valueMatcher) {
1022-
return org.hamcrest.collection.IsMapContaining.hasValue(valueMatcher);
1022+
return MatchingMaps.hasValue(valueMatcher);
10231023
}
10241024

10251025
/**
@@ -1031,7 +1031,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
10311031
* @param value the value that satisfying maps must contain
10321032
*/
10331033
public static <V> org.hamcrest.Matcher<java.util.Map<?, ? extends V>> hasValue(V value) {
1034-
return org.hamcrest.collection.IsMapContaining.hasValue(value);
1034+
return MatchingMaps.hasValue(value);
10351035
}
10361036

10371037
/**

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,6 @@ public void describeTo(Description description) {
4343
.appendText("]");
4444
}
4545

46-
/**
47-
* Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains
48-
* at least one entry whose key satisfies the specified <code>keyMatcher</code> <b>and</b> whose
49-
* value satisfies the specified <code>valueMatcher</code>.
50-
* For example:
51-
* <pre>assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))</pre>
52-
*
53-
* @param keyMatcher
54-
* the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry
55-
* @param valueMatcher
56-
* the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
57-
*/
58-
public static <K,V> Matcher<Map<? extends K,? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher) {
59-
return new IsMapContaining<>(keyMatcher, valueMatcher);
60-
}
61-
62-
/**
63-
* Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains
64-
* at least one entry whose key equals the specified <code>key</code> <b>and</b> whose value equals the
65-
* specified <code>value</code>.
66-
* For example:
67-
* <pre>assertThat(myMap, hasEntry("bar", "foo"))</pre>
68-
*
69-
* @param key
70-
* the key that, in combination with the value, must be describe at least one entry
71-
* @param value
72-
* the value that, in combination with the key, must be describe at least one entry
73-
*/
74-
public static <K,V> Matcher<Map<? extends K,? extends V>> hasEntry(K key, V value) {
75-
return new IsMapContaining<>(equalTo(key), equalTo(value));
76-
}
77-
7846
/**
7947
* Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains
8048
* at least one key that satisfies the specified matcher.

hamcrest-library/src/main/java/org/hamcrest/collection/MatchingMaps.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class MatchingMaps {
5252
* @param valueMatcher the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
5353
*/
5454
public static <K, V> Matcher<Map<? extends K, ? extends V>> hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher) {
55-
return IsMapContaining.hasEntry(keyMatcher, valueMatcher);
55+
return new IsMapContaining<>(keyMatcher, valueMatcher);
5656
}
5757

5858
/**
@@ -66,7 +66,7 @@ public class MatchingMaps {
6666
* @param value the value that, in combination with the key, must be describe at least one entry
6767
*/
6868
public static <K, V> Matcher<Map<? extends K, ? extends V>> hasEntry(K key, V value) {
69-
return IsMapContaining.hasEntry(key, value);
69+
return hasEntry(equalTo(key), equalTo(value));
7070
}
7171

7272
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import java.util.Map;
77
import java.util.TreeMap;
88

9-
import static org.hamcrest.collection.IsMapContaining.hasEntry;
10-
import static org.hamcrest.core.IsAnything.anything;
11-
import static org.hamcrest.core.IsEqual.equalTo;
9+
import static org.hamcrest.collection.MatchingMaps.hasEntry;
10+
import static org.hamcrest.object.MatchingObjects.anything;
11+
import static org.hamcrest.object.MatchingObjects.equalTo;
1212

1313
public class IsMapContainingTest extends AbstractMatcherTest {
1414

1515
@Override
1616
protected Matcher<?> createMatcher() {
17-
return IsMapContaining.hasEntry("irrelevant", "irrelevant");
17+
return hasEntry("irrelevant", "irrelevant");
1818
}
1919

2020
public void testMatchesMapContainingMatchingKeyAndValue() {

0 commit comments

Comments
 (0)