Skip to content

Commit 613cd12

Browse files
author
david.saff
committed
is(Class) and is(Object) both are Matcher<Object>, which makes Java sense
1 parent 0d6daa4 commit 613cd12

File tree

8 files changed

+19
-22
lines changed

8 files changed

+19
-22
lines changed

hamcrest-core/src/main/java/org/hamcrest/core/Is.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static <T> Matcher<T> is(Matcher<T> matcher) {
5555
* vs. assertThat(cheese, is(smelly))
5656
*/
5757
@Factory
58-
public static <T> Matcher<? super T> is(T value) {
58+
public static Matcher<Object> is(Object value) {
5959
return is(equalTo(value));
6060
}
6161

@@ -66,7 +66,7 @@ public static <T> Matcher<? super T> is(T value) {
6666
* vs. assertThat(cheese, is(Cheddar.class))
6767
*/
6868
@Factory
69-
public static <T> Matcher<? super T> is(Class<T> type) {
69+
public static Matcher<Object> is(Class<?> type) {
7070
return is(instanceOf(type));
7171
}
7272
}

hamcrest-core/src/main/java/org/hamcrest/core/IsEqual.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* Is the value equal to another value, as tested by the
1515
* {@link java.lang.Object#equals} invokedMethod?
1616
*/
17-
public class IsEqual<T> extends BaseMatcher<T> {
17+
public class IsEqual extends BaseMatcher<Object> {
1818
private final Object object;
1919

20-
public IsEqual(T equalArg) {
20+
public IsEqual(Object equalArg) {
2121
object = equalArg;
2222
}
2323

@@ -64,7 +64,7 @@ private static boolean isArray(Object o) {
6464
* {@link java.lang.Object#equals} invokedMethod?
6565
*/
6666
@Factory
67-
public static <T> Matcher<? super T> equalTo(T operand) {
68-
return new IsEqual<T>(operand);
67+
public static Matcher<Object> equalTo(Object operand) {
68+
return new IsEqual(operand);
6969
}
7070
}

hamcrest-library/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static class PropertyMatcher extends DiagnosingMatcher<Object> {
9494
public PropertyMatcher(PropertyDescriptor descriptor, Object expectedObject) {
9595
this.propertyName = descriptor.getDisplayName();
9696
this.readMethod = descriptor.getReadMethod();
97-
this.matcher = new IsEqual<Object>(readProperty(readMethod, expectedObject));
97+
this.matcher = new IsEqual(readProperty(readMethod, expectedObject));
9898
}
9999
@Override
100100
public boolean matches(Object actual, Description mismatchDescription) {

hamcrest-unit-test/src/main/java/org/hamcrest/FeatureMatcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void testDoesNotThrowClassCastException() {
3131
}
3232

3333

34-
public static class Match extends IsEqual<String> {
34+
public static class Match extends IsEqual {
3535
public Match(String equalArg) { super(equalArg); }
3636
@Override public void describeMismatch(Object item, Description description) {
3737
description.appendText("mismatch-description");

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContainingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24
5151
{
5252
final Set<Number> s = new HashSet<Number>();
5353
s.add(Integer.valueOf(2));
54-
assertThat(s, new IsCollectionContaining<Number>(new IsEqual<Object>(Integer.valueOf(2))));
54+
assertThat(s, new IsCollectionContaining<Number>(new IsEqual(Integer.valueOf(2))));
5555
assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2)));
5656
}
5757

hamcrest-unit-test/src/main/java/org/hamcrest/core/AllOfTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ protected Matcher<?> createMatcher() {
1616
return allOf(equalTo("irrelevant"));
1717
}
1818

19-
@SuppressWarnings("unchecked")
2019
public void testEvaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() {
2120
assertThat("good", allOf(equalTo("good"), equalTo("good")));
2221

@@ -25,30 +24,26 @@ public void testEvaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() {
2524
assertThat("good", not(allOf(equalTo("bad"), equalTo("bad"))));
2625
}
2726

28-
@SuppressWarnings("unchecked")
2927
public void testEvaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() {
3028
assertThat("good", allOf(equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good")));
3129
assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good"))));
3230
}
3331

34-
@SuppressWarnings("unchecked")
3532
public void testSupportsMixedTypes() {
36-
final Matcher<SampleSubClass> all = allOf(
33+
final Matcher<Object> all = allOf(
3734
equalTo(new SampleBaseClass("bad")),
3835
equalTo(new SampleBaseClass("good")),
3936
equalTo(new SampleSubClass("ugly")));
40-
final Matcher<SampleSubClass> negated = not(all);
37+
final Matcher<Object> negated = not(all);
4138

4239
assertThat(new SampleSubClass("good"), negated);
4340
}
4441

45-
@SuppressWarnings("unchecked")
4642
public void testHasAReadableDescription() {
4743
assertDescription("(\"good\" and \"bad\" and \"ugly\")",
4844
allOf(equalTo("good"), equalTo("bad"), equalTo("ugly")));
4945
}
5046

51-
@SuppressWarnings("unchecked")
5247
public void testMismatchDescriptionDescribesFirstFailingMatch() {
5348
assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad");
5449
}

hamcrest-unit-test/src/main/java/org/hamcrest/core/AnyOfTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ protected Matcher<?> createMatcher() {
1616
return anyOf(equalTo("irrelevant"));
1717
}
1818

19-
@SuppressWarnings("unchecked")
2019
public void testEvaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() {
2120
assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
2221
assertThat("good", anyOf(equalTo("good"), equalTo("good")));
@@ -25,15 +24,13 @@ public void testEvaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() {
2524
assertThat("good", not(anyOf(equalTo("bad"), equalTo("bad"))));
2625
}
2726

28-
@SuppressWarnings("unchecked")
2927
public void testEvaluatesToTheTheLogicalDisjunctionOfManyOtherMatchers() {
3028
assertThat("good", anyOf(equalTo("bad"), equalTo("good"), equalTo("bad"), equalTo("bad"), equalTo("bad")));
3129
assertThat("good", not(anyOf(equalTo("bad"), equalTo("bad"), equalTo("bad"), equalTo("bad"), equalTo("bad"))));
3230
}
3331

34-
@SuppressWarnings("unchecked")
3532
public void testSupportsMixedTypes() {
36-
final Matcher<SampleSubClass> combined = anyOf(
33+
final Matcher<Object> combined = anyOf(
3734
equalTo(new SampleBaseClass("bad")),
3835
equalTo(new SampleBaseClass("good")),
3936
equalTo(new SampleSubClass("ugly"))
@@ -42,7 +39,6 @@ public void testSupportsMixedTypes() {
4239
assertThat(new SampleSubClass("good"), combined);
4340
}
4441

45-
@SuppressWarnings("unchecked")
4642
public void testHasAReadableDescription() {
4743
assertDescription("(\"good\" or \"bad\" or \"ugly\")",
4844
anyOf(equalTo("good"), equalTo("bad"), equalTo("ugly")));

hamcrest-unit-test/src/main/java/org/hamcrest/core/CombinableTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.hamcrest.core;
22

3+
import static org.hamcrest.CoreMatchers.is;
34
import static org.hamcrest.CoreMatchers.not;
45
import static org.hamcrest.MatcherAssert.assertThat;
56
import static org.hamcrest.Matchers.equalTo;
@@ -22,11 +23,16 @@ public void bothAcceptsAndRejects() {
2223
}
2324

2425
@Test
25-
public void bothAcceptsAndRejectsInline() {
26+
public void bothCompilesWithEqualTo() {
2627
assertThat(2, CombinableMatcher.both(not(equalTo(3))).and(not(equalTo(4))));
2728
assertThat(3, not(CombinableMatcher.both(not(equalTo(3))).and(not(equalTo(4)))));
2829
}
2930

31+
@Test
32+
public void bothCompilesWithIs() {
33+
assertThat(3, CombinableMatcher.both(is(3)).and(is(Integer.class)));
34+
}
35+
3036
@Test
3137
public void acceptsAndRejectsThreeAnds() {
3238
final CombinableMatcher<? super Integer> tripleAnd = NOT_3_AND_NOT_4.and(equalTo(2));

0 commit comments

Comments
 (0)