ScoredCandidate implements Candidate, Comparable<ScoredCandidate> { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof Candidate)) { return false; } if (delegate == null) { return false; } Candidate other = (Candidate) obj; return delegate.getId().equals(other.getId()); } ScoredCandidate(Candidate candidate, int score); @Override String getId(); @Override String getName(); @Override Map<String, String> getKeyValuePairs(); @Override int compareTo(ScoredCandidate o); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void scoredCandidateEquals() { DefaultCandidate delegate1 = new DefaultCandidate(TEST, TEST, ImmutableMap.of(TEST, TEST)); DefaultCandidate delegate2 = new DefaultCandidate(OTHER, OTHER, ImmutableMap.of(OTHER, OTHER)); ScoredCandidate scored1 = new ScoredCandidate(delegate1, 10); ScoredCandidate scored2 = new ScoredCandidate(delegate1, 0); ScoredCandidate scored0 = new ScoredCandidate(delegate2, 10); assertEquals(scored1, scored1); assertEquals(scored1, scored2); assertTrue(scored1.equals(delegate1)); assertFalse(scored1.equals(null)); assertFalse(scored1.equals(scored0)); }