Skip to content

Commit deca642

Browse files
committed
Factory methods. Map size
1 parent ed60476 commit deca642

File tree

4 files changed

+36
-68
lines changed

4 files changed

+36
-68
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.hamcrest.collection.MatchingArrays;
44
import org.hamcrest.collection.MatchingCollections;
55
import org.hamcrest.collection.MatchingIterables;
6+
import org.hamcrest.collection.MatchingMaps;
67
import org.hamcrest.number.MatchingNumbers;
78
import org.hamcrest.object.MatchingObjects;
89
import org.hamcrest.text.MatchingStrings;
@@ -669,8 +670,8 @@ public static <E> org.hamcrest.Matcher<E[]> emptyArray() {
669670
*
670671
* @param sizeMatcher a matcher for the size of an examined {@link java.util.Map}
671672
*/
672-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> aMapWithSize(org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher) {
673-
return org.hamcrest.collection.IsMapWithSize.aMapWithSize(sizeMatcher);
673+
public static <K, V> Matcher<java.util.Map<? extends K, ? extends V>> aMapWithSize(org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher) {
674+
return MatchingMaps.aMapWithSize(sizeMatcher);
674675
}
675676

676677
/**
@@ -681,8 +682,8 @@ public static <E> org.hamcrest.Matcher<E[]> emptyArray() {
681682
*
682683
* @param size the expected size of an examined {@link java.util.Map}
683684
*/
684-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> aMapWithSize(int size) {
685-
return org.hamcrest.collection.IsMapWithSize.aMapWithSize(size);
685+
public static <K, V> Matcher<java.util.Map<? extends K, ? extends V>> aMapWithSize(int size) {
686+
return MatchingMaps.aMapWithSize(size);
686687
}
687688

688689
/**
@@ -691,8 +692,8 @@ public static <E> org.hamcrest.Matcher<E[]> emptyArray() {
691692
* For example:
692693
* <pre>assertThat(myMap, is(anEmptyMap()))</pre>
693694
*/
694-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> anEmptyMap() {
695-
return org.hamcrest.collection.IsMapWithSize.anEmptyMap();
695+
public static <K, V> Matcher<java.util.Map<? extends K, ? extends V>> anEmptyMap() {
696+
return MatchingMaps.anEmptyMap();
696697
}
697698

698699
/**
@@ -716,7 +717,7 @@ public static <E> org.hamcrest.Matcher<java.util.Collection<? extends E>> hasSiz
716717
* @param size the expected size of an examined {@link java.util.Collection}
717718
*/
718719
public static <E> org.hamcrest.Matcher<java.util.Collection<? extends E>> hasSize(int size) {
719-
return org.hamcrest.collection.IsCollectionWithSize.hasSize(size);
720+
return MatchingCollections.hasSize(size);
720721
}
721722

722723
/**
@@ -967,7 +968,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
967968
* @param keyMatcher the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry
968969
* @param valueMatcher the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
969970
*/
970-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(org.hamcrest.Matcher<? super K> keyMatcher, org.hamcrest.Matcher<? super V> valueMatcher) {
971+
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) {
971972
return org.hamcrest.collection.IsMapContaining.hasEntry(keyMatcher, valueMatcher);
972973
}
973974

@@ -981,7 +982,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(i
981982
* @param key the key that, in combination with the value, must be describe at least one entry
982983
* @param value the value that, in combination with the key, must be describe at least one entry
983984
*/
984-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(K key, V value) {
985+
public static <K, V> Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(K key, V value) {
985986
return org.hamcrest.collection.IsMapContaining.hasEntry(key, value);
986987
}
987988

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import java.util.Map;
77

8-
import static org.hamcrest.core.IsEqual.equalTo;
9-
108
/**
119
* Matches if map size satisfies a nested matcher.
1210
*/
@@ -20,41 +18,4 @@ protected Integer featureValueOf(Map<? extends K, ? extends V> actual) {
2018
return actual.size();
2119
}
2220

23-
/**
24-
* Creates a matcher for {@link java.util.Map}s that matches when the <code>size()</code> method returns
25-
* a value that satisfies the specified matcher.
26-
* For example:
27-
* <pre>assertThat(myMap, is(aMapWithSize(equalTo(2))))</pre>
28-
*
29-
* @param sizeMatcher
30-
* a matcher for the size of an examined {@link java.util.Map}
31-
*/
32-
public static <K, V> Matcher<Map<? extends K, ? extends V>> aMapWithSize(Matcher<? super Integer> sizeMatcher) {
33-
return new IsMapWithSize<>(sizeMatcher);
34-
}
35-
36-
/**
37-
* Creates a matcher for {@link java.util.Map}s that matches when the <code>size()</code> method returns
38-
* a value equal to the specified <code>size</code>.
39-
* For example:
40-
* <pre>assertThat(myMap, is(aMapWithSize(2)))</pre>
41-
*
42-
* @param size
43-
* the expected size of an examined {@link java.util.Map}
44-
*/
45-
public static <K, V> Matcher<Map<? extends K, ? extends V>> aMapWithSize(int size) {
46-
Matcher<? super Integer> matcher = equalTo(size);
47-
return IsMapWithSize.aMapWithSize(matcher);
48-
}
49-
50-
/**
51-
* Creates a matcher for {@link java.util.Map}s that matches when the <code>size()</code> method returns
52-
* zero.
53-
* For example:
54-
* <pre>assertThat(myMap, is(anEmptyMap()))</pre>
55-
*
56-
*/
57-
public static <K, V> Matcher<Map<? extends K, ? extends V>> anEmptyMap() {
58-
return IsMapWithSize.aMapWithSize(equalTo(0));
59-
}
6021
}

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.hamcrest.collection;
22

3+
import org.hamcrest.Matcher;
4+
5+
import java.util.Map;
6+
7+
import static org.hamcrest.core.IsEqual.equalTo;
8+
39
public class MatchingMaps {
410
/**
511
* Creates a matcher for {@link java.util.Map}s that matches when the <code>size()</code> method returns
@@ -9,8 +15,8 @@ public class MatchingMaps {
915
*
1016
* @param sizeMatcher a matcher for the size of an examined {@link java.util.Map}
1117
*/
12-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> aMapWithSize(org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher) {
13-
return org.hamcrest.collection.IsMapWithSize.aMapWithSize(sizeMatcher);
18+
public static <K, V> Matcher<Map<? extends K, ? extends V>> aMapWithSize(Matcher<? super Integer> sizeMatcher) {
19+
return new IsMapWithSize<>(sizeMatcher);
1420
}
1521

1622
/**
@@ -21,8 +27,8 @@ public class MatchingMaps {
2127
*
2228
* @param size the expected size of an examined {@link java.util.Map}
2329
*/
24-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> aMapWithSize(int size) {
25-
return org.hamcrest.collection.IsMapWithSize.aMapWithSize(size);
30+
public static <K, V> Matcher<Map<? extends K, ? extends V>> aMapWithSize(int size) {
31+
return aMapWithSize(equalTo(size));
2632
}
2733

2834
/**
@@ -31,8 +37,8 @@ public class MatchingMaps {
3137
* For example:
3238
* <pre>assertThat(myMap, is(anEmptyMap()))</pre>
3339
*/
34-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> anEmptyMap() {
35-
return org.hamcrest.collection.IsMapWithSize.anEmptyMap();
40+
public static <K, V> Matcher<Map<? extends K, ? extends V>> anEmptyMap() {
41+
return aMapWithSize(equalTo(0));
3642
}
3743

3844
/**
@@ -45,8 +51,8 @@ public class MatchingMaps {
4551
* @param keyMatcher the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry
4652
* @param valueMatcher the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry
4753
*/
48-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(org.hamcrest.Matcher<? super K> keyMatcher, org.hamcrest.Matcher<? super V> valueMatcher) {
49-
return org.hamcrest.collection.IsMapContaining.hasEntry(keyMatcher, valueMatcher);
54+
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);
5056
}
5157

5258
/**
@@ -59,8 +65,8 @@ public class MatchingMaps {
5965
* @param key the key that, in combination with the value, must be describe at least one entry
6066
* @param value the value that, in combination with the key, must be describe at least one entry
6167
*/
62-
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(K key, V value) {
63-
return org.hamcrest.collection.IsMapContaining.hasEntry(key, value);
68+
public static <K, V> Matcher<Map<? extends K, ? extends V>> hasEntry(K key, V value) {
69+
return IsMapContaining.hasEntry(key, value);
6470
}
6571

6672
/**
@@ -71,8 +77,8 @@ public class MatchingMaps {
7177
*
7278
* @param keyMatcher the matcher that must be satisfied by at least one key
7379
*/
74-
public static <K> org.hamcrest.Matcher<java.util.Map<? extends K, ?>> hasKey(org.hamcrest.Matcher<? super K> keyMatcher) {
75-
return org.hamcrest.collection.IsMapContaining.hasKey(keyMatcher);
80+
public static <K> org.hamcrest.Matcher<Map<? extends K, ?>> hasKey(Matcher<? super K> keyMatcher) {
81+
return IsMapContaining.hasKey(keyMatcher);
7682
}
7783

7884
/**
@@ -83,8 +89,8 @@ public class MatchingMaps {
8389
*
8490
* @param key the key that satisfying maps must contain
8591
*/
86-
public static <K> org.hamcrest.Matcher<java.util.Map<? extends K, ?>> hasKey(K key) {
87-
return org.hamcrest.collection.IsMapContaining.hasKey(key);
92+
public static <K> org.hamcrest.Matcher<Map<? extends K, ?>> hasKey(K key) {
93+
return IsMapContaining.hasKey(key);
8894
}
8995

9096
/**
@@ -95,8 +101,8 @@ public class MatchingMaps {
95101
*
96102
* @param valueMatcher the matcher that must be satisfied by at least one value
97103
*/
98-
public static <V> org.hamcrest.Matcher<java.util.Map<?, ? extends V>> hasValue(org.hamcrest.Matcher<? super V> valueMatcher) {
99-
return org.hamcrest.collection.IsMapContaining.hasValue(valueMatcher);
104+
public static <V> org.hamcrest.Matcher<Map<?, ? extends V>> hasValue(Matcher<? super V> valueMatcher) {
105+
return IsMapContaining.hasValue(valueMatcher);
100106
}
101107

102108
/**
@@ -107,8 +113,8 @@ public class MatchingMaps {
107113
*
108114
* @param value the value that satisfying maps must contain
109115
*/
110-
public static <V> org.hamcrest.Matcher<java.util.Map<?, ? extends V>> hasValue(V value) {
111-
return org.hamcrest.collection.IsMapContaining.hasValue(value);
116+
public static <V> org.hamcrest.Matcher<Map<?, ? extends V>> hasValue(V value) {
117+
return IsMapContaining.hasValue(value);
112118
}
113119

114120
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import java.util.HashMap;
88
import java.util.Map;
99

10-
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
11-
import static org.hamcrest.core.IsEqual.equalTo;
10+
import static org.hamcrest.collection.MatchingMaps.aMapWithSize;
11+
import static org.hamcrest.object.MatchingObjects.equalTo;
1212

1313
public final class IsMapWithSizeTest extends AbstractMatcherTest {
1414

0 commit comments

Comments
 (0)