1/* Copyright (c) 2000-2006 hamcrest.org 2 */ 3package org.hamcrest.core; 4 5import org.hamcrest.Description; 6import org.hamcrest.Matcher; 7import org.hamcrest.Factory; 8import org.hamcrest.BaseMatcher; 9 10 11/** 12 * Is the value the same object as another value? 13 */ 14public class IsSame<T> extends BaseMatcher<T> { 15 private final T object; 16 17 public IsSame(T object) { 18 this.object = object; 19 } 20 21 public boolean matches(Object arg) { 22 return arg == object; 23 } 24 25 public void describeTo(Description description) { 26 description.appendText("same(") .appendValue(object) .appendText(")"); 27 } 28 29 /** 30 * Creates a new instance of IsSame 31 * 32 * @param object The predicate evaluates to true only when the argument is 33 * this object. 34 */ 35 @Factory 36 public static <T> Matcher<T> sameInstance(T object) { 37 return new IsSame<T>(object); 38 } 39 40} 41