### Question:
Wrapper { public Wrapper<T> wrap(T wrapped) { this.wrapped = wrapped; return this; }  Wrapper<T> wrap(T wrapped); T getWrapped(); void setPosition(int position); int getPosition(); @Override int hashCode(); @Override @SuppressWarnings("unchecked") boolean equals(Object obj); @Override String toString(); abstract boolean safelyEquals(T actual, T expected); abstract String asString(T obj);  }### Answer:
@Test public void testEqualsSymmetric() { Wrapper<Object> objectWrapper1 = createTestWrapper(); Wrapper<Object> objectWrapper2 = createTestWrapper().wrap(objectWrapper1); Wrapper<Object> objectWrapper3 = createTestWrapper().wrap(objectWrapper1); String errorMessage = "Equals method should be symmetric"; Assert.assertThat(errorMessage, objectWrapper2, equalTo(objectWrapper3)); Assert.assertThat(errorMessage, objectWrapper3, equalTo(objectWrapper2)); Assert.assertThat(errorMessage, objectWrapper1, not(equalTo(objectWrapper2))); Assert.assertThat(errorMessage, objectWrapper2, not(equalTo(objectWrapper1))); }
@Test public void testEqualsTransitive() { Wrapper<Object> objectWrapper1 = createTestWrapper(); Wrapper<Object> objectWrapper2 = createTestWrapper().wrap(objectWrapper1); Wrapper<Object> objectWrapper3 = createTestWrapper().wrap(objectWrapper1); Wrapper<Object> objectWrapper4 = createTestWrapper().wrap(objectWrapper1); String errorMessage = "Equals method should be transitive"; Assert.assertThat(errorMessage, objectWrapper2, equalTo(objectWrapper3)); Assert.assertThat(errorMessage, objectWrapper3, equalTo(objectWrapper4)); Assert.assertThat(errorMessage, objectWrapper2, equalTo(objectWrapper4)); }
@Test public void testEqualsConsistent() { Wrapper<Object> objectWrapper1 = createTestWrapper(); Wrapper<Object> objectWrapper2 = createTestWrapper().wrap(objectWrapper1); Wrapper<Object> objectWrapper3 = createTestWrapper().wrap(objectWrapper1); final int attempts = 10; for (int i = 0; i < attempts; i++) { Assert.assertThat( "Equals method should be consistent", objectWrapper2, equalTo(objectWrapper3) ); } }