IsSame extends BaseMatcher<Object> { @Override public boolean matches(final Object arg) { return arg == object; } IsSame(final Object object); static Matcher sameInstance(final Object target); @Override boolean matches(final Object arg); @Override void describeTo(final Description description);  }
@Test public void testGivenTwoInstancesOfSameObjectWhenMatchesIsCalledThenTrueIsReturned() throws Exception { assumeTrue("Assumed that actual and comparison are the same object", actual == comparison); final boolean matches = sameInstanceMatcher.matches(actual); assertMatches(matches); }
@Test public void testGivenTwoInstancesOfDifferentObjectsWhenMatchesIsCalledThenFalseIsReturned() throws Exception { final Object actual = new Object(); assumeFalse("Assumed that actual and comparison are not the same object", actual == comparison); final boolean matches = sameInstanceMatcher.matches(actual); assertDoesNotMatch(matches); }