File tree Expand file tree Collapse file tree
hamcrest-core/src/main/java/org/hamcrest/core
hamcrest-unit-test/src/main/java/org/hamcrest/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,13 +31,26 @@ public void describeTo(Description description) {
3131 }
3232
3333 /**
34- * Creates a new instance of IsSame
34+ * Creates a matcher that evaluates to true only when the examined object is the
35+ * same instance as the specified target object.
3536 *
36- * @param object The predicate evaluates to true only when the argument is
37- * this object.
37+ * @param target
38+ * the target instance against which others should be assessed
3839 */
3940 @ Factory
40- public static <T > Matcher <T > sameInstance (T object ) {
41- return new IsSame <T >(object );
41+ public static <T > Matcher <T > sameInstance (T target ) {
42+ return new IsSame <T >(target );
43+ }
44+
45+ /**
46+ * Creates a matcher that evaluates to true only when the examined object is the
47+ * same instance as the specified target object.
48+ *
49+ * @param target
50+ * the target instance against which others should be assessed
51+ */
52+ @ Factory
53+ public static <T > Matcher <T > theInstance (T target ) {
54+ return new IsSame <T >(target );
4255 }
4356}
Original file line number Diff line number Diff line change 22 */
33package org .hamcrest .core ;
44
5+ import static org .hamcrest .core .IsSame .theInstance ;
56import static org .hamcrest .core .IsSame .sameInstance ;
67import static org .hamcrest .core .IsNot .not ;
78import org .hamcrest .AbstractMatcherTest ;
@@ -24,6 +25,14 @@ public void testEvaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() {
2425 assertThat (o2 , not (sameInstance (o1 )));
2526 }
2627
28+ public void testAlternativeFactoryMethodAlsoMatchesOnlyIfArgumentIsReferenceToASpecifiedObject () {
29+ Object o1 = new Object ();
30+ Object o2 = new Object ();
31+
32+ assertThat (o1 , theInstance (o1 ));
33+ assertThat (o2 , not (theInstance (o1 )));
34+ }
35+
2736 public void testReturnsReadableDescriptionFromToString () {
2837 assertDescription ("sameInstance(\" ARG\" )" , sameInstance ("ARG" ));
2938 }
You can’t perform that action at this time.
0 commit comments