### Question:
ReferralImpl implements Referral { @Override public boolean equals( Object obj ) { if ( obj == this ) { return true; } if ( obj instanceof Referral ) { Collection<String> refs = ( ( Referral ) obj ).getLdapUrls(); if ( refs.size() != urls.size() ) { return false; } Iterator<String> list = urls.iterator(); while ( list.hasNext() ) { if ( !refs.contains( list.next() ) ) { return false; } } return true; } return false; }  @Override int getReferralLength(); @Override void setReferralLength( int referralLength ); @Override Collection<String> getLdapUrls(); @Override Collection<byte[]> getLdapUrlsBytes(); @Override void addLdapUrl( String url ); @Override void addLdapUrlBytes( byte[] urlBytes ); @Override void removeLdapUrl( String url ); @Override int hashCode(); @Override boolean equals( Object obj ); @Override String toString();  }### Answer:
@Test public void testEqualsSameObject() { ReferralImpl refs = new ReferralImpl(); assertTrue( refs.equals( refs ), "equals method should work for the same object" ); }
@Test public void testEqualsDifferentImpls() { Referral refs0 = new Referral() { public Collection<String> getLdapUrls() { return Collections.emptyList(); } public void addLdapUrl( String url ) { } public void removeLdapUrl( String url ) { } public void addLdapUrlBytes( byte[] urlBytes ) { } public Collection<byte[]> getLdapUrlsBytes() { return null; } public int getReferralLength() { return 0; } public void setReferralLength( int referralLength ) { } }; ReferralImpl refs1 = new ReferralImpl(); assertFalse( refs0.equals( refs1 ), "Object.equals() in effect because we did not redefine equals for the new impl above" ); assertTrue( refs1.equals( refs0 ), "Empty Referrals should be equal even if they are different implementation classes" ); }