File tree Expand file tree Collapse file tree
main/java/org/hamcrest/core
test/java/org/hamcrest/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,4 +91,13 @@ private static boolean isArray(Object o) {
9191 public static <T > Matcher <T > equalTo (T operand ) {
9292 return new IsEqual <T >(operand );
9393 }
94+
95+ /**
96+ * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being
97+ * compared to be of the same static type.
98+ */
99+ @ Factory
100+ public static Matcher <Object > equalToObject (Object operand ) {
101+ return new IsEqual <Object >(operand );
102+ }
94103}
Original file line number Diff line number Diff line change 88import static org .hamcrest .AbstractMatcherTest .assertNullSafe ;
99import static org .hamcrest .AbstractMatcherTest .assertUnknownTypeSafe ;
1010import static org .hamcrest .core .IsEqual .equalTo ;
11+ import static org .hamcrest .core .IsEqual .equalToObject ;
1112
1213import org .hamcrest .Matcher ;
1314import org .junit .Test ;
@@ -110,6 +111,16 @@ public boolean equals(Object obj) {
110111 assertDoesNotMatch (matcher , null );
111112 }
112113
114+ @ Test public void
115+ hasUntypedVariant () {
116+ Object original = 10 ;
117+
118+ assertMatches (equalToObject (10 ), original );
119+ assertDoesNotMatch (equalToObject (0 ), original );
120+ assertDoesNotMatch (equalToObject ("10" ), original );
121+ assertDoesNotMatch (equalToObject (10 ), "10" );
122+ }
123+
113124 @ Test public void
114125 includesTheResultOfCallingToStringOnItsArgumentInTheDescription () {
115126 final String argumentDescription = "ARGUMENT DESCRIPTION" ;
You can’t perform that action at this time.
0 commit comments