File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
hamcrest-core/src/main/java/org/hamcrest/core
hamcrest-unit-test/src/main/java/org/hamcrest/core Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -31,13 +31,26 @@ public void describeTo(Description description) {
31
31
}
32
32
33
33
/**
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.
35
36
*
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
38
39
*/
39
40
@ 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 );
42
55
}
43
56
}
Original file line number Diff line number Diff line change 2
2
*/
3
3
package org .hamcrest .core ;
4
4
5
+ import static org .hamcrest .core .IsSame .theInstance ;
5
6
import static org .hamcrest .core .IsSame .sameInstance ;
6
7
import static org .hamcrest .core .IsNot .not ;
7
8
import org .hamcrest .AbstractMatcherTest ;
@@ -24,6 +25,14 @@ public void testEvaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() {
24
25
assertThat (o2 , not (sameInstance (o1 )));
25
26
}
26
27
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
+
27
36
public void testReturnsReadableDescriptionFromToString () {
28
37
assertDescription ("sameInstance(\" ARG\" )" , sameInstance ("ARG" ));
29
38
}
You can’t perform that action at this time.
0 commit comments