### Question:
EqualsPredicate implements Predicate<T> { @Override public boolean evaluate(T other) { return Objects.equal(controlObject, other); } EqualsPredicate(T controlObject); @Override boolean evaluate(T other); @Override boolean equals(Object other); @Override int hashCode();  }### Answer:
@Test public void shouldDelegateThroughToEqualsOnInitialisedObjectWithSuppliedObjectAndReturnTheResult() throws Exception { Name first = name("James"); Name second = name("James"); EqualsPredicate<Name> predicate = new EqualsPredicate<Name>(first); Boolean result = predicate.evaluate(second); assertThat(result, is(true)); }
@Test public void shouldReturnFalseIfEvaluatedObjectIsNotEqualToObjectUsedAtInitialisationViaEqualsMethod() throws Exception { Name first = name("John"); Name second = name("Anne"); EqualsPredicate<Name> predicate = new EqualsPredicate<Name>(first); Boolean result = predicate.evaluate(second); assertThat(result, is(false)); }
@Test public void shouldPassNullValuesThroughToObjectsEquals() throws Exception { Object first = new Object(); ObjectWithEqualsCapture second = new ObjectWithEqualsCapture(); EqualsPredicate<Object> predicate = new EqualsPredicate<Object>(first); predicate.evaluate(second); assertThat(second.getObjectEqualsWasCalledWith(), is((Object) null)); }
@Test public void shouldNotThrowNullPointerExceptionIfControlObjectIsNull() throws Exception { Object first = null; Object second = new Object(); EqualsPredicate<Object> predicate = new EqualsPredicate<Object>(first); try { predicate.evaluate(second); } catch(NullPointerException exception) { fail("Expected no NullPointerException to be thrown but one was."); } }
@Test public void shouldNotThrowNullPointerExceptionIfTestObjectIsNull() throws Exception { Object first = new Object(); Object second = null; EqualsPredicate<Object> predicate = new EqualsPredicate<Object>(first); try { predicate.evaluate(second); } catch(NullPointerException exception) { fail("Expected no NullPointerException to be thrown but one was."); } }