Merge pull request #117 from matzon/master

implement hashCode and equals in JwtMap
This commit is contained in:
Les Hazlewood 2016-09-11 12:57:02 -07:00 committed by GitHub
commit 0f63ec8012
2 changed files with 34 additions and 0 deletions

View File

@ -155,4 +155,14 @@ public class JwtMap implements Map<String,Object> {
public String toString() {
return map.toString();
}
@Override
public int hashCode() {
return map.hashCode();
}
@Override
public boolean equals(Object obj) {
return map.equals(obj);
}
}

View File

@ -124,4 +124,28 @@ class JwtMapTest {
def s = ['b', 'd']
assertTrue m.values().containsAll(s) && s.containsAll(m.values())
}
@Test
public void testEquals() throws Exception {
def m1 = new JwtMap();
m1.put("a", "a");
def m2 = new JwtMap();
m2.put("a", "a");
assertEquals(m1, m2);
}
@Test
public void testHashcode() throws Exception {
def m = new JwtMap();
def hashCodeEmpty = m.hashCode();
m.put("a", "b");
def hashCodeNonEmpty = m.hashCode();
assertTrue(hashCodeEmpty != hashCodeNonEmpty);
def identityHash = System.identityHashCode(m);
assertTrue(hashCodeNonEmpty != identityHash);
}
}