Skip to content

Commit 84c8fd5

Browse files
committed
Merge PR hamcrest#43 (Change generic signature of OrderingComparison to accept Comparable<? super T>) and re-implement for new OrderingComparison/ComparatorMatcherBuilder mechanism.
1 parent 9e3875c commit 84c8fd5

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

hamcrest-library/src/main/java/org/hamcrest/comparator/ComparatorMatcherBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
public final class ComparatorMatcherBuilder<T> {
1212

13-
private final Comparator<T> comparator;
13+
private final Comparator<? super T> comparator;
1414
private final boolean includeComparatorInDescription;
1515

1616
/**
1717
* Creates a matcher factory for matchers of {@code Comparable}s.
1818
* For example:
1919
* <pre>assertThat(1, ComparatorMatcherBuilder.&lt;Integer&gt;usingNaturalOrdering().lessThanOrEqualTo(1))</pre>
2020
*/
21-
public static <T extends Comparable<T>> ComparatorMatcherBuilder<T> usingNaturalOrdering() {
21+
public static <T extends Comparable<? super T>> ComparatorMatcherBuilder<T> usingNaturalOrdering() {
2222
return new ComparatorMatcherBuilder<>(new Comparator<T>() {
2323
@Override
2424
public int compare(T o1, T o2) {
@@ -36,11 +36,11 @@ public int compare(T o1, T o2) {
3636
* }
3737
* }).lessThan(4))</pre>
3838
*/
39-
public static <T> ComparatorMatcherBuilder<T> comparedBy(Comparator<T> comparator) {
39+
public static <T> ComparatorMatcherBuilder<T> comparedBy(Comparator<? super T> comparator) {
4040
return new ComparatorMatcherBuilder<>(comparator, true);
4141
}
4242

43-
private ComparatorMatcherBuilder(Comparator<T> comparator, boolean includeComparatorInDescription) {
43+
private ComparatorMatcherBuilder(Comparator<? super T> comparator, boolean includeComparatorInDescription) {
4444
this.comparator = comparator;
4545
this.includeComparatorInDescription = includeComparatorInDescription;
4646
}
@@ -50,7 +50,7 @@ private static final class ComparatorMatcher<T> extends TypeSafeMatcher<T> {
5050
private static final int GREATER_THAN = 1;
5151
private static final int EQUAL = 0;
5252

53-
private final Comparator<T> comparator;
53+
private final Comparator<? super T> comparator;
5454
private final T expected;
5555
private final int minCompare;
5656
private final int maxCompare;
@@ -62,7 +62,7 @@ private static final class ComparatorMatcher<T> extends TypeSafeMatcher<T> {
6262
"greater than"
6363
};
6464

65-
private ComparatorMatcher(Comparator<T> comparator, T expected, int minCompare, int maxCompare, boolean includeComparatorInDescription) {
65+
private ComparatorMatcher(Comparator<? super T> comparator, T expected, int minCompare, int maxCompare, boolean includeComparatorInDescription) {
6666
this.comparator = comparator;
6767
this.expected = expected;
6868
this.minCompare = minCompare;

hamcrest-library/src/main/java/org/hamcrest/number/OrderingComparison.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private OrderingComparison() {
1919
*
2020
* @param value the value which, when passed to the compareTo method of the examined object, should return zero
2121
*/
22-
public static <T extends Comparable<T>> Matcher<T> comparesEqualTo(T value) {
22+
public static <T extends Comparable<? super T>> Matcher<T> comparesEqualTo(T value) {
2323
return ComparatorMatcherBuilder.<T>usingNaturalOrdering().comparesEqualTo(value);
2424
}
2525

@@ -33,7 +33,7 @@ public static <T extends Comparable<T>> Matcher<T> comparesEqualTo(T value) {
3333
* @param value the value which, when passed to the compareTo method of the examined object, should return greater
3434
* than zero
3535
*/
36-
public static <T extends Comparable<T>> Matcher<T> greaterThan(T value) {
36+
public static <T extends Comparable<? super T>> Matcher<T> greaterThan(T value) {
3737
return ComparatorMatcherBuilder.<T>usingNaturalOrdering().greaterThan(value);
3838
}
3939

@@ -47,7 +47,7 @@ public static <T extends Comparable<T>> Matcher<T> greaterThan(T value) {
4747
* @param value the value which, when passed to the compareTo method of the examined object, should return greater
4848
* than or equal to zero
4949
*/
50-
public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value) {
50+
public static <T extends Comparable<? super T>> Matcher<T> greaterThanOrEqualTo(T value) {
5151
return ComparatorMatcherBuilder.<T>usingNaturalOrdering().greaterThanOrEqualTo(value);
5252
}
5353

@@ -61,7 +61,7 @@ public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value)
6161
* @param value the value which, when passed to the compareTo method of the examined object, should return less
6262
* than zero
6363
*/
64-
public static <T extends Comparable<T>> Matcher<T> lessThan(T value) {
64+
public static <T extends Comparable<? super T>> Matcher<T> lessThan(T value) {
6565
return ComparatorMatcherBuilder.<T>usingNaturalOrdering().lessThan(value);
6666
}
6767

@@ -75,7 +75,7 @@ public static <T extends Comparable<T>> Matcher<T> lessThan(T value) {
7575
* @param value the value which, when passed to the compareTo method of the examined object, should return less
7676
* than or equal to zero
7777
*/
78-
public static <T extends Comparable<T>> Matcher<T> lessThanOrEqualTo(T value) {
78+
public static <T extends Comparable<? super T>> Matcher<T> lessThanOrEqualTo(T value) {
7979
return ComparatorMatcherBuilder.<T>usingNaturalOrdering().lessThanOrEqualTo(value);
8080
}
8181
}

hamcrest-library/src/main/java/org/hamcrest/object/MatchObjects.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static <T> Matcher<T> oneOf(T... elements) {
195195
*
196196
* @param value the value which, when passed to the compareTo method of the examined object, should return zero
197197
*/
198-
public static <T extends Comparable<T>> Matcher<T> comparesEqualTo(T value) {
198+
public static <T extends Comparable<? super T>> Matcher<T> comparesEqualTo(T value) {
199199
return OrderingComparison.comparesEqualTo(value);
200200
}
201201

@@ -209,7 +209,7 @@ public static <T extends Comparable<T>> Matcher<T> comparesEqualTo(T value) {
209209
* @param value the value which, when passed to the compareTo method of the examined object, should return greater
210210
* than zero
211211
*/
212-
public static <T extends Comparable<T>> Matcher<T> greaterThan(T value) {
212+
public static <T extends Comparable<? super T>> Matcher<T> greaterThan(T value) {
213213
return OrderingComparison.greaterThan(value);
214214
}
215215

@@ -223,7 +223,7 @@ public static <T extends Comparable<T>> Matcher<T> greaterThan(T value) {
223223
* @param value the value which, when passed to the compareTo method of the examined object, should return greater
224224
* than or equal to zero
225225
*/
226-
public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value) {
226+
public static <T extends Comparable<? super T>> Matcher<T> greaterThanOrEqualTo(T value) {
227227
return ComparatorMatcherBuilder.<T>usingNaturalOrdering().greaterThanOrEqualTo(value);
228228
}
229229

@@ -237,7 +237,7 @@ public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value)
237237
* @param value the value which, when passed to the compareTo method of the examined object, should return less
238238
* than zero
239239
*/
240-
public static <T extends Comparable<T>> Matcher<T> lessThan(T value) {
240+
public static <T extends Comparable<? super T>> Matcher<T> lessThan(T value) {
241241
return OrderingComparison.lessThan(value);
242242
}
243243

@@ -251,7 +251,7 @@ public static <T extends Comparable<T>> Matcher<T> lessThan(T value) {
251251
* @param value the value which, when passed to the compareTo method of the examined object, should return less
252252
* than or equal to zero
253253
*/
254-
public static <T extends Comparable<T>> Matcher<T> lessThanOrEqualTo(T value) {
254+
public static <T extends Comparable<? super T>> Matcher<T> lessThanOrEqualTo(T value) {
255255
return OrderingComparison.lessThanOrEqualTo(value);
256256
}
257257

hamcrest-library/src/test/java/org/hamcrest/number/OrderingComparisonTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000-2009 hamcrest.org
1+
/* Copyright (c) 2000-2013 hamcrest.org
22
*/
33
package org.hamcrest.number;
44

0 commit comments

Comments
 (0)