Skip to content

Commit 8d168e5

Browse files
author
joeretro
committed
Added convenient is(Class<T>)
1 parent 0f8f021 commit 8d168e5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

matchers.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
<!-- Core -->
44
<factory class="org.hamcrest.core.Is"/>
5-
<factory class="org.hamcrest.core.AllOf"/>
6-
<factory class="org.hamcrest.core.AnyOf"/>
75
<factory class="org.hamcrest.core.IsNot"/>
86
<factory class="org.hamcrest.core.IsEqual"/>
7+
<factory class="org.hamcrest.core.IsInstanceOf"/>
8+
<factory class="org.hamcrest.core.AllOf"/>
9+
<factory class="org.hamcrest.core.AnyOf"/>
910
<factory class="org.hamcrest.core.IsSame"/>
1011
<factory class="org.hamcrest.core.IsAnything"/>
1112
<factory class="org.hamcrest.core.IsNull"/>
12-
<factory class="org.hamcrest.core.IsInstanceOf"/>
1313
<factory class="org.hamcrest.core.DescribedAs"/>
1414

1515
<!-- Collection -->

src/library/org/hamcrest/core/Is.java

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

3+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
34
import static org.hamcrest.core.IsEqual.equalTo;
45
import org.hamcrest.Factory;
56
import org.hamcrest.Matcher;
@@ -53,5 +54,16 @@ public static <T> Matcher<T> is(T value) {
5354
return is(equalTo(value));
5455
}
5556

57+
/**
58+
* This is a shortcut to the frequently used is(instanceOf(SomeClass.class)).
59+
*
60+
* eg. assertThat(cheese, is(instanceOf(Cheddar.class)))
61+
* vs assertThat(cheese, is(Cheddar.class))
62+
*/
63+
@Factory
64+
public static <T> Matcher<T> is(Class<T> type) {
65+
return is(instanceOf(type));
66+
}
67+
5668
}
5769

0 commit comments

Comments
 (0)