Skip to content

Commit c445ec3

Browse files
committed
Tidy up generics. Test to prove
hamcrest#38
1 parent cfaf873 commit c445ec3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public void describeTo(Description description) {
3333
/**
3434
* Creates a matcher that always matches, regardless of the examined object.
3535
*/
36-
public static Matcher<Object> anything() {
37-
return new IsAnything<Object>();
38-
}
36+
public static Matcher<Object> anything() { return new IsAnything<>(); }
3937

4038
/**
4139
* Creates a matcher that always matches, regardless of the examined object, but describes
@@ -45,6 +43,6 @@ public static Matcher<Object> anything() {
4543
* a meaningful {@link String} used when describing itself
4644
*/
4745
public static Matcher<Object> anything(String description) {
48-
return new IsAnything<Object>(description);
46+
return new IsAnything<>(description);
4947
}
5048
}

hamcrest-core/src/test/java/org/hamcrest/core/IsAnythingTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,31 @@
55

66
import static org.hamcrest.AbstractMatcherTest.assertDescription;
77
import static org.hamcrest.AbstractMatcherTest.assertMatches;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
import static org.hamcrest.core.Is.is;
810
import static org.hamcrest.core.IsAnything.anything;
911

1012
public final class IsAnythingTest {
1113

1214
private final Matcher<Object> matcher = anything();
1315

14-
private static class CustomThing { }
15-
16-
@Test public void
16+
private static class CustomThing {
17+
}
18+
19+
@Test
20+
public void
1721
alwaysEvaluatesToTrue() {
1822
assertMatches("didn't match null", matcher, null);
1923
assertMatches("didn't match Object", matcher, new Object());
2024
assertMatches("didn't match custom object", matcher, new CustomThing());
2125
assertMatches("didn't match String", matcher, "hi");
2226
}
2327

28+
@Test
29+
public void compilesWithoutTypeWarnings() {
30+
assertThat(new CustomThing(), is(anything()));
31+
}
32+
2433
@Test public void
2534
hasUsefulDefaultDescription() {
2635
assertDescription("ANYTHING", matcher);

0 commit comments

Comments
 (0)