Skip to content

Commit

Permalink
Implement PreferTag#hashCode()
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlinchen authored and Andrew Woods committed Feb 19, 2015
1 parent bb6072d commit c2e1af0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Expand Up @@ -146,4 +146,13 @@ public boolean equals(final Object obj) {
return false;
}
}

@Override
public int hashCode() {
if (getTag() == null) {
return 0;
}

return getTag().hashCode();
}
}
Expand Up @@ -15,14 +15,15 @@
*/
package org.fcrepo.http.commons.domain;

import org.junit.Test;

import java.text.ParseException;

import static org.fcrepo.kernel.RdfLexicon.LDP_NAMESPACE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.text.ParseException;

import org.junit.Test;

/**
* @author cabeer
*/
Expand All @@ -48,4 +49,25 @@ public void testEquals() throws ParseException {
assertFalse(preferTag1.equals(null));
assertFalse(preferTag1.equals("some string"));
}

@Test
public void testHashCode() throws ParseException {
doTestHashCode(new PreferTag("handling=lenient; received=\"minimal\""),
new PreferTag("handling=lenient; received=\"minimal\""),
true);

doTestHashCode(new PreferTag("handling=lenient; received=\"minimal\""),
new PreferTag("return=representation; include=\"" + LDP_NAMESPACE + "PreferMinimalContainer\""),
false);

doTestHashCode(new PreferTag("handling=lenient; received=\"minimal\""),
PreferTag.emptyTag(),
false);
}

private void doTestHashCode(final PreferTag tag0, final PreferTag tag1, final boolean expectEqual) {
assertEquals(expectEqual, tag0.equals(tag1));
assertEquals(expectEqual, tag0.hashCode() == tag1.hashCode());
}

}

0 comments on commit c2e1af0

Please sign in to comment.